Closed kishangohel closed 2 years ago
Experiencing the same problem on version 5.1.0. Downgrading to version 5.0.4 fixed this issue for me.
@lizhuoyuan please suggest or add working solution as most of developers getting same error after upgrading to 5.1.1
I have tried both solutions mentioned in document but not working.
I have static file which has all Dimensions with static
key
Duplicate of https://github.com/OpenFlutter/flutter_screenutil/issues/329
@kishangohel check my comment here how I dealt with the issue https://github.com/OpenFlutter/flutter_screenutil/issues/329#issuecomment-1025002303
Remove device preview and wrap Screen Util with MaterialApp. That will fix the crash.
// main.dart
void main() {
runApp(const APP());
}
class APP extends StatelessWidget {
const APP({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return GetMaterialApp(
builder: (context, widget) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: widget!,
);
},
home: ScreenUtilInit(
designSize: const Size(360, 690),
minTextAdapt: true,
splitScreenMode: true,
builder: () {
// ScreenUtil.setContext(context);
return Theme(
data: ThemeData(
textTheme: TextTheme(button: TextStyle(fontSize: 45.sp)),
),
child: SignPage(),
);
},
),
);
}
}
//sign_page.dart
class SignPage extends StatelessWidget {
SignPage({Key? key}) : super(key: key);
final ctrl = Get.put(SignCtrl());
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"汉字 ABC abc !@#%^&",
style: TextStyle(fontSize: 10.sp),
),
),
);
}
}
这样可以解决问题,我想可能是(flutter2.8)的问题,更改了某些渲染问题? This can solve the problem. I think it may be the problem of (fluent 2.8), which has changed some rendering problems?
This was absolutely destroying me tonight and I thought it was something I did. So glad to find this thread.
Remove device preview and wrap Screen Util with MaterialApp. That will fix the crash.
I want device preview to test multiple device UI behaviour. So I can't remove it.
add ScreenUtil.setContext(context); in builder
@override
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: const Size(360, 690),
minTextAdapt: true,
builder: () {
return GetMaterialApp(
builder: (context, widget) {
**ScreenUtil.setContext(context);**
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: widget!);
},
debugShowCheckedModeBanner: false,
theme: settingService.getThemeData(context),
home: SplashPage(),
);
},
);
}
Found the fix Main.dart
void main() { WidgetsFlutterBinding.ensureInitialized(); SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]) .then((_) { runApp(MaterialApp( debugShowCheckedModeBanner: false, home: App())); }); }
App.dart
return ScreenUtilInit( builder: (){ return MaterialApp( theme: ThemeData( fontFamily: "LatoRegular" ), debugShowCheckedModeBanner: false, routes: { '/splash':(context)=>SplashScreen() },initialRoute: "/splash", ); }, //designSize: Size(screenWidth,screenHeight), );
This is breaking whole application. This kind of updates tested first and release.
please add solution if any one find.