简体   繁体   中英

MultiProvider must specify a child 'package:provider/src/inherited_provider.dart': Failed assertion: 'builder != null || child != null'

Main

    void main() async {
          WidgetsFlutterBinding.ensureInitialized();
          await Firebase.initializeApp();
          runApp(MultiProvider(
            providers: [
              ChangeNotifierProvider.value(value: ProductProvider.initialize()),
            ], child: Builder(builder: _ProductProvider),
          ));
        }
class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Widget rootPage = Login(); //Pagina de inicio
  Future<Widget> estadoDelUsuario() async =>
      // ignore: await_only_futures
      await FirebaseAuth.instance.currentUser == null ? Login() : Inicio();
  // se pregunta si se esta loggeado y dependiendo de eso se muestra la pagina de inicio correspondiente

  @override
  void initState() {
    //de los primeros metodos que se inician
    // ignore: todo
    // TODO: implement initState
    super.initState();
    estadoDelUsuario().then((Widget page) {
      setState(() {
        rootPage = page; //se muestra la pagina obtenida de la pregunta
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    child:
    MaterialApp(
      theme: ThemeData(primaryColor: Colors.white),
      debugShowCheckedModeBanner: false,
      home: rootPage, //Pagina inicio
      routes: buildAppRoutes(), //Rutas
    );
  }
}

I know the error is in here:

     ChangeNotifierProvider.value(value: ProductProvider.initialize()),
     ], child: Builder(builder: _ProductProvider),

But I don't know what can I put in there. Because the MaterialApp it's down.

There is more than one problem. One of them is about the use of MultiProvider. You need to set MultiProvider correctly.

      MultiProvider( //                                     <--- MultiProvider
            providers: [
              ChangeNotifierProvider<MyModel>(create: (context) => MyModel()),
              ChangeNotifierProvider<AnotherModel>(create: (context) => AnotherModel()),
            ],

Please read more from here , and I advise you to follow the steps carefully.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM