Skip to content

Instantly share code, notes, and snippets.

@anilcancakir
Created February 28, 2018 21:30
Show Gist options
  • Select an option

  • Save anilcancakir/bb69c5391344a98f072c5fec37b398de to your computer and use it in GitHub Desktop.

Select an option

Save anilcancakir/bb69c5391344a98f072c5fec37b398de to your computer and use it in GitHub Desktop.
Forms in Flutter - Code #3
import 'package:flutter/material.dart';
void main() => runApp(new MaterialApp(
title: 'Forms in Flutter',
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>();
@override
Widget build(BuildContext context) {
final Size screenSize = MediaQuery.of(context).size;
return new Scaffold(
appBar: new AppBar(
title: new Text('Login'),
),
body: 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: 'you@example.com',
labelText: 'E-mail Address'
)
),
new TextFormField(
obscureText: true, // Use secure text for passwords.
decoration: new InputDecoration(
hintText: 'Password',
labelText: 'Enter your password'
)
),
new Container(
width: screenSize.width,
child: new RaisedButton(
child: new Text(
'Login',
style: new TextStyle(
color: Colors.white
),
),
onPressed: () => null,
color: Colors.blue,
),
margin: new EdgeInsets.only(
top: 20.0
),
)
],
),
)
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment