Closed lurongshuang closed 1 year ago
Same here
@lurongshuang @pumppmup1 , Of course it will, it's a basic Builder after all. That's why there is child parameter and it's passed in builder method. You should use flutter_screenutil: ^5.9.0-beta
, and be sure you use child only as you won't need builder. see example below:
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@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: const Size(360, 690),
minTextAdapt: true,
splitScreenMode: true,
// Use builder only if you need to use library outside ScreenUtilInit context
builder: (_ , child) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'First Method',
// You can use the library anywhere in the app even in theme
theme: ThemeData(
primarySwatch: Colors.blue,
// to use 1.sp (ScreenUtil) the library needs to be initialized, and rebuild materialapp theme to respond to changes
// as it wont be updated automatically, it's impossible to know what's hapening outside the context
textTheme: Typography.englishLike2018.apply(fontSizeFactor: 1.sp),
),
home: child,
);
},
child: const HomePage(title: 'First Method'),
);
}
}
Example above will be:
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@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: const Size(360, 690),
minTextAdapt: true,
splitScreenMode: true,
// Don't use builder if you don't use ScreenUtil in this bloc
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'First Method',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const HomePage(title: 'First Method'),
),
);
}
}
@Mounir-Bouaiche What if I use MaterialApp.router?
@Mounir-Bouaiche What if I use MaterialApp.router?
@vovaklh , you shouldn't use any function that doesn't depend on ScreenUtil, call all your functions outside ScreenUtilInit builder bloc. I've provided example in previous issue.
widgets getting rebuild on key board appearance and pop ...any solution?
Widget build(BuildContext context) { print("main rebulded"); super.build(context); subscribeToTopics(context); if (initialRoute != RoutesPath.loginPath) addSession();
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (context) => ConnectivityProvider(),
child: const BottomNavView(),
),
ChangeNotifierProvider<PortfolioProvider>(
create: (context) => PortfolioProvider(),
)
],
child:
// AnnotatedRegion(
// value: SystemUiOverlayStyle(
// statusBarColor: Colors.transparent, //top status bar
// systemNavigationBarColor:Colors.black, // navigation bar color, the one Im looking for
// statusBarIconBrightness: Brightness.dark, // status bar icons' color
// systemNavigationBarIconBrightness:
// Brightness.dark, //navigation bar icons' color
// ),
// child:
ScreenUtilInit(
designSize: const Size(360, 690),
minTextAdapt: true,
splitScreenMode: true,
child: Consumer<AppTheme>(builder: (context, appTheme, _) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "Portal",
theme: appTheme.light(),
darkTheme: appTheme.dark(),
themeMode: appTheme.currentTheme(),
onGenerateRoute: Routes.generateRoute,
initialRoute: initialRoute,
// ),
);})
)
// }),
);
} }
Yes , this worked for me too: https://github.com/OpenFlutter/flutter_screenutil/issues/495#issuecomment-1598513177
代码
三个版本都无效
flutter_screenutil: ^5.8.3
flutter_screenutil:
git:
url: https://github.com/OpenFlutter/flutter_screenutil
ref: dev
flutter_screenutil: ^5.9.0-beta