我有一个应用程序,我正在尝试使用三个包:responsive_framework、flaft_easyloading和one_context。问题是,我不知道如何正确地嵌套它们,因为它们都必须从MaterialApps生成器中调用。我知道它们必须这样嵌套:Responsive_framework<asyloading<one_context>gt>,但是我在利用它们的初始化方法找到正确的组合时遇到了困难。
当前初始化:
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider<UserInventoryProvider>(
create: (_) => UserInventoryProvider()),
ChangeNotifierProvider<UserFaultsProvider>(
create: (_) => UserFaultsProvider()),
ChangeNotifierProvider<AuthProvider>(create: ((_) => AuthProvider())),
ChangeNotifierProvider<NavDrawerProvider>(
create: ((_) => NavDrawerProvider())),
ChangeNotifierProvider<LoginDialogProvider>(
create: ((_) => LoginDialogProvider())),
//ChangeNotifierProvider<CacheProvider>(create: ((_) => CacheProvider()))
],
child: MaterialApp(
// Nest the builders in the tree
builder: EasyLoading.init(builder: OneContext().builder), <--- I have it working with 2 here
title: 'AppName',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
fontFamily: 'Roboto',
),
navigatorKey: locator<DynamicNavigationService>().navigationKey,
initialRoute: Routes.home,
onGenerateRoute: AppName.Router.generateRoute,
),
);
}
}
responsive_frameworks初始化如下:
builder: (context, widget) => ResponsiveWrapper.builder(
BouncingScrollWrapper.builder(context, widget!),
maxWidth: 1200,
minWidth: 450,
defaultScale: true,
breakpoints: [
ResponsiveBreakpoint.resize(450, name: MOBILE),
ResponsiveBreakpoint.autoScale(800, name: TABLET),
ResponsiveBreakpoint.autoScale(1000, name: TABLET),
ResponsiveBreakpoint.resize(1200, name: DESKTOP),
ResponsiveBreakpoint.autoScale(2460, name: "4K"),
],
background: Container(color: Color(0xFFF5F5F5))),
我一直在试图找到一种方法来返回其他两个的组合,比如:我发现这是一个不相关的包的例子
builder: (context, child) {
child = EasyLoading.init(builder: OneContext().builder);
child = ResponsiveWrapper.builder(
BouncingScrollWrapper.builder(context, widget!),
maxWidth: 1200,
minWidth: 450,
defaultScale: true,
breakpoints: [
ResponsiveBreakpoint.resize(450, name: MOBILE),
ResponsiveBreakpoint.autoScale(800, name: TABLET),
ResponsiveBreakpoint.autoScale(1000, name: TABLET),
ResponsiveBreakpoint.resize(1200, name: DESKTOP),
ResponsiveBreakpoint.autoScale(2460, name: "4K"),
],
background: Container(color: Color(0xFFF5F5F5))),
return child;
},
但我还没有找到一个有效的调用组合。我觉得有一个简单的方法可以做到这一点,但我找不到任何关于嵌套多个生成器的信息
以下代码应能在中工作
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
builder: (context, widget) => ResponsiveWrapper.builder(
OneContext().builder(
context,
FlutterEasyLoading(
child: Scaffold(), //Add your main Widget here
)),
maxWidth: 1200,
minWidth: 480,
defaultScale: true,
breakpoints: [
ResponsiveBreakpoint.resize(480, name: MOBILE),
ResponsiveBreakpoint.autoScale(800, name: TABLET),
ResponsiveBreakpoint.resize(1000, name: DESKTOP),
],
background: Container(color: Color(0xFFF5F5F5)),
),
);
}
}
我在这里遵循的规则是,每当一个建设者在找孩子时,我都会添加下一个建设者
这里唯一的技巧是使用EasyLoading:我没有使用init()
方法,而是使用了WidgetFlutterEasyLoading
嵌套生成器时要小心,您可能必须遵守特定的顺序才能使代码正常工作。