Closed longfit closed 2 years ago
Not yet adapted for the latest version
Is there any solution for this issue?
try this:
return MediaQuery(
data: MediaQueryData.fromWindow(WidgetsBinding.instance.window),
child: ScreenUtilInit(
...
or try master
Same result FlutterError (No MediaQuery widget ancestor found. LayoutBuilder widgets require a MediaQuery widget ancestor.
class MyApp extends StatelessWidget { // This widget is the root of your application.
final ThemeData myTheme = ThemeData(); @override Widget build(BuildContext context) {
return
MediaQuery(
data: MediaQueryData.fromWindow(WidgetsBinding.instance.window),
child:
ScreenUtilInit(
// designSize: Size(750, 1334),
designSize: Size(360, 690),
minTextAdapt: true,
splitScreenMode: true,
// allowFontScaling: false,
builder: () => MultiProvider(
providers: [
// ChangeNotifierProvider<CartViewModel>.value(value: _cartViewModel),
// ChangeNotifierProvider<UserViewModel>.value(
// value: _userViewModel),
ChangeNotifierProvider(create: (_) => UserViewModel()),
ChangeNotifierProvider(create: (_) => MunitViewModel()),
ChangeNotifierProvider(create: (_) => VendorViewModel()),
ChangeNotifierProvider(create: (_) => StockTakenViewModel()),
ChangeNotifierProvider(create: (_) => MedicineViewModel()),
ChangeNotifierProvider(create: (_) => MediSearchViewModel()),
ChangeNotifierProvider(create: (_) => PoViewModel()),
ChangeNotifierProvider(create: (_) => PoDetViewModel()),
],
child: MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('zh', 'CH'),
const Locale('en', 'US'),
],
locale: const Locale('zh'),
title: '一心堂',
debugShowCheckedModeBanner: false,
home: LoginYst(),
// builder: EasyLoading.init(),
//below builder modified by wing 2022/02/07
builder: EasyLoading.init(builder: (context,home) {
//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: home,
);
}),
// builder: EasyLoading.init(),
))));
} }
change to
ScreenUtilInit(
MaterialApp(
Adjusting the position of ScreenUtilInit Or use the second initialization method
flutter master 2.10-0-1.0.pre.333 After I upgrade from 5.0.1 to 5.1.1 version and modified , it can work properly
But I have upgraded flutter master 2.11.0-0.0.pre.455 Cannot work properly
Error Shown
Exception has occurred. FlutterError (No MediaQuery widget ancestor found. LayoutBuilder widgets require a MediaQuery widget ancestor. The specific widget that could not find a MediaQuery ancestor was: LayoutBuilder The ownership chain for the affected widget is: "LayoutBuilder ← ScreenUtilInit ← MyApp ← [root]" No MediaQuery ancestor could be found starting from the context that was passed to MediaQuery.of(). This can happen because you have not added a WidgetsApp, CupertinoApp, or MaterialApp widget (those widgets introduce a MediaQuery), or it can happen if the context you use comes from a widget above those widgets.)
Based On flutter_screenutil 5.1.1 Widget can work ( flutter master 2.10-0-1.0.pre.333) , Fail flutter master 2.11.0-0.0.pre.455
ScreenUtil().setSp(19) which came out above error
based on method 1 Where is wrong caused new flutter master 2.11.0-0.0.pre.455
class MyApp extends StatelessWidget { // This widget is the root of your application.
final ThemeData myTheme = ThemeData(); @override Widget build(BuildContext context) { // ScreenUtil = ScreenUtil(width: 750, height: 1334)..init(context);
} }
best Regards