future: FundCategories?.getCategories(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return GridView.builder(
itemCount: 7,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
),
itemBuilder: (context, index) {
return Card(
child: Stack(
children: [
Image.asset(snapshot.data[index]['image']),
],
),
);
},
);
}
return Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(LightThemes.mainTheme),
),
);
},
),
Which I got the exception `The method '[]' can't be unconditionally invoked because the receiver can be 'null'.
Try making the call conditional (using '?.') or adding a null check to the target ('!').dartunchecked_use_of_nullable_value`
I tried to Image.asset(snapshot.data?[index]['image']) and Image.asset(snapshot.data![index]['image']) but it dont work. any idea?
I already found the issue . the datatype wasn't declared. update: late final Future<List<Map<String, Object>>> categories = FundCategories?.getCategories(); FutureBuilder<dynamic>( future: categories, builder: (context, snapshot) { if (snapshot.hasData) { return GridView.builder( itemCount: snapshot.data!.length, gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 2, ), itemBuilder: (context, index) { return Card( child: Stack( children: [ Image.asset(snapshot.data![index]!['image']!), Text(snapshot.data![index]!['category']!) ], ), ); }, ); } return Center( child: CircularProgressIndicator( valueColor: AlwaysStoppedAnimation(LightThemes.mainTheme), ), ); }, ), and it feels like kotlin.
Обсуждают сегодня