[英]Exception has occurred. LateError (LateInitializationError: Field 'notes' has not been initialized.)
class search extends StatefulWidget { const search({Key? key}): super(key: key); class search extends StatefulWidget { const search({Key? key}): super(key: key);
@override State createState() => _searchState(); @override State createState() => _searchState(); }
}
class _searchState extends State { String query = ''; class _searchState 扩展 State { 字符串查询 = '';
late List notes;迟到的清单笔记;
@override Widget build(BuildContext context) => Scaffold( appBar: AppBar( title: Text("sdfs"), centerTitle: true, ), body: Column( children: [ buildSearch(), Expanded( child: StaggeredGridView.countBuilder( itemCount: notes.length, staggeredTileBuilder: (index) => StaggeredTile.fit(2), crossAxisCount: 4, itemBuilder: (context, index) { final note = notes[index]; @override Widget build(BuildContext context) => Scaffold( appBar: AppBar( title: Text("sdfs"), centerTitle: true, ), body: Column( children: [ buildSearch(), Expanded( child: StaggeredGridView.countBuilder( itemCount: notes.length, staggeredTileBuilder: (index) => StaggeredTile.fit(2), crossAxisCount: 4, itemBuilder: (context, index) { final note = notes[index]; }
return GestureDetector(
onTap: () async {
await Navigator.of(context).push(MaterialPageRoute(
builder: (context) => NoteDetailPage(noteId: note.id!),
));
},
child: NoteCardWidget(note: note, index: index),
);
},
),
),
],
),
);
you have made the List notes late
but seems you have used it without initializing it.你已经
late
做了 List 笔记,但似乎你没有初始化它就使用了它。 You need to initialize it in initState
, like this one-您需要在
initState
中对其进行初始化,就像这样-
@override
void initState() {
super.initState();
notes = [];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.