flutter_flip_panel FlipClock countdown decrease more than 1 second each second

0

i have a strange problem with flutter_flip_panel when i run my code, the flipclock runs countdown correctly then when i scroll horizontal listview to the end, when i scroll the list view again to the start point, i see that the countdown interval is 2 seconds

when i repeat this action the interval increases to 3, 4, 5 and ...

here is my code

  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);
          },
        ),
      ]);
    }
  }
dart
flutter
countdown

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0