I am building a login screen that passes data to a home screen and when I click on the login button nothing happens. No error but also no sending to a new screen.
here is the button code:
Widget submitButton()
{
return Container(
margin: EdgeInsets.all(10.0),
child:RaisedButton(
child: Text('LOGIN'),
onPressed: (){
if(formKey.currentState.validate()){
formKey.currentState.save();
print('Time to save $emailAddress and $passWord to my API');
Navigator.push(
context,
new MaterialPageRoute(
builder: (BuildContext context) =>
new Home()));
}
},
)
);
here is my routes.dart file
import 'package:flutter/material.dart';
import '../screens/home.dart';
import 'package:lbconnectv3/main.dart';
final routes = {
'/home': (BuildContext context) => new Home(),
'/' : (BuildContext context) => new LBConnectApp(),
};
EDIT
FULL CODE for main.dart, it basically has a form with 2 text fields for a login. No errors in console and it enters the if statement.
import 'package:flutter/material.dart';
import 'utils/validation.dart';
import 'screens/home.dart';
import 'utils/routes.dart';
void main() => runApp(new LBConnectApp());
class LBConnectApp extends StatefulWidget {
createState()
{
return new LBConnectAppState();
}
}
class LBConnectAppState extends State<LBConnectApp> with Validation
{
final formKey = GlobalKey<FormState>();
String emailAddress = '';
String passWord = '';
Widget build(context) {
return MaterialApp(
title: "LB Connect",
home: Scaffold(
backgroundColor: const Color(0xFF0099a9),
body:
Container(
margin: EdgeInsets.all(25.0),
child: Form(
key: formKey,
child: Column(
children: [
Container(
margin: EdgeInsets.only(top: 100.0),
child:Image.asset('images/lb_connect_trans.png')
),
emailField(),
passwordField(),
submitButton(),
],
),
),
)
),
);
}
Widget emailField()
{
return TextFormField(
keyboardType: TextInputType.emailAddress,
decoration : InputDecoration(
labelText: 'Email Address',
),
validator: validateEmail,
onSaved: (String value){
emailAddress = value;
},
);
}
Widget passwordField()
{
return TextFormField(
obscureText: true,
decoration : InputDecoration(
labelText: 'Password',
),
validator: validatePassword,
onSaved: (String value){
passWord = value;
},
);
}
Widget submitButton()
{
return Container(
margin: EdgeInsets.all(10.0),
child:RaisedButton(
child: Text('LOGIN'),
onPressed: (){
if(formKey.currentState.validate()){
formKey.currentState.save();
print('Time to save $emailAddress and $passWord to my API');
Navigator.push(
context,
new MaterialPageRoute(
builder: (BuildContext context) =>
new Home()));
}
},
)
);
}
}
if
in youronPressed
. Are you getting any error in console