@@ -106,6 +106,8 @@ class _EmailPasswordLoginPageState extends State<EmailPasswordLoginPage> {
106
106
});
107
107
}
108
108
109
+ bool _inProgress = false ;
110
+
109
111
Future <int > _getUserId (FetchApiKeyResult fetchApiKeyResult) async {
110
112
final FetchApiKeyResult (: email, : apiKey) = fetchApiKeyResult;
111
113
final auth = Auth (
@@ -126,13 +128,20 @@ class _EmailPasswordLoginPageState extends State<EmailPasswordLoginPage> {
126
128
// TODO(#35): validate email is in the shape of an email
127
129
128
130
final FetchApiKeyResult result;
131
+ setState (() {
132
+ _inProgress = true ;
133
+ });
129
134
try {
130
135
result = await fetchApiKey (
131
136
realmUrl: realmUrl, username: email, password: password);
132
137
} on Exception catch (e) { // TODO(#37): distinguish API exceptions
133
138
// TODO(#35): give feedback to user on failed login
134
139
debugPrint (e.toString ());
135
140
return ;
141
+ } finally {
142
+ setState (() {
143
+ _inProgress = false ;
144
+ });
136
145
}
137
146
138
147
// TODO(server-7): Rely on user_id from fetchApiKey.
@@ -168,7 +177,11 @@ class _EmailPasswordLoginPageState extends State<EmailPasswordLoginPage> {
168
177
Widget build (BuildContext context) {
169
178
assert (! PerAccountStoreWidget .debugExistsOf (context));
170
179
return Scaffold (
171
- appBar: AppBar (title: const Text ('Log in' )),
180
+ appBar: AppBar (title: const Text ('Log in' ),
181
+ bottom: _inProgress
182
+ ? const PreferredSize (preferredSize: Size .fromHeight (4 ),
183
+ child: LinearProgressIndicator (minHeight: 4 ))
184
+ : null ),
172
185
body: SafeArea (
173
186
minimum: const EdgeInsets .all (8 ),
174
187
child: Center (
@@ -197,7 +210,7 @@ class _EmailPasswordLoginPageState extends State<EmailPasswordLoginPage> {
197
210
icon: _obscurePassword ? const Icon (Icons .visibility_off) : const Icon (Icons .visibility))))),
198
211
const SizedBox (height: 8 ),
199
212
ElevatedButton (
200
- onPressed: _submit,
213
+ onPressed: _inProgress ? null : _submit, // disabled if in progress
201
214
child: const Text ('Log in' )),
202
215
])))))));
203
216
}
0 commit comments