I am using flutter_screenutil and
The following code used to work, but it gives me this error when I try to run it:
Error: The argument type 'MaterialApp Function()' can't be assigned to the parameter type 'Widget Function(BuildContext)'.
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (_) {
return themeChanger;
},
),
ChangeNotifierProvider(
create: (_) {
return settingChanger;
},
),
ChangeNotifierProvider(create: (_) {
return locationChanger;
})
],
child: Consumer2<DarkThemeProvider, AdvancedSettingsProvider>(
builder: (context, value1, value2, child) {
return
ScreenUtilInit(
designSize: Size(1080, 2160),
builder: () =>
MaterialApp(
builder: (context, widget) {
ScreenUtil.setContext(context);
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1),
child: widget!);
},
theme: Styles.themeData(
themeChanger.darkTheme, context, themeChanger.color),
debugShowCheckedModeBanner: false,
home: (widget.payload.isEmpty)
? Skeleton()
[enter image description here][1] : AccessedByNotifPage(
payload: widget.payload,
),
),
);
}),
);
}
}
This image shows the error:

If you use ScreenUtilInit, you must have to provide Buildcontext or pass a value in the builder function callback.
Use:
return ScreenUtilInit(
designSize: Size(1080, 2160),
builder: (BuildContext context,child) => MaterialApp(
or:
return ScreenUtilInit(
designSize: Size(1080, 2160),
builder: (_,child) => MaterialApp(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With