-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmain.dart
110 lines (105 loc) · 3.39 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import 'package:flutter/material.dart';
void main() => runApp(new InputApp());
class InputApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new InputPage(),
);
}
}
class InputPage extends StatefulWidget {
InputPage({Key key}) : super(key: key);
@override
_InputPageState createState() => new _InputPageState();
}
class _InputPageState extends State<InputPage> {
final scaffoldKey = new GlobalKey<ScaffoldState>();
final formKey = new GlobalKey<FormState>();
final TextEditingController _controller = new TextEditingController();
String _email;
String _password;
void _submit() {
final form = formKey.currentState;
if (form.validate()) {
form.save();
showDialog(
context: context,
child: new AlertDialog(
title: new Text('Alert'),
content: new Text('Email: $_email, password: $_password'),
));
}
}
@override
Widget build(BuildContext context) {
return new Scaffold(
key: scaffoldKey,
appBar: new AppBar(
title: new Text("Form Input Demo"),
),
body: new ListView(
// mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Padding(
padding: new EdgeInsets.all(20.0),
child: new TextField(
controller: _controller,
decoration: new InputDecoration(
hintText: 'Type something', labelText: "Text Field "),
),
),
new Padding(
padding: new EdgeInsets.symmetric(horizontal: 140.0),
child: new RaisedButton(
onPressed: () {
showDialog(
context: context,
child: new AlertDialog(
title: new Text('Alert'),
content: new Text('You typed ${_controller.text}'),
),
);
},
child: new Text('Submit')),
),
new Padding(
padding: new EdgeInsets.symmetric(horizontal: 10.0),
child: new Form(
key: formKey,
child: new Column(
children: <Widget>[
new TextFormField(
validator: (value) =>
!value.contains('@') ? 'Not a valid email.' : null,
onSaved: (val) => _email = val,
decoration: const InputDecoration(
icon: const Icon(Icons.person),
hintText: 'Enter your email',
labelText: 'Email',
),
),
new TextFormField(
validator: (val) =>
val.length < 6 ? 'Password too short.' : null,
onSaved: (val) => _password = val,
decoration: const InputDecoration(
icon: const Icon(Icons.lock),
hintText: 'Enter your password',
labelText: 'New Password',
),
obscureText: true,
),
new RaisedButton(
onPressed: _submit,
child: new Text('Login'),
),
],
),
),
),
],
),
);
}
}