'Table_calendar not show event indicator and event when data load
I have load data in init state but the event indicator does not show and when I click on other date and come bak data gone.
Solution 1:[1]
Since initState is not async, you normally wouldn't add code to it that executes asynchronously (like a fetch of data). Instead, I would suggest using a FutureBuilder (or StreamBuilder.periodic if you want to keep fetching your data periodically).
Say you have the function
Future<List<Event>> fetchEvents() async {
...
return events;
}
Which fetches the events from your local or online database and returns them as a list. You could then wrap your widget in a FutureBuilder:
FutureBuilder<List<Event>>(
future: fetchEvents,
builder: (BuildContext context, AsyncSnapshot<List<Event>> snapshot) {
List<Event> events = snapshot.data ?? [];
return MyAwesomeCalendarWidget(events: events);
}
);
This way, the Widget will build first with the empty List (no events fetched yet), showing you an empty calendar, and once the data is fetched it'll rebuild accordingly. You would no longer need to use a StatefulWidget in this case.
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 | fravolt |

