I've been trying to create a list of Flutter Widgets to use them in a slider.
I'm fetching the data from JSON file, and passing it as Future<List> to FutureBuilder.
However, when trying to build my app, Error message pops up:
Error: Operator '[]' cannot be called on 'List<dynamic>?' because it is potentially null. 'List' is from 'dart:core'.
I've tried to validate it with 'initial data' or checking if it's not null, but they don't seem to work.
Is there some nice solution to get a list of Widgets just like ItemBuilder from ListView.builder does it?
NOTE: when I build app with static data, and then perform hot reload it fetches data just fine, and shows no exceptions or warnings.
List<Widget> elements = [];
if (snapshot.hasData) {
for(int j = 0; j < snapshot?.data?.length; ++j) {
elements.add(
Container(child: Text(snapshot.data[j]["my_text"])
)
);
}