flutter_flip_panel FlipClock倒数每秒减少超过1秒

时间:2019-02-15 20:34:28

标签: dart flutter countdown

我对flutter_flip_panel有一个奇怪的问题 当我运行代码时,flipclock正确运行倒计时 然后,当我将水平列表视图滚动到末尾时,当我再次将列表视图滚动到起点时,我看到倒数间隔间隔是2秒

当我重复此操作时,间隔增加到3、4、5和...

这是我的代码

  getAuctionProducts() async {
    // Animations
    controller = new AnimationController(vsync: this, duration: Duration(milliseconds: 2000));
    opacity = Tween(begin: 0.0, end: 1.0).animate(new CurvedAnimation(parent: controller, curve: Curves.easeInOut));

    if (await checkInternetConnection() == true) {
      GetData getData = new GetData();
      getData.get(AuctionsJsonLocation).then((dynamic result) {
        if (result['data'] != null && result['data'] != '') {
          for (var auctionProductItem in getData.jsonToMap(result['data'])['result']) {
            auctionProductItems.add(
              GestureDetector(
                child: Container(
                  width: 180,
                  margin: EdgeInsets.all(4),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border.all(
                      color: Color(0xFFCCCCCC),
                    ),
                    borderRadius: BorderRadius.all(Radius.circular(5)),
                  ),
                  child: Column(
                    children: <Widget>[
                      Stack(alignment: Alignment.topLeft, children: [
                        Container(
                          width: 180,
                          height: 135,
                          child: ClipRRect(
                            borderRadius: new BorderRadius.vertical(top: Radius.circular(5)),
                            child: CachedNetworkImage(
                              imageUrl: auctionProductItem['image'],
                              placeholder: Container(
                                alignment: Alignment.center,
                                width: 20,
                                height: 20,
                                child: CircularProgressIndicator(
                                  valueColor: AlwaysStoppedAnimation<Color>(Color(0xFFCCCCCC)),
                                ),
                              ),
                              errorWidget: Icon(Icons.error),
                              fit: BoxFit.cover,
                            ),
                          ),
                        ),
                        Directionality(
                          textDirection: TextDirection.ltr,
                          child: Padding(
                              padding: EdgeInsets.all(2.0),
                              child: FlipClock.countdown(
                                  width: 14,
                                  height: 18,
                                  spacing: EdgeInsets.all(1),
                                  duration: Duration(seconds: ((auctionProductItem['auctionExpireDate'] - auctionProductItem['now']) % 86400)),
                                  digitColor: Color(0xFFFFFFFF),
                                  backgroundColor: Color(0xCC000000),
                                  digitSize: 12.0,
                                  borderRadius: const BorderRadius.all(Radius.circular(2.0)),
                            ),
                          ),
                        ),
                      ]),
                      Container(
                        height: 35,
                        child: Padding(
                          padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 5.0),
                          child: RichText(
                            text: TextSpan(text: auctionProductItem['title'], style: TextStyle(color: Colors.black, fontFamily: "IranYekan")),
                            maxLines: 2,
                            textAlign: TextAlign.start,
                          ),
                        ),
                      ),
                      auctionProductItem['oldPrice'] > 0
                          ? Container(
                              height: 20,
                              child: Text(
                                numberFormat(auctionProductItem['oldPrice']) + ' تومان',
                                textAlign: TextAlign.start,
                                style: TextStyle(color: Color(0xFFb71e3f), decorationStyle: TextDecorationStyle.dashed),
                              ),
                            )
                          : Container(),
                      Container(
                        height: 20,
                        child: Text(
                          numberFormat(auctionProductItem['price']) + ' تومان',
                          textAlign: TextAlign.start,
                          style: TextStyle(color: Colors.green, decorationStyle: TextDecorationStyle.dashed),
                        ),
                      ),
                    ],
                  ),
                ),
                onTap: () {
                  print('You Tapped Product ' + auctionProductItem['id'].toString());
                },
              ),
            );
          }

          setState(() {
            auctionProducts = FadeTransition(
              opacity: opacity,
              child: Column(
                children: <Widget>[
                  headingTitle(
                    text: 'پیشنهاد شگفت انگیز',
                    color: Color(0xFFb71e3f),
                    backgroundColor: Color(0xFFfff2d7),
                    icon: Icon(FontAwesomeIcons.percent_regular, color: Color(0xFFb71e3f), size: 16),
                  ),
                  Container(
                    height: 220,
                    child: ListView(
                      shrinkWrap: true,
                      scrollDirection: Axis.horizontal,
                      children: auctionProductItems,
                    ),
                  ),
                ],
              ),
            );
          });
        }
      });
    } else {
      showAlert(context: context, title: "خطا در اتصال به اینترنت", description: "دستگاه خود را به اینترنت متصل کنید", actions: <Widget>[
        FlatButton(
          child: Text('دوباره سعی کن'),
          onPressed: () {
            getSliders();
            Navigator.of(context, rootNavigator: true).pop();
          },
        ),
        FlatButton(
          child: Text('خروج'),
          onPressed: () {
            exit(0);
          },
        ),
      ]);
    }
  }

0 个答案:

没有答案