-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.dart
139 lines (132 loc) · 4.58 KB
/
login.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import 'package:flutter/material.dart';
import 'package:parse_server_sdk/parse_server_sdk.dart';
import 'package:go_router/go_router.dart';
class Login extends StatefulWidget {
const Login({Key? key}) : super(key: key);
@override
State<Login> createState() => _LoginState();
}
class _LoginState extends State<Login> {
TextEditingController nameController = TextEditingController();
TextEditingController passwordController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('LoginDemo'),
),
body: Padding(
padding: const EdgeInsets.all(10),
child: ListView(
children: <Widget>[
Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(10),
child: const Text(
'My App',
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.w500,
fontSize: 30),
)),
Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(10),
child: const Text(
'Sign in',
style: TextStyle(fontSize: 20),
)),
Container(
padding: const EdgeInsets.all(10),
child: TextField(
controller: nameController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'User Name',
),
),
),
Container(
padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
child: TextField(
obscureText: true,
controller: passwordController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Password',
),
),
),
TextButton(
onPressed: () {
//forgot password screen
},
child: const Text(
'Forgot Password',
),
),
Container(
height: 50,
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
child: ElevatedButton(
child: const Text('Login'),
onPressed: () {
print("Controller name = ${nameController.text}");
print(
"Controller password = ${passwordController.text}");
processLogin(context, nameController.text,
passwordController.text);
},
)),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('Need an account?'),
TextButton(
child: const Text(
'Join us now',
//style: TextStyle(fontSize: 20),
),
onPressed: () {
//signup screen
print("SIGNUP PRESSED");
GoRouter.of(context).go('/signup');
},
)
],
),
],
)));
}
processLogin(context, username, password) async {
print("processLogin name = $username");
print("processLogin password = $password");
var user = ParseUser(username, password, "");
var response = await user.login();
if (response.success) {
user = response.result;
GoRouter.of(context).go('/homepage');
} else {
// set up the button
Widget okButton = TextButton(
child: const Text("OK"),
onPressed: () => Navigator.pop(context),
);
// set up the AlertDialog
AlertDialog alert = AlertDialog(
title: const Text("Error Dialog"),
content: Text('${response.error?.message}'),
actions: [
okButton,
],
);
// show the dialog
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
}
}