Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ,
like image 821
Muhammad Anus Avatar asked Dec 30 '22 18:12

Muhammad Anus


1 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()),
like image 198
osaxma Avatar answered Jan 13 '23 14:01

osaxma