changenotifierprovider是否会处置导航?

时间:2019-09-11 10:35:04

标签: flutter dart flutter-provider flutter-navigation flutter-widget

我在应用页面上初始化Provider

@override
  Widget build(BuildContext context) {
return ChangeNotifierProxyProvider<Model1, Model2>(
initialBuilder: (_) => Model2(),
  builder: (_, model1, model2) => model2
    ..string = model1.string,
),
  child: Consumer<Model2>(
    builder: (context, model2, _) =>

...
        Navigator.push(
          context,
          MaterialPageRoute(builder: (context) => Page2(context: context)),

但是当我将Navigator.push页面推至Page2时:

class Page2 extends StatelessWidget {

final context;

  Page2({Key key, this.context});
...

@override
Widget build(BuildContext context) {

return Consumer<Model2>(
    builder: (context, model2, _) =>
MaterialApp(
home: Scaffold(
…

出现错误:

  

错误:在此上方找不到正确的提供者   消费者小工具

如何解决此错误?

0 个答案:

没有答案