Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

大佬,跪求解决 那个初始化无法成功,太迫切了,现在项目每次重新运行就会报错 #209

Closed
IOCloudFly opened this issue Feb 4, 2021 · 20 comments

Comments

@IOCloudFly
Copy link

No description provided.

@haifzhan
Copy link

haifzhan commented Feb 5, 2021

我也遇到了这个问题, 查了一下发现新版本是2月4号更新的。 我回滚到4.0.2+3 就没事了,之前是^4.0.2+3。

@lizhuoyuan
Copy link
Collaborator

是最新版本有问题 ?
初始化方法有改动

@IOCloudFly
Copy link
Author

插件:^4.0.2+3
flutter sdk: 1.22.5
目前初始化失败,主要你那个判断maxWidth != 0,就不会初始化,我不懂为何。项目每次build会导致app卡顿。

@lizhuoyuan
Copy link
Collaborator

插件:^4.0.2+3
flutter sdk: 1.22.5
目前初始化失败,主要你那个判断maxWidth != 0,就不会初始化,我不懂为何。项目每次build会导致app卡顿。

更新到最新版,然后照文档修改一下初始化方法试一试

@idootop
Copy link
Contributor

idootop commented Feb 5, 2021

插件:^4.0.2+3
flutter sdk: 1.22.5
目前初始化失败,主要你那个判断maxWidth != 0,就不会初始化,我不懂为何。项目每次build会导致app卡顿。

是maxWidth != 0,就会初始化,因为maxWidth为0的时候你的所有尺寸都变成0了,显然这是不对的,而且分母不能为0

lizhuoyuan added a commit that referenced this issue Feb 5, 2021
@IOCloudFly
Copy link
Author

不行,还是那个报错

我也遇到了这个问题, 查了一下发现新版本是2月4号更新的。 我回滚到4.0.2+3 就没事了,之前是^4.0.2+3。

你能否说下你现在的版本

@IOCloudFly
Copy link
Author

插件:^4.0.2+3
flutter sdk: 1.22.5
目前初始化失败,主要你那个判断maxWidth != 0,就不会初始化,我不懂为何。项目每次build会导致app卡顿。

是maxWidth != 0,就会初始化,因为maxWidth为0的时候你的所有尺寸都变成0了,显然这是不对的,而且分母不能为0

这是你们的方法,只是我debug走到那一步就不走了,目前还是无法初始化成功

@IOCloudFly
Copy link
Author

image
我目前是这样的写法,语法有问题吗?我当前的是MyApp 是 StatefulWidget

@idootop
Copy link
Contributor

idootop commented Feb 6, 2021

image
我目前是这样的写法,语法有问题吗?我当前的是MyApp 是 StatefulWidget

先把这个插件的依赖更新成本仓库的master分支,然后把 child:MaterialApp 改成 builder: ()=>MaterialApp

@IOCloudFly
Copy link
Author

image
我目前是这样的写法,语法有问题吗?我当前的是MyApp 是 StatefulWidget

先把这个插件的依赖更新成本仓库的master分支,然后把 child:MaterialApp 改成 builder: ()=>MaterialApp

大佬,你说的这种插件依赖怎么写。

@idootop
Copy link
Contributor

idootop commented Feb 7, 2021

image
我目前是这样的写法,语法有问题吗?我当前的是MyApp 是 StatefulWidget

先把这个插件的依赖更新成本仓库的master分支,然后把 child:MaterialApp 改成 builder: ()=>MaterialApp

大佬,你说的这种插件依赖怎么写。

  flutter_screenutil:
    git:
      url: https://github.com/OpenFlutter/flutter_screenutil.git

@lizhuoyuan
Copy link
Collaborator

不要依赖master, 依赖v4版本 , master是 null safety的

@jasonlaw
Copy link

Same problem with v4.0.3+1

image

@lizhuoyuan
Copy link
Collaborator

can you show initialization code?

@jasonlaw
Copy link

class VIQCoreMaterialApp extends StatelessWidget {
  final Key key;
  final String initialRoute;
  final TransitionBuilder builder;
  final VoidCallback onInit;
  final VoidCallback onDispose;
  final ThemeData theme;
  final ThemeData darkTheme;
  final ThemeMode themeMode;
  final Function(Routing) routingCallback;
  final List<GetPage> getPages;

  //Screen Utils
  final Size designSize;
  final bool allowFontScaling;

  VIQCoreMaterialApp({
    this.key,
    this.designSize = ScreenUtil.defaultSize,
    this.allowFontScaling = false,
    // Widget home,
    // Widget login,
    //Map<String, WidgetBuilder> routes = const <String, WidgetBuilder>{},
    this.initialRoute,
    //this.onGenerateRoute,
    //this.onGenerateInitialRoutes,
    //this.onUnknownRoute,
    //this.navigatorObservers = const <NavigatorObserver>[],
    this.builder,
    //this.translationsKeys,
    //Map<String, Map<String, String>> translations,
    //String title = '',
    //this.onGenerateTitle,
    //Color color,
    // this.customTransition,
    this.onInit,
    this.onDispose,
    this.theme,
    this.darkTheme,
    this.themeMode,
    // this.locale,
    // this.localizationsDelegates,
    // this.localeListResolutionCallback,
    // this.localeResolutionCallback,
    // this.supportedLocales = const <Locale>[Locale('en', 'US')],
    // this.debugShowMaterialGrid = false,
    // this.showPerformanceOverlay = false,
    // this.checkerboardRasterCacheImages = false,
    // this.checkerboardOffscreenLayers = false,
    // this.showSemanticsDebugger = false,
    // this.debugShowCheckedModeBanner = false,
    // this.shortcuts,
    // this.smartManagement = SmartManagement.full,
    // this.initialBinding,
    // this.unknownRoute,
    this.routingCallback,
    // this.defaultTransition,
    // // this.actions,
    @required this.getPages,
    // this.opaqueRoute,
    // this.enableLog,
    // this.popGesture,
    // this.transitionDuration,
    // this.defaultGlobalState,
  }) : assert(AppAuth == null || getPages.any((x) => x.name == "/login"));

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
        designSize: designSize,
        allowFontScaling: allowFontScaling,
        builder: () => buildMaterialApp(context));
  }

  Widget buildMaterialApp(BuildContext context) {
    return GetMaterialApp(
      supportedLocales: AppLanguage.locales,
      localizationsDelegates: [
        FormBuilderLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      key: key,
      //locale: LanguageController.to.locale,
      debugShowCheckedModeBanner: false,
      onInit: onInit,
      onDispose: onDispose,
      theme: theme,
      darkTheme: darkTheme,
      themeMode: themeMode ?? AppTheme.themeMode,
      initialRoute: initialRoute ?? (App.isLogin ? "/" : "/login"),
      routingCallback: routingCallback,
      getPages: getPages,
      builder: (BuildContext context, Widget child) {
        /// make sure that loading can be displayed in front of all other widgets
        return UpgradeAlert(
          child:
              FlutterEasyLoading(child: builder?.call(context, child) ?? child),
        );
      },
    );
  }
}

@lizhuoyuan
Copy link
Collaborator

change Widget buildMaterialApp to Builder buildMaterialApp

@jasonlaw
Copy link

you mean like this?

 Builder buildMaterialApp(BuildContext context) {
    return Builder(
        builder: (_) => GetMaterialApp(
              supportedLocales: AppLanguage.locales,
              localizationsDelegates: [
                FormBuilderLocalizations.delegate,
                GlobalMaterialLocalizations.delegate,
                GlobalWidgetsLocalizations.delegate,
              ],
              key: key,
              //locale: LanguageController.to.locale,
              debugShowCheckedModeBanner: false,
              onInit: onInit,
              onDispose: onDispose,
              theme: theme,
              darkTheme: darkTheme,
              themeMode: themeMode ?? AppTheme.themeMode,
              initialRoute: initialRoute ?? (App.isLogin ? "/" : "/login"),
              routingCallback: routingCallback,
              getPages: getPages,
              builder: (BuildContext context, Widget child) {
                /// make sure that loading can be displayed in front of all other widgets
                return UpgradeAlert(
                  child: FlutterEasyLoading(
                      child: builder?.call(context, child) ?? child),
                );
              },
            ));
  }

But I thought we are already using builder here? Why so many builder required?

 return ScreenUtilInit(
        designSize: designSize,
        allowFontScaling: allowFontScaling,
        builder: () => buildMaterialApp(context));
  }

@lizhuoyuan
Copy link
Collaborator

The best way is to combine two methods into one,
like this:

 ScreenUtilInit(
        designSize: designSize,
        allowFontScaling: allowFontScaling,
        builder: App()
  }

the reason:
If the type is Widget, its code will be executed in advance, and the initialization is not completed at this time.

@seekcx
Copy link

seekcx commented Feb 21, 2021

大哥们,backchange 为什么发小版本?

@lizhuoyuan
Copy link
Collaborator

大哥们,backchange 为什么发小版本?

不是大小, 那个v5是 null safety的 , 如无必要请用v4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants