appinioGmbH / flutter_packages

Dart and Flutter plugins/packages used and maintained by @appinioGmbH
193 stars 224 forks source link

How to make TimerCountdown auto refresh to count when endTime has new value? #6

Closed DVCStudioX closed 2 years ago

DVCStudioX commented 2 years ago

Hi, thanks for the great packages, I use GraphQL to fetch data, so endTime will change sometime -> I want TimerCountdown will refresh like that: Option 1: TimerCountdown auto-refresh count when endTime have a new value Option 2: if option 1 is not possible, onEnd: after 10 minutes -> TimerCountdown refresh count

So pls help me (I am a newbie), this is my code:

 body: Query(
        options: QueryOptions(
          document: gql(traderResetTimes),
          pollInterval: Duration(seconds: 10),
        ),
        builder: (QueryResult result, {VoidCallback refetch, FetchMore fetchMore}) {
          if (result.hasException) {
            return Text(result.exception.toString());
          }
          if (result.isLoading) {
            return Text('Loading');
          }

          List repositories = result.data['traderResetTimes'];

          return ListView.builder(
              itemCount: repositories.length,
              itemBuilder: (context, index) {
                final r = repositories[index];
                var t1 = DateTime.parse(r['resetTimestamp']).toLocal();
                var t2 = DateFormat.Hms().format(t1);
                return Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    Expanded(child: Text(r['name'])),
                    Expanded(
                      child: TimerCountdown(
                        format: CountDownTimerFormat.hoursMinutesSeconds,
                        spacerWidth: 0,
                        enableDescriptions: false,
                        endTime: t1,

                      ),
                    ),
                    Expanded(child: Text(t2.toString())),
                  ],
                );
              });
        },
      ),
tobiasbentin commented 2 years ago

Can you try to use setState on your endTime value? So at some point when the endTime has to be updated you do something like:

setState((){
endTime = newEndTime;
});
DVCStudioX commented 2 years ago

Yeah, thank you :D