Flutter 如何消除此错误:不正确使用ParentDataWidget
我没有使用扩展的widget,但我不知道为什么我会不断得到这个错误。 小部件库未捕获的异常,ParentDataWidget的错误使用在四个地方,我无法确切了解错误的来源。虽然这并没有阻止我使用这个应用程序,但我觉得它应该被修复。有人能帮我吗? 下面是我的代码:Flutter 如何消除此错误:不正确使用ParentDataWidget,flutter,dart,flutter-layout,flutter-dependencies,flutter-test,Flutter,Dart,Flutter Layout,Flutter Dependencies,Flutter Test,我没有使用扩展的widget,但我不知道为什么我会不断得到这个错误。 小部件库未捕获的异常,ParentDataWidget的错误使用在四个地方,我无法确切了解错误的来源。虽然这并没有阻止我使用这个应用程序,但我觉得它应该被修复。有人能帮我吗? 下面是我的代码: import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:erg_app/Anchors.dart'; import 'package:
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:erg_app/Anchors.dart';
import 'package:erg_app/api/api.dart';
import 'package:shared_preferences/shared_preferences.dart';
class LogIn extends StatefulWidget {
@override
_LogInState createState() => _LogInState();
}
class _LogInState extends State<LogIn> {
bool _isLoading = false;
TextEditingController mailController = TextEditingController();
TextEditingController passwordController = TextEditingController();
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
ScaffoldState scaffoldState;
_showMsg() {
final snackBar = SnackBar(
content: Text(
'Invalid Username or Password',
style: (TextStyle(fontSize: 18)),
),
backgroundColor: Colors.amber[900],
);
_scaffoldKey.currentState.showSnackBar(snackBar);
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
},
child: Scaffold(
key: _scaffoldKey,
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
stops: [0.0, 0.4, 0.9],
colors: [
Color(0XFF4CAF50),
Color(0xFF388E3C),
Color(0xFF075009),
],
),
),
child: ListView(
children: <Widget>[
/////////// background///////////
SizedBox(height: 30),
new Container(
width: 100.00,
height: 100.00,
decoration: new BoxDecoration(
image: new DecorationImage(
image: AssetImage('assets/images/icon.png'),
fit: BoxFit.contain,
),
)),
Column(
children: <Widget>[
Positioned(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Positioned(
left: 30,
top: 100,
child: Container(
margin: EdgeInsets.only(top: 50),
child: Center(
child: Text(
"Welcome",
style: TextStyle(
color: Colors.white,
fontSize: 23,
fontWeight: FontWeight.bold),
),
),
),
),
SizedBox(height: 30),
Card(
elevation: 4.0,
color: Colors.white,
margin: EdgeInsets.only(left: 20, right: 20),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)),
child: Padding(
padding: const EdgeInsets.all(10.0),
// child: form(key: _formKey),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
///////////// Email//////////////
TextField(
style: TextStyle(color: Color(0xFF000000)),
controller: mailController,
cursorColor: Color(0xFF9b9b9b),
keyboardType: TextInputType.text,
decoration: InputDecoration(
prefixIcon: Icon(
Icons.account_circle,
color: Colors.grey,
),
hintText: "Username",
hintStyle: TextStyle(
color: Color(0xFF9b9b9b),
fontSize: 15,
fontWeight: FontWeight.normal),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.green)),
),
),
/////////////// password////////////////////
TextField(
style: TextStyle(color: Color(0xFF000000)),
cursorColor: Color(0xFF9b9b9b),
controller: passwordController,
keyboardType: TextInputType.number,
obscureText: true,
decoration: InputDecoration(
prefixIcon: Icon(
Icons.vpn_key,
color: Colors.grey,
),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.green)),
hintText: "Password",
hintStyle: TextStyle(
color: Color(0xFF9b9b9b),
fontSize: 15,
fontWeight: FontWeight.normal),
),
),
///////////// LogIn Botton///////////////////
Padding(
padding: const EdgeInsets.all(10.0),
child: FlatButton(
child: Padding(
padding: EdgeInsets.only(
top: 8,
bottom: 8,
left: 10,
right: 10),
child: Text(
_isLoading ? 'Loging...' : 'Login',
textDirection: TextDirection.ltr,
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
decoration: TextDecoration.none,
fontWeight: FontWeight.normal,
),
),
),
color: Colors.green,
disabledColor: Colors.grey,
shape: new RoundedRectangleBorder(
borderRadius:
new BorderRadius.circular(20.0)),
onPressed: _isLoading ? null : _login,
),
),
],
),
),
),
//////////// new account///////////////
Padding(
padding: const EdgeInsets.only(top: 20),
child: InkWell(
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => LogIn()));
},
child: Text(
'Forgot Your Password?',
textDirection: TextDirection.ltr,
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
decoration: TextDecoration.none,
fontWeight: FontWeight.normal,
),
),
),
),
],
),
),
),
],
)
],
),
),
));
// Gesture ends here
}
}
导入'dart:convert';
进口“包装:颤振/材料.省道”;
导入“包:erg_app/Anchors.dart”;
导入“包:erg_app/api/api.dart”;
导入“package:shared_preferences/shared_preferences.dart”;
类登录扩展StatefulWidget{
@凌驾
_LogInState createState()=>\u LogInState();
}
类_LogInState扩展了状态{
bool_isLoading=false;
TextEditingController mailController=TextEditingController();
TextEditingController密码控制器=TextEditingController();
最终GlobalKey _scaffoldKey=新的GlobalKey();
脚手架状态脚手架状态;
_showMsg(){
最终蛇杆=蛇杆(
内容:文本(
“无效的用户名或密码”,
样式:(TextStyle(fontSize:18)),
),
背景颜色:颜色。琥珀色[900],
);
_scaffoldKey.currentState.showSnackBar(snackBar);
}
@凌驾
小部件构建(构建上下文){
返回手势检测器(
onTap:(){
FocusScopeNode currentFocus=FocusScope.of(上下文);
如果(!currentFocus.hasPrimaryFocus){
currentFocus.unfocus();
}
},
孩子:脚手架(
钥匙:_scaffoldKey,
主体:容器(
装饰:盒子装饰(
梯度:线性梯度(
开始:Alignment.topLeft,
结束:对齐。右下角,
停止:[0.0,0.4,0.9],
颜色:[
颜色(0XFF4CAF50),
颜色(0xFF388E3C),
颜色(0xFF075009),
],
),
),
子:ListView(
儿童:[
///////////背景///////////
尺寸箱(高度:30),
新容器(
宽度:100.00,
身高:100.00,
装饰:新盒子装饰(
图片:新装饰图片(
图像:AssetImage('assets/images/icon.png'),
适合:BoxFit.contain,
),
)),
纵队(
儿童:[
定位(
孩子:填充(
填充:常数边集全部(8.0),
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
定位(
左:30,,
前100名,
子:容器(
页边距:仅限边缘集(顶部:50),
儿童:中心(
子:文本(
“欢迎”,
样式:TextStyle(
颜色:颜色,白色,
尺寸:23,
fontWeight:fontWeight.bold),
),
),
),
),
尺寸箱(高度:30),
卡片(
标高:4.0,
颜色:颜色,白色,
边距:仅限边集(左:20,右:20),
形状:圆形矩形边框(
边界半径:边界半径。圆形(15)),
孩子:填充(
填充:常数边集全部(10.0),
//子项:窗体(键:_formKey),
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
/////////////电子邮件//////////////
文本字段(
样式:TextStyle(颜色:颜色(0xFF000000)),
控制器:邮件控制器,
光标颜色:颜色(0xFF9b9b9b),
键盘类型:TextInputType.text,
装饰:输入装饰(
前缀:图标(
Icons.account_圈,
颜色:颜色。灰色,
),
hintText:“用户名”,
hintStyle:TextStyle(
颜色:颜色(0xFF9b9b9b),
尺寸:15,
fontWeight:fontWeight.正常),
聚焦顺序:大纲输入边框(
边界:
BorderSide(颜色:Colors.green)),
),
),
///////////////密码////////////////////
文本字段(
样式:TextStyle(颜色:颜色(0xFF000000)),
光标颜色:颜色(0xFF9b9b9b)