Flutter - how to call multiple builder items in material app?

Viewed 3560
class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      builder: BotToastInit(), //1. call BotToastInit
      navigatorObservers: [BotToastNavigatorObserver()],
      debugShowCheckedModeBanner: false,
      title: 'Pak Coins',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MySplashScreen(),
    );
  }
}

this is my MyApp Class where want to call 2 builder

  1. BotToastInit(),
  2. EasyLoading.init() how i call both of this? builder: //here ,
2 Answers

The builder parameter must return one widget. If you like to do initialization or return two widgets, you've to nest them yourself inside the builder:

builder: (context, child) {
    // do your initialization here
    child = EasyLoading.init();  // assuming this is returning a widget
    child = botToastBuilder(context,child);
    return child;
  }

if you look at the getting started guide of bot_toast package, they've an example at step 3.

Update: Or utilize the builder methods provided by BotToast or EasyLoading such as:

builder: EasyLoading.init(builder: BotToastInit()),

Here is the solution.

The build items I want to call are: DevicePreview.appBuilder , BotToastInit() and EasyLoading.init() .

So the solution will be as follows:

 builder: (context, myWidget){
             myWidget = DevicePreview.appBuilder(context, myWidget);
             myWidget = BotToastInit()(context, myWidget);
             myWidget = EasyLoading.init()(context,myWidget);
             return myWidget;
           },
Related