我在试着让一个登录屏幕飘飘欲仙。此登录连接到电子邮件和密码,但有一些问题.在布局过程中,物体周围的误差被赋予无限大的大小。附加的是我的Dart类的代码和运行代码时记录的错误。
你们从我无法解决的错误代码中得到了什么?
Dart类
import 'package:flutter/material.dart';
import 'package:loja_virtual/models/user_model.dart';
import 'package:scoped_model/scoped_model.dart';
class FormContainer extends StatelessWidget {
final _emailController = TextEditingController();
final _passController = TextEditingController();
final _formKey = GlobalKey<FormState>();
final _scaffoldKey = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
body: ScopedModelDescendant<UserModel>(
builder: (context, child, model) {
if (model.isLoading)
return Center(child: CircularProgressIndicator(),);
return Container(
margin: EdgeInsets.symmetric(horizontal: 20),
child: Form(
key: _formKey,
child: Column(
children: <Widget>[
TextFormField(
style: TextStyle(
color: Colors.white),
controller: _passController,
decoration: InputDecoration(
hintStyle: TextStyle(color: Colors.white,fontFamily: "WorkSansLight", fontSize: 18.0),
filled: true,
fillColor: Colors.white24,
hintText: "E-mail",
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(90.0)),
borderSide: BorderSide(color: Colors.white24, width: 0.5)),
prefixIcon: const Icon(
Icons.email,
color: Colors.white,
),
),
keyboardType: TextInputType.emailAddress,
validator: (text){
if(text.isEmpty || !text.contains("@")) return "E-mail inválido!";
},
),
SizedBox(height: 16.0,),
TextFormField(
style: TextStyle(
color: Colors.white),
controller: _passController,
decoration: InputDecoration(
hintStyle: TextStyle(color: Colors.white,fontFamily: "WorkSansLight", fontSize: 18.0),
filled: true,
fillColor: Colors.white24,
hintText: "Senha",
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(90.0)),
borderSide: BorderSide(color: Colors.white24, width: 0.5)),
prefixIcon: const Icon(
Icons.lock_outline,
color: Colors.white,
),
),
obscureText: true,
validator: (text){
if(text.isEmpty || text.length < 6) return "Senha inválida!";
},
),
Align(
alignment: Alignment.centerRight,
child: FlatButton(
onPressed: (){
if(_emailController.text.isEmpty)
_scaffoldKey.currentState.showSnackBar(
SnackBar(content: Text("Insira seu e-mail para recuperação!"),
backgroundColor: Colors.redAccent,
duration: Duration(seconds: 2),
)
);
else {
model.recoverPass(_emailController.text);
_scaffoldKey.currentState.showSnackBar(
SnackBar(content: Text("Confira seu e-mail!"),
backgroundColor: Colors.purple,
duration: Duration(seconds: 2),
)
);
}
},
child: Text("Esqueci minha senha",
textAlign: TextAlign.right,
style: TextStyle(color: Colors.white, fontSize: 15.0),
),
padding: EdgeInsets.zero,
),
),
SizedBox(
height: 16,
),
SizedBox(
height: 80,
width: 80,
child: new FloatingActionButton(
backgroundColor: Colors.white30,
child: Text(
"Entrar",
style: TextStyle(
fontSize: 18.0,
),
),
onPressed: () {
if (_formKey.currentState.validate()) {
}
model.signIn(
email: _emailController.text,
pass: _passController.text,
onSuccess: _onSuccess,
onFail: _onFail
);
},
),
),
],
),
),
);
},
)
);
}
void _onSuccess() {
// Navigator.of(context).pop(); Esta dando erro
}
void _onFail() {
_scaffoldKey.currentState.showSnackBar(
SnackBar(content: Text("Falha ao Entrar!"),
backgroundColor: Colors.redAccent,
duration: Duration(seconds: 3),
)
);
}
}误差
I/flutter ( 4207): The following assertion was thrown during performLayout():
I/flutter ( 4207): RenderCustomMultiChildLayoutBox object was given an infinite size during layout.
I/flutter ( 4207): This probably means that it is a render object that tries to be as big as possible, but it was put inside
another render object that allows its children to pick their own size.
I/flutter ( 4207): The nearest ancestor providing an unbounded height constraint is: RenderIndexedSemantics#dc596
relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 4207): creator: IndexedSemantics ← NotificationListener<KeepAliveNotification> ← KeepAlive ←
I/flutter ( 4207): AutomaticKeepAlive ← SliverList ← SliverPadding ← Viewport ← IgnorePointer-[GlobalKey#aaf31] ←
I/flutter ( 4207): Semantics ← Listener ← _GestureSemantics ←
I/flutter ( 4207): RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#1430c] ←
I/flutter ( 4207): parentData: index=0; layoutOffset=0.0 (can use size)
I/flutter ( 4207): constraints: BoxConstraints(w=360.0, 0.0<=h<=Infinity)
I/flutter ( 4207): semantic boundary
I/flutter ( 4207): size: Size(360.0, Infinity)
I/flutter ( 4207): index: 0
I/flutter ( 4207): The constraints that applied to the RenderCustomMultiChildLayoutBox were:
I/flutter ( 4207): BoxConstraints(0.0<=w<=360.0, 0.0<=h<=Infinity)
I/flutter ( 4207): The exact size it was given was:
I/flutter ( 4207): Size(360.0, Infinity)发布于 2019-07-17 14:13:02
我的答案是:
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart' show timeDilation;
import 'package:loja_virtual/models/user_model.dart';
import 'package:loja_virtual/widgets/sign_up_button.dart';
import 'package:flare_flutter/flare_actor.dart';
import 'package:scoped_model/scoped_model.dart';
class NewLoginScreen extends StatefulWidget {
@override
_NewLoginScreenState createState() => _NewLoginScreenState();
}
class _NewLoginScreenState extends State<NewLoginScreen> {
final _emailController = TextEditingController();
final _passController = TextEditingController();
final _formKey = GlobalKey<FormState>();
final _scaffoldKey = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(backgroundColor: Colors.transparent),
body: ScopedModelDescendant<UserModel>(
builder: (context, child, model) {
if (model.isLoading)
return Center(
child: CircularProgressIndicator(),
);
return Form(
key: _formKey,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("images/background1.jpg"),
fit: BoxFit.cover)),
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
Column(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 10, bottom: 10),
child: Image.asset(
"images/user1.png",
width: 130,
height: 130,
fit: BoxFit.contain,
),
),
TextFormField(
style: TextStyle(color: Colors.white),
controller: _emailController,
decoration: InputDecoration(
hintStyle: TextStyle(
color: Colors.white,
fontFamily: "WorkSansLight",
fontSize: 15.0),
filled: true,
fillColor: Colors.white24,
hintText: "E-mail",
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(90.0)),
borderSide: BorderSide(
color: Colors.white24, width: 0.5)),
prefixIcon: const Icon(
Icons.email,
color: Colors.white,
),
),
keyboardType: TextInputType.emailAddress,
validator: (text) {
if (text.isEmpty || !text.contains("@"))
return "E-mail inválido!";
},
),
SizedBox(
height: 10.0,
),
TextFormField(
style: TextStyle(color: Colors.white),
controller: _passController,
decoration: InputDecoration(
hintStyle: TextStyle(
color: Colors.white,
fontFamily: "WorkSansLight",
fontSize: 15.0),
filled: true,
fillColor: Colors.white24,
hintText: "Senha",
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(90.0)),
borderSide: BorderSide(
color: Colors.white24, width: 0.5)),
prefixIcon: const Icon(
Icons.lock_outline,
color: Colors.white,
),
),
obscureText: true,
validator: (text) {
if (text.isEmpty || text.length < 6)
return "Senha inválida!";
},
),
Align(
alignment: Alignment.centerRight,
child: FlatButton(
onPressed: () {
if (_emailController.text.isEmpty)
_scaffoldKey.currentState
.showSnackBar(SnackBar(
content: Text(
"Insira seu e-mail para recuperação!"),
backgroundColor: Colors.redAccent,
duration: Duration(seconds: 2),
));
else {
model.recoverPass(_emailController.text);
_scaffoldKey.currentState
.showSnackBar(SnackBar(
content: Text("Confira seu e-mail!"),
backgroundColor: Colors.purple,
duration: Duration(seconds: 3),
));
}
},
child: Text(
"Esqueci minha senha",
textAlign: TextAlign.right,
style: TextStyle(
color: Colors.white, fontSize: 13.0),
),
padding: EdgeInsets.zero,
),
),
SizedBox(
height: 10,
),
SizedBox(
height: 80,
width: 80,
child: new FloatingActionButton(
backgroundColor: Colors.white30,
child: Text(
"Entrar",
style: TextStyle(
fontSize: 18.0,
),
),
onPressed: () {
if (_formKey.currentState.validate()) {}
model.signIn(
email: _emailController.text,
pass: _passController.text,
onSuccess: _onSuccess,
onFail: _onFail);
},
),
),
SignUpButton()
],
),
],
),
],
),
),
);
},
),
);
}
void _onSuccess() {
Navigator.of(context).pop();
}
void _onFail() {
_scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text("Falha ao Entrar!"),
backgroundColor: Colors.redAccent,
duration: Duration(seconds: 3),
));
}
}现在没事了。thx
发布于 2019-07-17 12:37:05
尝试将您的ScopedModelDescendant包装在一个灵活的(或一个固定大小的容器)中。就其本身而言,它没有任何需要大小的概念,所以您需要它是具有大小约束的事物的子级。
https://stackoverflow.com/questions/57075227
复制相似问题