Skip to content

Commit 50d39ea

Browse files
gnpricePIG208
authored andcommitted
app_bar [nfc]: Move ZulipAppBar.isLoading to within widget
This keeps call sites simpler.
1 parent a9d9ef8 commit 50d39ea

File tree

7 files changed

+25
-27
lines changed

7 files changed

+25
-27
lines changed

lib/widgets/app.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,7 @@ class HomePage extends StatelessWidget {
253253
}
254254

255255
return Scaffold(
256-
appBar: ZulipAppBar(
257-
title: const Text("Home"),
258-
isLoading: store.isLoading),
256+
appBar: ZulipAppBar(title: const Text("Home")),
259257
body: Center(
260258
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
261259
DefaultTextStyle.merge(

lib/widgets/app_bar.dart

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'package:flutter/material.dart';
22

3+
import 'store.dart';
4+
35
/// A custom [AppBar] with a loading indicator.
46
///
57
/// This should be used for most of the pages with access to [PerAccountStore].
@@ -12,11 +14,21 @@ class ZulipAppBar extends AppBar {
1214
super.backgroundColor,
1315
super.shape,
1416
super.actions,
15-
required bool isLoading,
16-
}) : super(
17-
bottom: PreferredSize(
18-
preferredSize: const Size.fromHeight(4.0),
19-
child: (isLoading)
20-
? LinearProgressIndicator(backgroundColor: backgroundColor, minHeight: 4.0)
21-
: const SizedBox.shrink()));
17+
}) : super(bottom: _ZulipAppBarBottom(backgroundColor: backgroundColor));
18+
}
19+
20+
class _ZulipAppBarBottom extends StatelessWidget implements PreferredSizeWidget {
21+
const _ZulipAppBarBottom({this.backgroundColor});
22+
23+
final Color? backgroundColor;
24+
25+
@override
26+
Size get preferredSize => const Size.fromHeight(4.0);
27+
28+
@override
29+
Widget build(BuildContext context) {
30+
final store = PerAccountStoreWidget.of(context);
31+
if (!store.isLoading) return const SizedBox.shrink();
32+
return LinearProgressIndicator(minHeight: 4.0, backgroundColor: backgroundColor);
33+
}
2234
}

lib/widgets/inbox.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ class _InboxPageState extends State<InboxPage> with PerAccountStoreAwareStateMix
161161
}
162162

163163
return Scaffold(
164-
appBar: ZulipAppBar(
165-
title: const Text('Inbox'),
166-
isLoading: store.isLoading),
164+
appBar: ZulipAppBar(title: const Text('Inbox')),
167165
body: SafeArea(
168166
// Don't pad the bottom here; we want the list content to do that.
169167
bottom: false,

lib/widgets/message_list.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
271271
return Scaffold(
272272
appBar: ZulipAppBar(
273273
title: MessageListAppBarTitle(narrow: narrow),
274-
isLoading: store.isLoading,
275274
backgroundColor: appBarBackgroundColor,
276275
shape: removeAppBarBottomBorder
277276
? const Border()

lib/widgets/profile.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ class ProfilePage extends StatelessWidget {
103103
];
104104

105105
return Scaffold(
106-
appBar: ZulipAppBar(
107-
title: Text(user.fullName),
108-
isLoading: store.isLoading),
106+
appBar: ZulipAppBar(title: Text(user.fullName)),
109107
body: SingleChildScrollView(
110108
child: Center(
111109
child: ConstrainedBox(
@@ -123,11 +121,8 @@ class _ProfileErrorPage extends StatelessWidget {
123121

124122
@override
125123
Widget build(BuildContext context) {
126-
final store = PerAccountStoreWidget.of(context);
127124
return Scaffold(
128-
appBar: ZulipAppBar(
129-
title: const Text('Error'),
130-
isLoading: store.isLoading),
125+
appBar: ZulipAppBar(title: const Text('Error')),
131126
body: const SingleChildScrollView(
132127
child: Padding(
133128
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 32),

lib/widgets/recent_dm_conversations.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ class _RecentDmConversationsPageState extends State<RecentDmConversationsPage> w
5656

5757
@override
5858
Widget build(BuildContext context) {
59-
final store = PerAccountStoreWidget.of(context);
6059
final zulipLocalizations = ZulipLocalizations.of(context);
6160
final sorted = model!.sorted;
6261
return Scaffold(
6362
appBar: ZulipAppBar(
64-
title: Text(zulipLocalizations.recentDmConversationsPageTitle),
65-
isLoading: store.isLoading),
63+
title: Text(zulipLocalizations.recentDmConversationsPageTitle)),
6664
body: SafeArea(
6765
// Don't pad the bottom here; we want the list content to do that.
6866
bottom: false,

lib/widgets/subscription_list.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ class _SubscriptionListPageState extends State<SubscriptionListPage> with PerAcc
9090
_sortSubs(unpinned);
9191

9292
return Scaffold(
93-
appBar: ZulipAppBar(
94-
title: const Text("Channels"),
95-
isLoading: store.isLoading),
93+
appBar: ZulipAppBar(title: const Text("Channels")),
9694
body: SafeArea(
9795
// Don't pad the bottom here; we want the list content to do that.
9896
bottom: false,

0 commit comments

Comments
 (0)