-
Notifications
You must be signed in to change notification settings - Fork 0
/
form em pass.dart
90 lines (84 loc) · 2.52 KB
/
form em pass.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
import 'package:flutter/material.dart';
void main() {
runApp(EmployeeForm());
}
class EmployeeForm extends StatefulWidget {
@override
_EmployeeFormState createState() => _EmployeeFormState();
}
class _EmployeeFormState extends State<EmployeeForm> {
final _formKey = GlobalKey<FormState>();
late String _password;
late String _email;
void submitform() {
print("Here");
showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
content: Text("hi"),
));
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Employee Form',
home: Scaffold(
appBar: AppBar(
title: Text('Employee Form'),
),
body: Form(
key: _formKey,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextFormField(
decoration: InputDecoration(
labelText: 'Email',
),
validator: (value) {
if (value!.isEmpty) {
return 'Please enter an email';
}
return null;
},
onSaved: (value) {
_email = value!;
},
),
TextFormField(
obscureText: true,
decoration: InputDecoration(
labelText: 'Password',
),
validator: (value) {
if (value!.isEmpty) {
return 'Please enter a password';
}
return null;
},
onSaved: (value) {
_password = value!;
},
),
Center(
child: ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
// Do something with the form data
submitform();
}
},
child: Text('Submit'),
),
),
],
),
),
),
),
);
}
}