我试图在我的应用程序顶部实现提供程序,但遇到错误:“位置参数:预期为0,但找到1”。我尝试了不同的实现,但是随后出现运行时错误“ build function return null”。以下实现有问题吗?
this.cptForm.controls['bankFilterCtrl'].setValue('search value');
我的UserModel看起来像这样:
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
Provider<UserModel>(
builder: (context) => UserModel(),
return new MaterialApp(
title: 'Profile Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Profile'),
),
),
);
}
}
完整的MyHomePage代码:
class UserModel extends ChangeNotifier {
String uid;
}
答案 0 :(得分:0)
问题是您正在尝试返回MaterialApp。您需要将MaterialApp设置为Provider的子级,而不返回它:
Provider<UserModel>(
builder: (context) => UserModel(),
child: MaterialApp( // <<<<<<<<<<<<<<<<<<<<<<<<< Here
title: 'Profile Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),