-
Notifications
You must be signed in to change notification settings - Fork 310
Add a loading indicator for PerAccountStore #852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5380574
store: Add field for tracking loading status.
PIG208 a9d9ef8
ui: Extract ZulipAppBar for loading indicator.
PIG208 50d39ea
app_bar [nfc]: Move ZulipAppBar.isLoading to within widget
gnprice 1fb76ac
app_bar [nfc]: Explain why the lightbox skips ZulipAppBar
gnprice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'store.dart'; | ||
|
||
/// A custom [AppBar] with a loading indicator. | ||
/// | ||
/// This should be used for most of the pages with access to [PerAccountStore]. | ||
class ZulipAppBar extends AppBar { | ||
ZulipAppBar({ | ||
super.key, | ||
required super.title, | ||
super.backgroundColor, | ||
super.shape, | ||
super.actions, | ||
}) : super(bottom: _ZulipAppBarBottom(backgroundColor: backgroundColor)); | ||
} | ||
|
||
class _ZulipAppBarBottom extends StatelessWidget implements PreferredSizeWidget { | ||
const _ZulipAppBarBottom({this.backgroundColor}); | ||
|
||
final Color? backgroundColor; | ||
|
||
@override | ||
Size get preferredSize => const Size.fromHeight(4.0); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final store = PerAccountStoreWidget.of(context); | ||
if (!store.isLoading) return const SizedBox.shrink(); | ||
return LinearProgressIndicator(minHeight: 4.0, backgroundColor: backgroundColor); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:checks/checks.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:zulip/widgets/app_bar.dart'; | ||
import 'package:zulip/widgets/profile.dart'; | ||
|
||
import '../example_data.dart' as eg; | ||
import '../model/binding.dart'; | ||
import '../model/test_store.dart'; | ||
import 'test_app.dart'; | ||
|
||
void main() { | ||
TestZulipBinding.ensureInitialized(); | ||
|
||
testWidgets('show progress indicator when loading', (tester) async { | ||
addTearDown(testBinding.reset); | ||
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot()); | ||
|
||
final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); | ||
await store.addUser(eg.selfUser); | ||
|
||
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id, | ||
child: ProfilePage(userId: eg.selfUser.userId))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I intentionally only test this with one of the many call sites. This test does not prevent the bug where a new page is added without |
||
|
||
final finder = find.descendant( | ||
of: find.byType(ZulipAppBar), | ||
matching: find.byType(LinearProgressIndicator)); | ||
|
||
await tester.pumpAndSettle(); | ||
final rectBefore = tester.getRect(find.byType(ZulipAppBar)); | ||
check(finder.evaluate()).isEmpty(); | ||
store.isLoading = true; | ||
|
||
await tester.pump(); | ||
check(tester.getRect(find.byType(ZulipAppBar))).equals(rectBefore); | ||
check(finder.evaluate()).single; | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useful for a widget test added later.