Skip to content

Commit ddc88de

Browse files
committed
login: Show progress
Fixes-partly: zulip#35
1 parent b024c25 commit ddc88de

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/widgets/login.dart

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class _EmailPasswordLoginPageState extends State<EmailPasswordLoginPage> {
106106
});
107107
}
108108

109+
bool _inProgress = false;
110+
109111
Future<int> _getUserId(FetchApiKeyResult fetchApiKeyResult) async {
110112
final FetchApiKeyResult(:email, :apiKey) = fetchApiKeyResult;
111113
final auth = Auth(
@@ -126,13 +128,20 @@ class _EmailPasswordLoginPageState extends State<EmailPasswordLoginPage> {
126128
// TODO(#35): validate email is in the shape of an email
127129

128130
final FetchApiKeyResult result;
131+
setState(() {
132+
_inProgress = true;
133+
});
129134
try {
130135
result = await fetchApiKey(
131136
realmUrl: realmUrl, username: email, password: password);
132137
} on Exception catch (e) { // TODO(#37): distinguish API exceptions
133138
// TODO(#35): give feedback to user on failed login
134139
debugPrint(e.toString());
135140
return;
141+
} finally {
142+
setState(() {
143+
_inProgress = false;
144+
});
136145
}
137146

138147
// TODO(server-7): Rely on user_id from fetchApiKey.
@@ -168,7 +177,11 @@ class _EmailPasswordLoginPageState extends State<EmailPasswordLoginPage> {
168177
Widget build(BuildContext context) {
169178
assert(!PerAccountStoreWidget.debugExistsOf(context));
170179
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),
172185
body: SafeArea(
173186
minimum: const EdgeInsets.all(8),
174187
child: Center(
@@ -197,7 +210,7 @@ class _EmailPasswordLoginPageState extends State<EmailPasswordLoginPage> {
197210
icon: _obscurePassword ? const Icon(Icons.visibility_off) : const Icon(Icons.visibility))))),
198211
const SizedBox(height: 8),
199212
ElevatedButton(
200-
onPressed: _submit,
213+
onPressed: _inProgress ? null : _submit, // disabled if in progress
201214
child: const Text('Log in')),
202215
])))))));
203216
}

0 commit comments

Comments
 (0)