Skip to content

Commit 28b85cb

Browse files
committed
login: Show progress indicator during server-settings request
Fixes-partly: zulip#35
1 parent 01ebad4 commit 28b85cb

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

lib/widgets/login.dart

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ class AddAccountPage extends StatefulWidget {
109109
}
110110

111111
class _AddAccountPageState extends State<AddAccountPage> {
112+
bool _inProgress = false;
113+
112114
final ServerUrlTextEditingController _controller = ServerUrlTextEditingController();
113115
late ServerUrlParseResult _parseResult;
114116

@@ -141,17 +143,25 @@ class _AddAccountPageState extends State<AddAccountPage> {
141143
}
142144
assert(url != null);
143145

144-
// TODO(#35): show feedback that we're working, while fetching server settings
145-
final serverSettings = await getServerSettings(realmUrl: url!);
146-
// https://github.com/dart-lang/linter/issues/4007
147-
// ignore: use_build_context_synchronously
148-
if (!context.mounted) {
149-
return;
150-
}
146+
setState(() {
147+
_inProgress = true;
148+
});
149+
try {
150+
final serverSettings = await getServerSettings(realmUrl: url!);
151+
// https://github.com/dart-lang/linter/issues/4007
152+
// ignore: use_build_context_synchronously
153+
if (!context.mounted) {
154+
return;
155+
}
151156

152-
// TODO(#36): support login methods beyond email/password
153-
Navigator.push(context,
154-
EmailPasswordLoginPage.buildRoute(serverSettings: serverSettings));
157+
// TODO(#36): support login methods beyond email/password
158+
Navigator.push(context,
159+
EmailPasswordLoginPage.buildRoute(serverSettings: serverSettings));
160+
} finally {
161+
setState(() {
162+
_inProgress = false;
163+
});
164+
}
155165
}
156166

157167
@override
@@ -164,7 +174,11 @@ class _AddAccountPageState extends State<AddAccountPage> {
164174

165175
// TODO(#35): more help to user on entering realm URL
166176
return Scaffold(
167-
appBar: AppBar(title: const Text('Add an account')),
177+
appBar: AppBar(title: const Text('Add an account'),
178+
bottom: _inProgress
179+
? const PreferredSize(preferredSize: Size.fromHeight(4),
180+
child: LinearProgressIndicator(minHeight: 4)) // 4 restates default
181+
: null),
168182
body: SafeArea(
169183
minimum: const EdgeInsets.all(8),
170184
child: Center(
@@ -181,7 +195,7 @@ class _AddAccountPageState extends State<AddAccountPage> {
181195
helperText: kLayoutPinningHelperText)),
182196
const SizedBox(height: 8),
183197
ElevatedButton(
184-
onPressed: errorText == null
198+
onPressed: !_inProgress && errorText == null
185199
? () => _onSubmitted(context)
186200
: null,
187201
child: const Text('Continue')),

0 commit comments

Comments
 (0)