简体   繁体   English

发生异常。 LateError(LateInitializationError:字段“注释”尚未初始化。)

[英]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.

相关问题 LateError (LateInitializationError: Field 'customTypeSchemas' has not been initialized.) 放大插件错误 - LateError (LateInitializationError: Field 'customTypeSchemas' has not been initialized.) Amplify Plugins Error 未处理的错误 LateInitializationError:字段“currentUser”尚未初始化。 发生在“HomeBloc”的实例中 - Unhandled error LateInitializationError: Field 'currentUser' has not been initialized. occurred in Instance of 'HomeBloc' 未处理的异常:LateInitializationError:字段“requestPort”尚未初始化。 集市 flutter - Unhandled Exception: LateInitializationError: Field 'requestPort' has not been initialized. Agora flutter flutter:LateInitializationError:字段“名称”尚未初始化 - flutter: LateInitializationError: Field 'name' has not been initialized Flutter:LateInitializationError:字段“_name”尚未初始化 - Flutter: LateInitializationError: Field '_name' has not been initialized LateInitializationError:字段“chatRoomsStream”尚未在 Flutter 中初始化 - LateInitializationError: Field 'chatRoomsStream' has not been initialized in Flutter Flutter Dart - LateInitializationError:字段“playerSnapshot”尚未初始化 - Flutter Dart - LateInitializationError: Field 'playerSnapshot' has not been initialized 发生异常。 StateError(错误 state:DocumentSnapshotPlatform 中不存在字段)- 当我发出请求时 Flutter Firestore - Exception has occurred. StateError (Bad state: field does not exist within the DocumentSnapshotPlatform) - When I make a request Flutter Firestore Flutter Firebase 没有正确初始化。 您是否已将“google-services.json”文件添加到项目中? - Flutter Firebase has not been correctly initialized. Have you added the "google-services.json" file to the project? 发生存储异常。 用户未通过身份验证 - StorageException has occurred. User is not authenticated
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM