dart StreamBuilder中出现意外的空值[已关闭]

qqrboqgw  于 2023-03-15  发布在  其他
关注(0)|答案(1)|浏览(137)

Closed. This question needs debugging details . It is not currently accepting answers.

Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem . This will help others answer the question.
Closed yesterday.
Improve this question
Unexpected null value.
The relevant error-causing widget was:
StreamBuilder<QuerySnapshot<Object?>> StreamBuilder:file:///C:/Users/India/AndroidStudioProjects/emplace_data/lib/list_employee_page.dart:31:12 When the exception was thrown, this was the stack: C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49 throw C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 528:63 nullCheck packages/emplace_data/list_employee_page.dart 48:14 packages/flutter/src/widgets/async.dart 444:81
build packages/flutter/src/widgets/async.dart 124:48
build packages/flutter/src/widgets/framework.dart 4992:27
build packages/flutter/src/widgets/framework.dart 4878:15
performRebuild packages/flutter/src/widgets/framework.dart 5050:11
performRebuild packages/flutter/src/widgets/framework.dart 4604:5
rebuild packages/flutter/src/widgets/framework.dart 2667:18
buildScope packages/flutter/src/widgets/binding.dart 882:9
drawFrame packages/flutter/src/rendering/binding.dart 378:5
[_handlePersistentFrameCallback] packages/flutter/src/scheduler/binding.dart 1175:15
[_invokeFrameCallback] packages/flutter/src/scheduler/binding.dart 1104:9
handleDrawFrame packages/flutter/src/scheduler/binding.dart 1015:5
[_handleDrawFrame] C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/platform_dispatcher.dart 1168:13 invoke C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/platform_dispatcher.dart 219:5 invokeOnDrawFrame C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/initialization.dart 195:45 C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 334:14 _checkAndCall C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 339:39 dcall
adding data to table view using registration page but unexpected null error shown please help me to solve the issue

41zrol4v

41zrol4v1#

请使用这种方式。它只是一个例子,根据您的问题可能是你流建设者得到一些空值。
例子:-

StreamBuilder(
          stream: FirebaseFirestore.instance
              .collection('chats')
              .doc(remoteUser.uid)
              .collection('users')
              .doc(SharedPreferenceHelper().getUserId())
              .collection('messages')
              .orderBy('timestamp', descending: false)
              .snapshots(),
          builder: (context, snapshot) {
            if (snapshot.hasData) {
              final allData =
                  snapshot.data!.docs.map((doc) => doc.data()).toList();
              List<dynamic> list = allData;
            }
            if (snapshot.hasError) {
              return const Center(
                child: Text("Something went wrong!"),
              );
            }
            return Expanded(
              child: Center(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    WillPopScope(
                        onWillPop: () async {
                          return true;
                        },
                        child: Lottie.asset('assets/chat_msg.json',
                            filterQuality: FilterQuality.high)),
                    const Text(
                      "No messages",
                      style: TextStyle(color: Colors.black, fontSize: 16),
                    ),
                    const Text(
                      "Chat will automatically deleted after 24 Hours",
                      style: TextStyle(color: Colors.black54, fontSize: 14),
                    ),
                  ],
                ),
              ),
            );
          }),

相关问题