尝试将 flutter_screenutil 包与 introduction_screen 包一起使用时,我在 flutter 中遇到了延迟初始化错误
I'm getting late initialization error in flutter when trying to use flutter_screenutil package with introduction_screen package
当我将 .w、.h、.sp 添加到 double 值时出现延迟初始化错误,例如
top: 16.h
或
right: 16.w
这是代码
https://drive.google.com/file/d/1yN2AqKF2LOMFYkX9PzsTVz_o5hktSY0D/view?usp=sharing
这些是我安装的包
dev_dependencies:
flutter_test:
sdk: flutter
google_fonts: 2.1.0
flutter_screenutil: ^5.0.0+2
page_transition: ^2.0.4
introduction_screen: ^2.1.0
您需要像示例页面中提供的那样初始化 ScreenUtil class here
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
//You need to add this line to your code
//Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the 360*690(dp)
ScreenUtil.init(
BoxConstraints(
maxWidth: MediaQuery.of(context).size.width,
maxHeight: MediaQuery.of(context).size.height),
designSize: Size(360, 690),
minTextAdapt: true,
orientation: Orientation.portrait);
return Scaffold();
}
}
当我将 .w、.h、.sp 添加到 double 值时出现延迟初始化错误,例如
top: 16.h
或
right: 16.w
这是代码 https://drive.google.com/file/d/1yN2AqKF2LOMFYkX9PzsTVz_o5hktSY0D/view?usp=sharing
这些是我安装的包
dev_dependencies:
flutter_test:
sdk: flutter
google_fonts: 2.1.0
flutter_screenutil: ^5.0.0+2
page_transition: ^2.0.4
introduction_screen: ^2.1.0
您需要像示例页面中提供的那样初始化 ScreenUtil class here
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
//You need to add this line to your code
//Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the 360*690(dp)
ScreenUtil.init(
BoxConstraints(
maxWidth: MediaQuery.of(context).size.width,
maxHeight: MediaQuery.of(context).size.height),
designSize: Size(360, 690),
minTextAdapt: true,
orientation: Orientation.portrait);
return Scaffold();
}
}