I am new to flutter and I am trying to add an image on the same screen which contains the login, but I have the following error:
flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during performResize():
flutter: Vertical viewport was given unbounded height.
flutter: Viewports expand in the scrolling direction to fill their container.In this case, a vertical
flutter: viewport was given an unlimited amount of vertical space in which to expand. This situation
flutter: typically happens when a scrollable widget is nested inside another scrollable widget.
flutter: If this widget is always nested in a scrollable widget there is no need to use a viewport because
flutter: there will always be enough vertical space for the children. In this case, consider using a Column
flutter: instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
flutter: the height of the viewport to the sum of the heights of its children.
My code is the following:
import 'package:flutter/material.dart';
import 'package:validate/validate.dart';
void main() => runApp(new MaterialApp(
title: 'Login',
home: new LoginPage(),
));
class LoginPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => new _LoginPageState();
}
class _LoginData {
String email = '';
String password = '';
}
class _LoginPageState extends State<LoginPage> {
final GlobalKey<FormState> _formKey = new GlobalKey<FormState>();
_LoginData _data = new _LoginData();
String _validateEmail(String value) {
// If empty value, the isEmail function throw a error.
// So I changed this function with try and catch.
try {
Validate.isEmail(value);
} catch (e) {
return 'Debe ingresar un RUT válido.';
}
return null;
}
String _validatePassword(String value) {
if (value.length < 6) {
return 'La contraseña debe ser al menos de 6 caracteres..';
}
return null;
}
void submit() {
// First validate form.
if (this._formKey.currentState.validate()) {
_formKey.currentState.save(); // Save our form now.
print('Printing the login data.');
print('Email: ${_data.email}');
print('Password: ${_data.password}');
}
}
@override
//Colores
final morado = const Color(0xFF913a90);
final naranjo = const Color(0xFFf15a24);
final gris = const Color(0xFF525252);
final double textSize = 40.0;
Widget build(BuildContext context) {
final Size screenSize = MediaQuery.of(context).size;
return new Scaffold(
appBar: new AppBar(
title: new Text('Espacio Seguro'),
backgroundColor: morado,
),
body: new ListView(
children: <Widget>[
new Image.asset(
'images/logo_login.png',
width: 80.0,
height: 100.0,
),
new Container(
padding: new EdgeInsets.all(20.0),
child: new Form(
key: this._formKey,
child: new ListView(
children: <Widget>[
new TextFormField(
keyboardType: TextInputType
.emailAddress, // Use email input type for emails.
decoration: new InputDecoration(
hintText: 'Ejemplo: 12.304.248-5',
labelText: 'Ingresar RUT',
icon: Icon(Icons.account_circle),
),
validator: this._validateEmail,
onSaved: (String value) {
this._data.email = value;
}),
new TextFormField(
obscureText: true, // Use secure text for passwords.
decoration: new InputDecoration(
hintText: 'Ingresar contraseña',
labelText: 'Ingresar Contraseña',
icon: Icon(Icons.lock)),
validator: this._validatePassword,
onSaved: (String value) {
this._data.password = value;
}),
new Container(
width: screenSize.width,
child: new RaisedButton(
child: new Text(
'Ingresar',
style: new TextStyle(color: Colors.white),
),
onPressed: this.submit,
color: naranjo,
),
margin: new EdgeInsets.only(top: 20.0),
)
],
),
)),
],
));
}
}