【问题标题】:I'm getting late initialization error in flutter when trying to use flutter_screenutil package with introduction_screen package尝试将flutter_screenutil包与introduction_screen包一起使用时,我在flutter中遇到延迟初始化错误
【发布时间】:2021-12-26 16:37:09
【问题描述】:

当我将 .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

【问题讨论】:

    标签: android flutter mobile


    【解决方案1】:

    您需要像示例页面here中提供的那样初始化 ScreenUtil 类

    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();
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-14
      • 1970-01-01
      • 2019-11-08
      • 2020-05-10
      相关资源
      最近更新 更多