-
Notifications
You must be signed in to change notification settings - Fork 479
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
关于我使用ScreenUtilInit这种方式初始化,builder会调用两次,导致跳转页面会多生成一个 #563
Comments
|
i moved MaterialApp Widget to child label,initialRoute also build twice |
code below: class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: const Size(750, 1624),
child: MaterialApp(
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate
],
supportedLocales: const [
Locale('zh'),
],
onGenerateRoute: (settings){
String? pageName = settings.name;
final Function pageBuilder = LunarPages().pageMap['$pageName'] as Function;
if(settings.arguments != null){
return CupertinoPageRoute(
builder: (context) =>
pageBuilder(context, arguments: settings.arguments));
}else{
return CupertinoPageRoute(
builder: (context) => pageBuilder(context),
settings: settings
);
}
},
initialRoute: 'loading',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
// home: child,
builder: (context, child){
//不跟随系统字体
return MediaQuery(data: MediaQuery.of(context).copyWith(textScaler: const TextScaler.linear(1.0)),
child: easyLoading(context, child));
},
),
);
}
} leak to build twice, how to fix it, thx |
@xh307 Which builder called twice ? I can't run your code to test. Please provide a minimal reproduction code so I can debug (fresh project with only flutter_screenutil as dependency). This will help also to ensure that this bug is raised from this package. |
main code:
@Mounir-Bouaiche LunarLoadingView named loading is initialRoute, if i used ScreenUtilInit, The build method of LunarLoadingView will be executed twice |
@xh307 Is your code uploaded somewhere ? Github? Can you share with me. I need to run the project so I can debug. |
@xh307 However, for any code you want to be sure it run once, you sould use initState of StatefulWidget. This ensure your code run once even if widget get replaced by this library, flutter widget, or any other library. |
1:flutter version:3.19.6
2:flutter_screenutil version: 5.9.0
3:使用方式是全局的方式(ScreenUtilInit):看上面图片
4:现在的问题,每次启动应用都有build两次,导致会生成两个page的问题,请问有什么方式可以解决吗
The text was updated successfully, but these errors were encountered: