Skip to content

Commit

Permalink
[Riverpod2x][PicoGram] Create HomeView
Browse files Browse the repository at this point in the history
  • Loading branch information
Arti-Sadra committed Feb 2, 2023
1 parent aa27d1a commit f80c688
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'home_view.dart';
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(),
),
);
}
}

0 comments on commit f80c688

Please sign in to comment.