flutter 当杀死应用程序并多次加载时,屏幕的抖动UI扭曲,我正在使用screen_utills类获取屏幕大小

kyxcudwk  于 2022-11-17  发布在  Flutter
关注(0)|答案(1)|浏览(123)

我使用screen_utill类为我的项目的灵活UI的所有屏幕。但我面临着一个问题,实际上,当我杀死我的应用程序,并再次尝试运行应用程序的一些时候,屏幕得到扭曲的大部分时间,它似乎没有加载或设置一个比率的设备。我正在与这个问题作斗争

@override

小部件构建(BuildContext上下文){

ScreenUtil.init();// this is where I initialized.
return MultiBlocProvider(
  providers: [
    BlocProvider(
      create: (context) => abcBloc,
    ),
    BlocProvider(
      create: (context) => defBloc,
    ),
  

  ],
  child: GestureDetector(
    onTap: () {
      FocusScopeNode focusScopeNode = FocusScope.of(context);
   
    },
    child: FutureBuilder(
      future: _initializeSharedPrefs(),
      builder: (context, snapshot) {
        if (snapshot.connectionState == ConnectionState.done) {
       
          return  MaterialApp(
            debugShowCheckedModeBanner: false,
         
            theme: ThemeData(
            ..........
                  ),
            
            ),
            initialRoute:'login',
            routes: {
              'login': (context) => LoginScreen(),
            
            },
          );
        } else
     
      },
    ),
  ),
);

}
静态常量大小默认大小=大小(375,812);已在screen_utills类别中设定。

wqsoz72f

wqsoz72f1#

第二种初始化方式似乎给予问题。请尝试文档中提供的第一种初始化过程。
使用ScreenUtilInit小部件将MaterialApp小部件 Package 在主.dart文件中。

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //Set the fit size (Find your UI design, look at the dimensions of the device screen and fill it in,unit in dp)
    return ScreenUtilInit(
      designSize: Size(360, 690),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: () =>
      MaterialApp(
        //... other code
        builder: (context, widget) {
          //add this line
          ScreenUtil.setContext(context);
          return MediaQuery(
            //Setting font does not change with system font size
            data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
            child: widget!,
          );
        },
        theme: ThemeData(
          textTheme: TextTheme(
            //To support the following, you need to use the first initialization method
            button: TextStyle(fontSize: 45. sp)
          ),
        ),
      ),
    );
  }
}

相关问题