'I want to show data change dynamically but its does not work

I am trying to show the product offer time left by using the difference between DateTime Now and the deadline date which is come from API,

Here The Code:

GridView.builder(
                  shrinkWrap: true,
                  itemCount: value.grocery!.social!.length,
                  itemBuilder: (context, index) {
                    DateTime date = DateTime.parse(
                        value.grocery!.social![index].deadline.toString());
                    DateTime date2 = DateTime.now();
                    diff = date.difference(date2);
                    print(diff);                
                    return Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Expanded(
                          child: Padding(
                            padding: const EdgeInsets.symmetric(
                                horizontal: 20.0),
                            child: Row(
                              mainAxisAlignment:
                                  MainAxisAlignment.spaceBetween,
                              crossAxisAlignment:
                                  CrossAxisAlignment.stretch,
                              children: [
                                Column(
                                  children: [
                                    Container(
                                      padding: const EdgeInsets.all(8.0),
                                      color: Colors.black,
                                      child: Text(
                                        diff!.inDays.toInt() > 0
                                            ? diff!.inDays.toString()
                                            : "0",
                                        textAlign: TextAlign.center,
                                        style: const TextStyle(
                                          color: Colors.white,
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                                Column(
                                  children: [
                                    Container(
                                      padding: const EdgeInsets.all(8.0),
                                      color: Colors.black,
                                      child: Text(
                                        diff!.inHours
                                                    .toInt()
                                                    .remainder(12) >
                                                0
                                            ? diff!.inHours
                                                .remainder(12)
                                                .toString()
                                            : "0",
                                        style: const TextStyle(
                                            color: Colors.white),
                                      ),
                                    ),
                                  ],
                                ),
                                Column(
                                  children: [
                                    Container(
                                      padding: const EdgeInsets.all(8.0),
                                      color: Colors.black,
                                      child: Text(
                                        diff!.inMinutes
                                                    .remainder(60)
                                                    .toDouble() >
                                                0
                                            ? diff!.inMinutes
                                                .remainder(60)
                                                .toString()
                                            : "0",
                                        style: const TextStyle(
                                            color: Colors.white),
                                      ),
                                    ),
  
                                  ],
                                ),
                              ],
                            ),
                          ),
                        ),
                      
                  },
                );

I want to show data changes dynamically but the data does not change dynamically. When I do restart then it changes. I try to use setState but it's not working for GrideView.Builder. How can I solve this?



Solution 1:[1]

Maybe ? you should make a timer that call setState function every second or millisecond

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hakim Hüseyin