简体   繁体   English

未处理的异常:无效参数 Flutter

[英]Unhandled Exception: Invalid argument(s) Flutter

We using Bloc pattern in our project.我们在项目中使用Bloc模式。 In page A, it has a textView and a button .在 A 页,它有一个textView和一个button When textView is tapped, it will pass the list to page B. The list will then populate in listView page B.textView被点击时,它会将list传递到页面 B。然后列表将填充到列表视图页面 B 中。

When the row of listView is clicked, it will pass the selected data back to page A and add it to sink .当点击 listView 的行时,会将选中的数据传回页面 A 并添加到sink中。 It works exactly like how the startActivityForResult in Android.它的工作方式与 Android 中的startActivityForResult完全相同。

TextField文本域

   StreamBuilder(
                          stream: _bloc.locationListStream,
                          builder: (context, snapshot) {
                            return TextField(
                              onTap: () {
                                _goToPageB(snapshot.data); 
                              },
                              style: TextStyle(fontSize: 12.0, height: 1.0),
                              onChanged: (text) =>
                                  _bloc.locationSink.add(text),
                                       .....
                              controller: _locationController,
                            );
                          },
                        ),


void _goToPageB(List locationList) async {
    var results = await Navigator.of(context)
        .push(MaterialPageRoute<dynamic>(builder: (BuildContext context) {
      return PageB(locationList);
    }));

    if (results != null) {
      setState(() {
        _locationController.text = results.name;
      });
      _bloc.locationSink.add(results.id);  // set the returned data to sink      
    }
  }

When the button in page A is clicked, it will call submit() in bloc class.We want it print out the value, but we get this error.当点击页面 A 中的按钮时,它将调用 bloc class 中的 submit()。我们希望它打印出该值,但我们得到了这个错误。

E/flutter ( 8944): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Invalid argument(s) E/flutter(8944):[错误:flutter/lib/ui/ui_dart_state.cc(148)]未处理异常:无效参数

bloc class集团 class

  final _location = BehaviorSubject<String>();
  get locationSink => _location.sink;
  get locationStream => _location.stream;

Future submit(
      BuildContext context) async {
    final location = _location.value;
    print('The value is '+location);
 }

Edit编辑

When I use print('The value is $location');当我使用print('The value is $location'); , it prints null. ,它打印 null。 Why it is null?为什么是 null?

There's an error in print('The value is '+location); print('The value is '+location);有错误when location is null .locationnull时。 In Dart it is more conventional to use print('The value is $location');在 Dart 中,使用print('The value is $location'); because it's easier to read (and is null safe whereas concatenation is not).因为它更容易阅读(并且 null 是安全的,而串联则不是)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter Https 未处理异常:无效参数 - Flutter Https Unhandled Exception: Invalid argument(s) Flutter:未处理的异常:无效的参数 - Flutter : unhandled exception: invalid argument 未处理的异常:无效参数(值):不得为 null Flutter 2 - Unhandled Exception: Invalid argument(s) (value): Must not be null Flutter 2 Flutter 未处理的异常:无效参数(值):不得为 null - Flutter Unhandled Exception: Invalid argument(s) (value): Must not be null E/flutter(6866):[错误:flutter/lib/ui/ui_dart_state.cc(148)]未处理异常:无效参数 - E/flutter ( 6866): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Invalid argument(s) Flutter,Dart,FireBase:[错误:颤振/lib/ui/ui_dart_state.cc(199)) - 无效的TAP异常 - Flutter, Dart, FireBase: [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Invalid argument(s) - onTap GestureDetcture Flutter 中的参数无效 - Invalid argument(s) in Flutter Dart Error:未处理的异常:E / flutter(5079):无效的参数:&#39;未来的实例 <String> “ - Dart Error: Unhandled exception: E/flutter ( 5079): Invalid argument: Instance of 'Future<String>' 错误:flutter/lib/ui/ui_dart_state.cc(166),未处理的异常:无效参数:“GoogleSignInAccount”实例 - ERROR:flutter/lib/ui/ui_dart_state.cc(166), Unhandled Exception: Invalid argument: Instance of 'GoogleSignInAccount' 未处理的异常:无效参数:“加密”的实例 - Unhandled Exception: Invalid argument: Instance of 'Encrypted'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM