在MaterialApp构建器属性内返回多个小部件

时间:2020-07-04 05:42:09

标签: flutter dart

我正在使用active_framework和bot_toast,并且要对其进行初始化,我需要使用MaterialApp内部的builder属性。

response_framework

builder: (context, widget) {
    return ResponsiveWrapper.builder(
      BouncingScrollWrapper.builder(context, widget),
      maxWidth: 1200,
      minWidth: 450,
      defaultScale: true,
      breakpoints: [
        ResponsiveBreakpoint.autoScale(480, name: MOBILE),
        ResponsiveBreakpoint.autoScale(800, name: TABLET),
        ResponsiveBreakpoint.autoScale(1000, name: DESKTOP),
      ],
      background: Container(
        color: Color(0xFFF5F5F5),
      ),
    );
  },

bot_toast

MaterialApp(
  title: 'BotToast Demo',
  builder: BotToastInit(), //1. call BotToastInit
  navigatorObservers: [BotToastNavigatorObserver()], //2. registered route observer
  home: XxxxPage(),

我的问题是,即使这两个软件包都使用了builder属性,我该如何配置它们?

1 个答案:

答案 0 :(得分:0)

我找到了解决方法

@override
Widget build(BuildContext context) {
final botToastBuilder = BotToastInit();
return MaterialApp(    
  builder: (context, child) {
    child = ResponsiveWrapper.builder(
      BouncingScrollWrapper.builder(context, child),
      maxWidth: 1200,
      minWidth: 450,
      defaultScale: true,
      breakpoints: [
        ResponsiveBreakpoint.autoScale(480, name: MOBILE),
        ResponsiveBreakpoint.autoScale(800, name: TABLET),
        ResponsiveBreakpoint.autoScale(1000, name: DESKTOP),
      ],
      background: Container(
        color: Color(0xFFF5F5F5),
      ),
    );

    child = botToastBuilder(context, child);
    return child;
  },
  navigatorObservers: [BotToastNavigatorObserver()],
 
);
}

感谢https://github.com/MMMzq/bot_toast/issues/55