如何修复布局过程中抛出的以下断言:I/flutter(9632):RenderFlex底部溢出77个像素.I/flutt



当我试图在flutter 中打开屏幕时,我收到了这个错误

The overflowing RenderFlex has an orientation of Axis.vertical.
I/flutter ( 9632): The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
I/flutter ( 9632): black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
I/flutter ( 9632): Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
I/flutter ( 9632): RenderFlex to fit within the available space instead of being sized to their natural size.
I/flutter ( 9632): This is considered an error condition because it indicates that there is content that cannot be
I/flutter ( 9632): seen. If the content is legitimately bigger than the available space, consider clipping it with a
I/flutter ( 9632): ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
I/flutter ( 9632): like a ListView.
I/flutter ( 9632): The specific RenderFlex in question is: RenderFlex#86692 relayoutBoundary=up6 OVERFLOWING:
I/flutter ( 9632):   needs compositing
I/flutter ( 9632):   creator: Column ← _FormScope ← WillPopScope ← Form ← Center ← DecoratedBox ← Container ←
I/flutter ( 9632):     _BodyBuilder ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ←
I/flutter ( 9632):     AnimatedBuilder ← ⋯
I/flutter ( 9632):   parentData: offset=Offset(0.0, 0.0) (can use size)
I/flutter ( 9632):   constraints: BoxConstraints(0.0<=w<=411.4, 0.0<=h<=435.4)
I/flutter ( 9632):   size: Size(411.4, 435.4)
I/flutter ( 9632):   direction: vertical
I/flutter ( 9632):   mainAxisAlignment: start
I/flutter ( 9632):   mainAxisSize: min
I/flutter ( 9632):   crossAxisAlignment: center
I/flutter ( 9632):   verticalDirection: down
I/flutter ( 9632): ◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
I/flutter ( 9632): ════════════════════════════════════════════════════════════════════════════════════════════════════

这是我的代码

import 'package:flutter/material.dart';
class Authform extends StatefulWidget {
@override
_AuthformState createState() => _AuthformState();
Widget build(BuildContext context) {

}
}
class _AuthformState extends State<Authform> {
final _formKey = GlobalKey <FormState> ();
var _isLogin = true;
var _userCivilID = '';
var _userName = '';
var _userNationality = '';
var _userEmail = '';
var _userPassword = '';
void _trySumbit() {
final isValid = _formKey.currentState.validate();
FocusScope.of(context).unfocus();
if (isValid)
{
_formKey.currentState.save();
print(_userEmail);
print(_userPassword);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("images/bk.jpg"),
fit: BoxFit.cover,
),
),


child: Center(
child: Form(child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget> [
ListTile(
title: Row(
children: <Widget>[
Expanded(child: RaisedButton(
onPressed: () {},
child: Text("Civilian"),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.black),
),
),
),
Expanded(child: RaisedButton(
onPressed: () {},
child: Text("Police"),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.black),
),),
),],
),
),
Container( child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(45.0),
side: BorderSide(color: Colors.black)),
margin: EdgeInsets.all(40),
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(16),
child: Form(
key: _formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget> [

if(!_isLogin)
TextFormField(
key: ValueKey ('Name'),
validator: (value) {
if (value.isEmpty )
{
return 'Please enter your name';
}
return null;
},
keyboardType: TextInputType.name,
decoration: InputDecoration(
labelText: 'Name',
),
onSaved: (value) {
_userName = value;
},
),

if(!_isLogin)
TextFormField(
key: ValueKey ('Civil ID'),
validator: (value) {
if (value.isEmpty )
{
return 'Please enter a valid Civil ID';
}
return null;
},
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Civil ID',
),
onSaved: (value) {
_userCivilID = value;
},
),
TextFormField(
key: ValueKey ('Email'),
validator: (value) {
if (value.isEmpty || !value.contains('@'))
{
return 'Please enter a valid email address';
}
return null;
},
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: 'Email Address',
),
onSaved: (value) {
_userEmail = value;
},
),
TextFormField(
key: ValueKey ('password'),
validator: (value) {
if (value.isEmpty || value.length < 7)
{
return 'Password must be at least 7 characters long';
}
return null;
},
decoration: InputDecoration(
labelText: 'Password'
),
obscureText: true,
onSaved: (value) {
_userPassword = value;
},
),
SizedBox(height: 12),
RaisedButton(
child: Text (_isLogin ? 'Login' : 'Sign up'),
onPressed: _trySumbit,
),
FlatButton( child: Text ( _isLogin ?'Create new account' : 'I already have an account'),
onPressed: () {
setState(() {
_isLogin = !_isLogin;
});
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.black)
),)
],
),
),
),
),
),
),
/* add child content here */

//)
],
),
),
),
),
);
}
}

SingleChildScrollView包裹整个假发child: Center,并移除另一个SingleChildScrollView

相关内容

最新更新