[英]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
.当location
是null
时。 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.