更新提供程序模型时,类型 'Null' 不是类型 'String' 'function result' 的子类型



提供程序版本和dart

provider: ^6.0.1
sdk: ">=2.12.0 <3.0.0"

我有两个屏幕。

屏幕A-我有一个表格。当你点击文本框时,它会打开屏幕B全屏模式。

屏幕B-您将从中的列表中选择一个项目,然后返回屏幕A。

在屏幕A文本框中,我用consumer方法进行了包装。

Consumer<AgentModel>( //                    <--- Consumer
builder: (context, agentModel, child) {
agentController.text = agentModel.name.toString();
return  AppInputWrapper(
marginBottom: 'small',
widgets: Column(
children: [
TextFormField(
style: appInputStyle,
keyboardType: TextInputType.text,
autocorrect: false,
enableSuggestions: false,
decoration: AppInputStyleDecoration.textFieldStyle(hintTextStr: "Agent"),
controller: agentController,
validator: (value) {
return validateAgent(value);
},
readOnly: true,
onTap: (){
Navigator.push(  context, MaterialPageRoute( builder: (context) => AgentFormComponent(),),);
},
),
],
),
);
}
)

当第一个实例从屏幕B到屏幕A时,它没有从提供者加载值。我得到以下错误。

======== Exception caught by widgets library =======================================================
The following _TypeError was thrown building Consumer<AgentModel>(dirty, dependencies: [_InheritedProviderScope<AgentModel?>]):
type 'Null' is not a subtype of type 'String' of 'function result'
The relevant error-causing widget was: 
Consumer<AgentModel> file:///Users/soundharraj/StudioProjects/LHMarine/lib/screens/jobs/create/form.dart:389:13
When the exception was thrown, this was the stack: 
#0      _Location.file (package:flutter/src/widgets/widget_inspector.dart)
#1      _Location.toJsonMap (package:flutter/src/widgets/widget_inspector.dart:2844:15)
#2      _Location.toJsonMap.<anonymous closure> (package:flutter/src/widgets/widget_inspector.dart:2853:42)
#3      MappedListIterable.elementAt (dart:_internal/iterable.dart:412:31)
#4      ListIterator.moveNext (dart:_internal/iterable.dart:341:26)
...
====================================================================================================
Reloaded 1 of 1128 libraries in 592ms.

我不知道如何检查提供程序值是否为NULL。轮到绳子了。

感谢

在ontab上编写函数时,用Gestuetector包装TextFormField。

相关内容

最新更新