169 похожих чатов

Guys I have issue with null safety dart FutureBuilder(

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?

1 ответов

8 просмотров
非主流-Me Автор вопроса

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.

Похожие вопросы

Обсуждают сегодня

Есть какой-нибудь для Delphi/FPC T*Compression(Decompression)Stream на базе LZ4/Zstd/любой другой быстрый(и хорошо сжимающий) алгоритм А ещё лучше в pure pascal А ещё лучше од...
notme
48
Такой вопросец - есть функция function MySuperDuperConcat(const a: array of AnsiString): AnsiString; Как мне в её теле сделать вот так? Result:=Concat(a); А не грустный вариан...
notme
15
type TObj = object procedure Init; virtual; end; TObj1 = object(TObj) procedure Init; override; end; procedure TObj1.Init; begin inherited; end; procedur...
Alexander 👋
29
А чем вам питонисты не угодили?😂
.
79
Всем привет. Поделитесь, пожалуйста, опытом. Есть форма, на которой имеется dbgrid и кнопки: добавить, редактировать, удалить. Если нет записей в dbgrid, то кнопки редактирова...
Евгений
4
Всем привет, написал код ниже, но он выдает сегфолт, в чем причина? #include <stdio.h> #include <stdlib.h> #include <string.h> struct product { char *name; float price; };...
buzz базз
86
Вот смотрите у меня есть два стрима сейчас fs, cs: TStream; fs := TFileStream.Create('filename'); cs := TCompressionStream.Create(compression_level, fs); Я хочу сделать так: ...
notme
5
type TExtensions<GExtender>=class function GetExtension<GEntityExtenderType>:GEntityExtenderType; end; function TExtensions<GExtender>.GetExtension<GEntityExtenderType...
zamtmn
8
Всем здравствуйте! Я хотел узнать сколько стоит средняя месячная зарплата у Electron js разработчиков? Мне очень это важно и нужно, плиз помогите узнать эту инфу! Для Джунио...
U.K.
10
Можно ли загрузить скрипт py в бота чтобы он работал по нему? как это сделать?
huskadam #RCC Фанат? @hitlerpvp
13
Карта сайта