-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Riverpod2x][PicoGram] Create HomeView
- Loading branch information
1 parent
aa27d1a
commit f80c688
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
Riverpod/Vandad/Riverpod2.x/picogram/lib/views/tabs/home/home.dart
This file contains 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 @@ | ||
export 'home_view.dart'; |
41 changes: 41 additions & 0 deletions
41
Riverpod/Vandad/Riverpod2.x/picogram/lib/views/tabs/home/home_view.dart
This file contains 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,41 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
|
||
import '../../../lib.dart' | ||
show | ||
EmptyContentsWithTextAnimationView, | ||
ErrorAnimationView, | ||
LoadingAnimationView, | ||
PostGridView, | ||
Strings, | ||
allPostsProvider; | ||
|
||
class HomeView extends ConsumerWidget { | ||
const HomeView({ | ||
Key? key, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final posts = ref.watch(allPostsProvider); | ||
|
||
return RefreshIndicator( | ||
onRefresh: () { | ||
ref.refresh(allPostsProvider); | ||
return Future.delayed(const Duration(seconds: 1)); | ||
}, | ||
child: posts.when( | ||
data: (posts) { | ||
if (posts.isEmpty) { | ||
return const EmptyContentsWithTextAnimationView( | ||
text: Strings.noPostsAvailable, | ||
); | ||
} | ||
return PostGridView(posts: posts); | ||
}, | ||
loading: () => const LoadingAnimationView(), | ||
error: (error, stack) => const ErrorAnimationView(), | ||
), | ||
); | ||
} | ||
} |