Skip to content

Commit 88c3c9d

Browse files
app [nfc]: Extract _ChooseAccountListItem to a separate widget
1 parent 9cc6700 commit 88c3c9d

File tree

1 file changed

+59
-51
lines changed

1 file changed

+59
-51
lines changed

lib/widgets/app.dart

Lines changed: 59 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,65 @@ class _PreventEmptyStack extends NavigatorObserver {
308308
class ChooseAccountPage extends StatelessWidget {
309309
const ChooseAccountPage({super.key});
310310

311-
Widget _buildAccountItem(
312-
BuildContext context, {
313-
required int accountId,
314-
required Widget title,
315-
Widget? subtitle,
316-
}) {
311+
@override
312+
Widget build(BuildContext context) {
313+
final colorScheme = ColorScheme.of(context);
314+
final zulipLocalizations = ZulipLocalizations.of(context);
315+
assert(!PerAccountStoreWidget.debugExistsOf(context));
316+
final globalStore = GlobalStoreWidget.of(context);
317+
318+
// Borrowed from [AppBar.build].
319+
// See documentation on [ModalRoute.impliesAppBarDismissal]:
320+
// > Whether an [AppBar] in the route should automatically add a back button or
321+
// > close button.
322+
final hasBackButton = ModalRoute.of(context)?.impliesAppBarDismissal ?? false;
323+
324+
return MenuButtonTheme(
325+
data: MenuButtonThemeData(style: MenuItemButton.styleFrom(
326+
backgroundColor: colorScheme.secondaryContainer,
327+
foregroundColor: colorScheme.onSecondaryContainer)),
328+
child: Scaffold(
329+
appBar: AppBar(
330+
titleSpacing: hasBackButton ? null : 16,
331+
title: Text(zulipLocalizations.chooseAccountPageTitle),
332+
actions: const [ChooseAccountPageOverflowButton()]),
333+
body: SafeArea(
334+
minimum: const EdgeInsets.fromLTRB(8, 0, 8, 8),
335+
child: Center(
336+
child: ConstrainedBox(
337+
constraints: const BoxConstraints(maxWidth: 400),
338+
child: Column(mainAxisSize: MainAxisSize.min, children: [
339+
Flexible(child: SingleChildScrollView(
340+
padding: const EdgeInsets.only(top: 8),
341+
child: Column(mainAxisSize: MainAxisSize.min, children: [
342+
for (final (:accountId, :account) in globalStore.accountEntries)
343+
_ChooseAccountListItem(
344+
accountId: accountId,
345+
title: Text(account.realmUrl.toString()),
346+
subtitle: Text(account.email)),
347+
]))),
348+
const SizedBox(height: 12),
349+
ElevatedButton(
350+
onPressed: () => Navigator.push(context,
351+
AddAccountPage.buildRoute()),
352+
child: Text(zulipLocalizations.chooseAccountButtonAddAnAccount)),
353+
]))))));
354+
}
355+
}
356+
357+
class _ChooseAccountListItem extends StatelessWidget {
358+
const _ChooseAccountListItem({
359+
required this.accountId,
360+
required this.title,
361+
required this.subtitle,
362+
});
363+
364+
final int accountId;
365+
final Widget title;
366+
final Widget? subtitle;
367+
368+
@override
369+
Widget build(BuildContext context) {
317370
final colorScheme = ColorScheme.of(context);
318371
final designVariables = DesignVariables.of(context);
319372
final zulipLocalizations = ZulipLocalizations.of(context);
@@ -359,51 +412,6 @@ class ChooseAccountPage extends StatelessWidget {
359412
contentPadding: const EdgeInsetsDirectional.only(start: 16, end: 12),
360413
onTap: () => HomePage.navigate(context, accountId: accountId)));
361414
}
362-
363-
@override
364-
Widget build(BuildContext context) {
365-
final colorScheme = ColorScheme.of(context);
366-
final zulipLocalizations = ZulipLocalizations.of(context);
367-
assert(!PerAccountStoreWidget.debugExistsOf(context));
368-
final globalStore = GlobalStoreWidget.of(context);
369-
370-
// Borrowed from [AppBar.build].
371-
// See documentation on [ModalRoute.impliesAppBarDismissal]:
372-
// > Whether an [AppBar] in the route should automatically add a back button or
373-
// > close button.
374-
final hasBackButton = ModalRoute.of(context)?.impliesAppBarDismissal ?? false;
375-
376-
return MenuButtonTheme(
377-
data: MenuButtonThemeData(style: MenuItemButton.styleFrom(
378-
backgroundColor: colorScheme.secondaryContainer,
379-
foregroundColor: colorScheme.onSecondaryContainer)),
380-
child: Scaffold(
381-
appBar: AppBar(
382-
titleSpacing: hasBackButton ? null : 16,
383-
title: Text(zulipLocalizations.chooseAccountPageTitle),
384-
actions: const [ChooseAccountPageOverflowButton()]),
385-
body: SafeArea(
386-
minimum: const EdgeInsets.fromLTRB(8, 0, 8, 8),
387-
child: Center(
388-
child: ConstrainedBox(
389-
constraints: const BoxConstraints(maxWidth: 400),
390-
child: Column(mainAxisSize: MainAxisSize.min, children: [
391-
Flexible(child: SingleChildScrollView(
392-
padding: const EdgeInsets.only(top: 8),
393-
child: Column(mainAxisSize: MainAxisSize.min, children: [
394-
for (final (:accountId, :account) in globalStore.accountEntries)
395-
_buildAccountItem(context,
396-
accountId: accountId,
397-
title: Text(account.realmUrl.toString()),
398-
subtitle: Text(account.email)),
399-
]))),
400-
const SizedBox(height: 12),
401-
ElevatedButton(
402-
onPressed: () => Navigator.push(context,
403-
AddAccountPage.buildRoute()),
404-
child: Text(zulipLocalizations.chooseAccountButtonAddAnAccount)),
405-
]))))));
406-
}
407415
}
408416

409417
class ChooseAccountPageOverflowButton extends StatelessWidget {

0 commit comments

Comments
 (0)