FlutterCountdownTimer icon indicating copy to clipboard operation
FlutterCountdownTimer copied to clipboard

When SliverAppbar re-renders after a scroll, Current remaining time returns null

Open beingentangled opened this issue 5 years ago • 3 comments

SliverAppBar( expandedHeight: MediaQuery.of(context).size.height / 3.5, pinned: true, snap: false, floating: true, forceElevated: innerBoxIsScrolled, automaticallyImplyLeading: false, flexibleSpace: LayoutBuilder( builder: (BuildContext context, BoxConstraints constraints) { return FlexibleSpaceBar( collapseMode: CollapseMode.parallax, background: Container( decoration: BoxDecoration(color: AppColors.blue[500]), child: Observer( builder: (BuildContext context) { return _matchStore.gameListLoading ? CustomProgressIndicatorWidget() : buildHeaderListView(); }, ), ), ); }, ), )

The Above buildHeaderview is re-rendered while the body is scrolled

getMatchDetail(int index) { UserMatches userMatch = _matchStore.matchesResponse.userMatches[index]; DateFormat dateFormat = DateFormat("yyyy-MM-dd H:m:s"); DateFormat gameDateFormat = new DateFormat.yMd().add_jm(); DateTime dateTime = dateFormat.parse(userMatch.matchTime); String gameDate = gameDateFormat.format(dateTime); int endTime = dateTime.millisecondsSinceEpoch; countdownTimerController = CountdownTimerController(endTime: endTime, onEnd: onEnd); TimeClass timeClass = TimeClass(); switch (userMatch.matchStatus) { case 0: { //UpComing return Stack( children: [ Container( alignment: Alignment.bottomLeft, margin: EdgeInsets.only(bottom: 20, left: 10), child: Text( "Upcoming", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15), ), ), Container( alignment: Alignment.bottomLeft, margin: EdgeInsets.only(left: 10), child: CountdownTimer( controller: countdownTimerController, widgetBuilder: (_, CurrentRemainingTime time) { if (time == null) { //todo notify timer stopped for reactions return Text("Contest is online"); } else { return Text( time.days != null ? timeClass.getTimeWithDays(time) : time.hours != null ? timeClass.getTimeWithHours(time) : time.min != null ? timeClass.getTimeWithMinutes(time) : time.sec != null ? timeClass.getTimeWithSeconds(time) : "Match Started", style: TextStyle(fontSize: 12), ); } }, ), ), ], ); });

    **Current Remaining time always comes null after re rendering**         

beingentangled avatar Dec 30 '20 21:12 beingentangled

The end time must be greater than the current timestamp.Can you print the endTime and DateTime.now().millisecondsSinceEpoch?Or give me a minimal runnable example

wuweijian1997 avatar Jan 01 '21 04:01 wuweijian1997

I experienced the same issue on version 2.0.0. In my case I had an expandable_bottom_sheet as a wrapper and in the page (background property of ebs) a CountdownTimer. Once I opened the bottom sheet the CurrentRemainingTime in the widgetBuilder always came back as null. I reverted back to 1.5.0, which is working with no problems & in my case I didn't have the need for the controller property.

Since I'm currently in a little hurry with the project I haven't had time to debug further – sorry, but maybe the fact that it's working in 1.5.0 gives you a little idea where to look.

If this ticket is still open when I get a little more time on my hands I will try to provide more info.

reesz avatar Jan 01 '21 13:01 reesz

Hello,I released 2.1.0 and added endTime and onEnd parameters again. I hope it can help you.

int endTime = DateTime.now().millisecondsSinceEpoch + 1000 * 30;

void onEnd() {
  print('onEnd');
}

CountdownTimer(
  onEnd: onEnd,
  endTime: endTime,
 ),

wuweijian1997 avatar Jan 01 '21 15:01 wuweijian1997