The error is as follows
reason
We use ScreenUtil().screenWidth in the layout to obtain the screen width. When initializing the unloaded view, it cannot be obtained the first time it is obtained, and the above crash will occur.
solution
import 'package:flutter_screenutil/screenutil_init.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
@override
Widget build(BuildContext context) {
//使用屏幕初始化包裹整个body布局
return ScreenUtilInit(
//设置初始化屏幕大小
designSize: Size(375, 812),
builder: () => Scaffold(
backgroundColor: WBColors.color_f4f5f7,
body: Container(
height: 263.5,
width: ScreenUtil().screenWidth,
)
)
);
}
- Use ScreenUtilInit screen initialization component to wrap the outermost layer of the entire page layout
- Set the initial size of the screen
- The API for obtaining the width and height of the screen can be used arbitrarily in the body
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。