Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
refactor: update to riverpod dev (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabeef authored Oct 29, 2021
1 parent 1d50c19 commit c9c35dc
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 54 deletions.
2 changes: 1 addition & 1 deletion ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>8.0</string>
<string>9.0</string>
</dict>
</plist>
8 changes: 4 additions & 4 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class App extends HookWidget {
class App extends HookConsumerWidget {
const App({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
final theme = useProvider(appThemeProvider);
final themeMode = useProvider(appThemeModeProvider);
Widget build(BuildContext context, WidgetRef ref) {
final theme = ref.watch(appThemeProvider);
final themeMode = ref.watch(appThemeModeProvider);
final appRouter = useMemoized(() => AppRouter());
return MaterialApp.router(
theme: theme.data,
Expand Down
7 changes: 3 additions & 4 deletions lib/ui/component/loading/container_with_loading.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'package:app/ui/component/loading/loading.dart';
import 'package:app/ui/loading_state_view_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class ContainerWithLoading extends HookWidget {
class ContainerWithLoading extends ConsumerWidget {
const ContainerWithLoading({
Key? key,
required this.child,
Expand All @@ -13,8 +12,8 @@ class ContainerWithLoading extends HookWidget {
final Widget child;

@override
Widget build(BuildContext context) {
final state = useProvider(loadingStateProvider);
Widget build(BuildContext context, WidgetRef ref) {
final state = ref.watch(loadingStateProvider);
return Stack(children: [
child,
state.isLoading ? const Loading() : const SizedBox(),
Expand Down
7 changes: 3 additions & 4 deletions lib/ui/component/loading/loading.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import 'package:app/ui/theme/app_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class Loading extends HookWidget {
class Loading extends ConsumerWidget {
const Loading({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
final theme = useProvider(appThemeProvider);
Widget build(BuildContext context, WidgetRef ref) {
final theme = ref.watch(appThemeProvider);
return Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(theme.appColors.accent),
Expand Down
7 changes: 3 additions & 4 deletions lib/ui/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import 'package:app/ui/route/app_route.gr.dart';
import 'package:app/ui/theme/app_theme.dart';
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class HomePage extends HookWidget {
class HomePage extends HookConsumerWidget {
const HomePage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
final theme = useProvider(appThemeProvider);
Widget build(BuildContext context, WidgetRef ref) {
final theme = ref.watch(appThemeProvider);
final l10n = useL10n();
return AutoTabsScaffold(
routes: const [
Expand Down
7 changes: 3 additions & 4 deletions lib/ui/news/article_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import 'package:app/ui/route/app_route.dart';
import 'package:app/ui/theme/app_theme.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class ArticleItem extends HookWidget {
class ArticleItem extends HookConsumerWidget {
const ArticleItem({
Key? key,
required this.article,
Expand All @@ -26,8 +25,8 @@ class ArticleItem extends HookWidget {
);

@override
Widget build(BuildContext context) {
final theme = useProvider(appThemeProvider);
Widget build(BuildContext context, WidgetRef ref) {
final theme = ref.watch(appThemeProvider);
final router = useRouter();
final l10n = useL10n();
return Card(
Expand Down
10 changes: 4 additions & 6 deletions lib/ui/news/connected_new_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ import 'package:app/ui/route/app_route.dart';
import 'package:app/ui/theme/app_theme.dart';
import 'package:app/ui/user_view_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class ConnectedNewsPage extends HookWidget {
class ConnectedNewsPage extends HookConsumerWidget {
const ConnectedNewsPage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
final theme = useProvider(appThemeProvider);
Widget build(BuildContext context, WidgetRef ref) {
final theme = ref.watch(appThemeProvider);
final l10n = useL10n();
final router = useRouter();

final user =
useProvider(userViewModelProvider.select((value) => value.user));
final user = ref.watch(userViewModelProvider.select((value) => value.user));

return Scaffold(
appBar: AppBar(
Expand Down
11 changes: 5 additions & 6 deletions lib/ui/news/news_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class NewsPage extends HookWidget {
class NewsPage extends HookConsumerWidget {
const NewsPage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
final l10n = useL10n();
final homeViewModel = context.read(newsViewModelProvider);
final news =
useProvider(newsViewModelProvider.select((value) => value.news));
final homeViewModel = ref.read(newsViewModelProvider);
final news = ref.watch(newsViewModelProvider.select((value) => value.news));

final snapshot = useFuture(
useMemoized(() {
return context
return ref
.read(loadingStateProvider)
.whileLoading(homeViewModel.fetchNews);
}, [news?.toString()]),
Expand Down
16 changes: 7 additions & 9 deletions lib/ui/signIn/sign_in_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@ import 'package:app/ui/loading_state_view_model.dart';
import 'package:app/ui/theme/app_theme.dart';
import 'package:app/ui/user_view_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:gap/gap.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class SignInPage extends HookWidget {
class SignInPage extends HookConsumerWidget {
const SignInPage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
final theme = useProvider(appThemeProvider);
Widget build(BuildContext context, WidgetRef ref) {
final theme = ref.watch(appThemeProvider);
final l10n = useL10n();
final user =
useProvider(userViewModelProvider.select((value) => value.user));
final userViewModel = context.read(userViewModelProvider);
final loading = context.read(loadingStateProvider);
final user = ref.watch(userViewModelProvider.select((value) => value.user));
final userViewModel = ref.read(userViewModelProvider);
final loading = ref.read(loadingStateProvider);

return Scaffold(
appBar: AppBar(
Expand Down Expand Up @@ -91,7 +89,7 @@ class SignInPage extends HookWidget {
),
onPressed: () {
loading.whileLoading(() async {
return context.read(userViewModelProvider).signIn();
return ref.read(userViewModelProvider).signIn();
});
},
icon: Assets.svgs.firebase.svg(width: 24),
Expand Down
7 changes: 3 additions & 4 deletions lib/ui/video/video_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import 'package:app/ui/hook/use_asset_vide_player_controller.dart';
import 'package:app/ui/hook/use_l10n.dart';
import 'package:app/ui/theme/app_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:video_player/video_player.dart';

class VideoPage extends HookWidget {
class VideoPage extends HookConsumerWidget {
const VideoPage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
final theme = useProvider(appThemeProvider);
Widget build(BuildContext context, WidgetRef ref) {
final theme = ref.watch(appThemeProvider);
final l10n = useL10n();
final videoController = useAssetVideoController(
asset: Assets.videos.bigbuckbunny,
Expand Down
10 changes: 5 additions & 5 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ packages:
name: flutter_hooks
url: "https://pub.dartlang.org"
source: hosted
version: "0.17.0"
version: "0.18.0"
flutter_lints:
dependency: "direct dev"
description:
Expand All @@ -388,7 +388,7 @@ packages:
name: flutter_riverpod
url: "https://pub.dartlang.org"
source: hosted
version: "0.14.0+3"
version: "1.0.0-dev.11"
flutter_svg:
dependency: "direct main"
description:
Expand Down Expand Up @@ -419,7 +419,7 @@ packages:
name: freezed_annotation
url: "https://pub.dartlang.org"
source: hosted
version: "0.14.3"
version: "0.15.0"
frontend_server_client:
dependency: transitive
description:
Expand Down Expand Up @@ -482,7 +482,7 @@ packages:
name: hooks_riverpod
url: "https://pub.dartlang.org"
source: hosted
version: "0.14.0+4"
version: "1.0.0-dev.11"
html:
dependency: transitive
description:
Expand Down Expand Up @@ -748,7 +748,7 @@ packages:
name: riverpod
url: "https://pub.dartlang.org"
source: hosted
version: "0.14.0+3"
version: "1.0.0-dev.10"
shelf:
dependency: transitive
description:
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ dependencies:
firebase_performance: ^0.7.1+2

# For Architecture
flutter_hooks: ^0.17.0
hooks_riverpod: ^0.14.0+4
flutter_hooks: ^0.18.0
hooks_riverpod: ^1.0.0-dev.10

# For Networking
dio: ^4.0.1
Expand All @@ -34,7 +34,7 @@ dependencies:

# For Model
json_serializable: ^5.0.2
freezed_annotation: ^0.14.0
freezed_annotation: ^0.15.0

# For Navigation
auto_route: ^3.0.4
Expand Down

0 comments on commit c9c35dc

Please sign in to comment.