Skip to content

Commit 5c62d37

Browse files
committed
accounts-ui: Make accounts list scrollable
Before this fix, the list of accounts did not scroll when they were more than a screenful and would show an overflow error on the screen. After this fix, the list of accounts scrolls properly with no overflow error and without shifting other content offscreen. Fixes: #100
1 parent 68116a2 commit 5c62d37

File tree

2 files changed

+72
-6
lines changed

2 files changed

+72
-6
lines changed

lib/widgets/app.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,15 @@ class ChooseAccountPage extends StatelessWidget {
194194
child: Center(
195195
child: ConstrainedBox(
196196
constraints: const BoxConstraints(maxWidth: 400),
197-
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
198-
for (final (:accountId, :account) in globalStore.accountEntries)
199-
_buildAccountItem(context,
200-
accountId: accountId,
201-
title: Text(account.realmUrl.toString()),
202-
subtitle: Text(account.email)),
197+
child: Column(mainAxisSize: MainAxisSize.min, children: [
198+
Flexible(child: SingleChildScrollView(
199+
child: Column(mainAxisSize: MainAxisSize.min, children: [
200+
for (final (:accountId, :account) in globalStore.accountEntries)
201+
_buildAccountItem(context,
202+
accountId: accountId,
203+
title: Text(account.realmUrl.toString()),
204+
subtitle: Text(account.email)),
205+
]))),
203206
const SizedBox(height: 12),
204207
ElevatedButton(
205208
onPressed: () => Navigator.push(context,

test/widgets/app_test.dart

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import 'package:checks/checks.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart';
24
import 'package:flutter/widgets.dart';
35
import 'package:flutter_test/flutter_test.dart';
6+
import 'package:zulip/model/database.dart';
47
import 'package:zulip/widgets/app.dart';
58
import 'package:zulip/widgets/inbox.dart';
69
import 'package:zulip/widgets/page.dart';
10+
import 'package:zulip/widgets/store.dart';
711

812
import '../example_data.dart' as eg;
913
import '../model/binding.dart';
14+
import '../model/test_store.dart';
1015
import '../test_navigation.dart';
1116
import 'page_checks.dart';
1217

@@ -50,5 +55,63 @@ void main() {
5055
..page.isA<InboxPage>(),
5156
]);
5257
});
58+
59+
Future<void> setupChooseAccountPage(WidgetTester tester, {
60+
List<Account>? accounts,
61+
}) async {
62+
addTearDown(testBinding.reset);
63+
64+
accounts ??= [eg.selfAccount];
65+
for (final account in accounts) {
66+
await testBinding.globalStore
67+
.insertAccount(account.toCompanion(false));
68+
}
69+
70+
await tester.pumpWidget(
71+
const MaterialApp(
72+
localizationsDelegates: ZulipLocalizations.localizationsDelegates,
73+
supportedLocales: ZulipLocalizations.supportedLocales,
74+
home: GlobalStoreWidget(
75+
child: ChooseAccountPage())));
76+
77+
// global store gets loaded
78+
await tester.pumpAndSettle();
79+
}
80+
81+
Iterable<Account> dummyAccounts(int count) sync* {
82+
var i = 0;
83+
while (i < count) {
84+
yield eg.account(
85+
id: i,
86+
user: eg.user(fullName: 'User $i', email: 'user$i@example'),
87+
apiKey: 'user${i}apikey',
88+
);
89+
i++;
90+
}
91+
}
92+
93+
Finder findAccount(Account account) {
94+
return find.text(account.email).hitTestable();
95+
}
96+
97+
void checkAccountShown(Account account, {required bool expected}) {
98+
check(findAccount(account).evaluate().length).equals(expected ? 1 : 0);
99+
}
100+
101+
testWidgets('accounts list is scrollable when more than a screenful', (tester) async {
102+
final accounts = dummyAccounts(15).toList();
103+
104+
await setupChooseAccountPage(tester, accounts: accounts);
105+
106+
// Accounts list is more than a screenful
107+
// * First account is shown
108+
// * Last account is out of view
109+
checkAccountShown(accounts.first, expected: true);
110+
checkAccountShown(accounts.last, expected: false);
111+
112+
// Accounts list is scrollable to the bottom
113+
await tester.scrollUntilVisible(findAccount(accounts.last), 50);
114+
checkAccountShown(accounts.last, expected: true);
115+
});
53116
});
54117
}

0 commit comments

Comments
 (0)