gpt4 book ai didi

flutter - ScreenUtil.instance = ScreenUtil(宽度:750,高度:1334,allowFontScaling:true);为什么给我错误?

转载 作者:行者123 更新时间:2023-12-03 03:23:37 29 4
gpt4 key购买 nike

在youtube上观看了有关设计应用程序登录页面的视频后,我逐行复制了代码,但是这两行login.dart给我一个错误。这两条线是什么意思?

ScreenUtil.instance = ScreenUtil.getInstance()..init(context);
ScreenUtil.instance = ScreenUtil(width: 750, height: 1334, allowFontScaling: true);

这是login.dart页面代码
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';


class LoginPage extends StatefulWidget {
@override
_LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {

@override
Widget build(BuildContext context) {
ScreenUtil.instance = ScreenUtil.getInstance()..init(context);
ScreenUtil.instance =
ScreenUtil(width: 750, height: 1334, allowFontScaling: true);
return Scaffold(
backgroundColor: Colors.white,
resizeToAvoidBottomPadding: true,
body: Stack(
fit: StackFit.expand,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 50.0, right: 20.0),
child: Image.asset("assets/login_logo.png"),
),
Expanded(
child: Container(),
),
Image.asset("assets/image_02.png")
],
),
SingleChildScrollView(
child: Padding(
padding: EdgeInsets.fromLTRB(28.0, 50.0, 28.0, 0.0),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Image.asset("assets/logo.png")
],
),
],
),
),
),
],
),
);
}
}

我在pubspec.yaml文件中添加了屏幕实用程序打包 flutter_screenutil:^ 1.0.2

最佳答案

在此视频中,使用了flutter_screenutil的旧版本:0.7.0
您正在使用1.0.2和API has been changed in 1.0.0

因此,代替:

ScreenUtil.instance = ScreenUtil.getInstance()..init(context);
ScreenUtil.instance = ScreenUtil(width: 750, height: 1334, allowFontScaling: true);

您应该使用:

ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);

并且,而不是:

ScreenUtil.getInstance().setWidth(...); // or .setHeight(...)

您应该使用:

ScreenUtil().setWidth(...); // or .setHeight(...);

关于flutter - ScreenUtil.instance = ScreenUtil(宽度:750,高度:1334,allowFontScaling:true);为什么给我错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60282476/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com