Skip to content

Commit

Permalink
feat: use initialization page and providers
Browse files Browse the repository at this point in the history
  • Loading branch information
riscait committed Dec 17, 2024
1 parent bcb00b1 commit 76310c6
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 56 deletions.
2 changes: 1 addition & 1 deletion packages/flutter_app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ CHECKOUT OPTIONS:
SPEC CHECKSUMS:
AppAuth: d4f13a8fe0baf391b2108511793e4b479691fb73
cloud_firestore: 3fafe78d755b01fe1fd267a87bb52e80b7dacacc
connectivity_plus: ddd7f30999e1faaef5967c23d5b6d503d10434db
connectivity_plus: 4c41c08fc6d7c91f63bc7aec70ffe3730b04f563
device_info_plus: 97af1d7e84681a90d0693e63169a5d50e0839a0d
Firebase: cf1b19f21410b029b6786a54e9764a0cacad3c99
firebase_analytics: ac872e186755025fbfbb477afb4761ae392a8a2a
Expand Down
3 changes: 3 additions & 0 deletions packages/flutter_app/lib/initialization_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

import 'features/user_device/user_device_provider.dart';
import 'package_adaptor/configurator_provider.dart';
import 'package_adaptor/package_info_provider.dart';
import 'util/providers/providers.dart';

Expand All @@ -21,4 +22,6 @@ Future<void> initialization(Ref ref) async {
ref.watch(packageInfoInitializingProvider.future),
ref.watch(userDeviceInitializingProvider.future),
]);
final configurator = ref.watch(configuratorProvider);
await configurator.fetchAndActivate();
}
2 changes: 1 addition & 1 deletion packages/flutter_app/lib/initialization_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/flutter_app/lib/main_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:themes/themes.dart';

import 'features/theme_selector/theme_selector.dart';
import 'gen/strings.g.dart';
import 'pages/initialization_page.dart';
import 'router/router.dart';
import 'util/providers/scaffold_messenger_key_provider.dart';

Expand All @@ -29,6 +30,9 @@ class MainApp extends ConsumerWidget {
],
supportedLocales: AppLocaleUtils.supportedLocales,
scaffoldMessengerKey: ref.watch(scaffoldMessengerKeyProvider),
builder: (context, child) {
return InitializationPage(onInitialized: (_) => child!);
},
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:altfire_configurator/altfire_configurator.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'configurator_provider.g.dart';

/// Provides a [Configurator] to retrieve parameters using "RemoteConfig".
///
/// It is recommended to call [Configurator.fetchAndActivate] before using
/// the parameters (e.g., at app startup) in order to fetch and activate them
/// for use in the app.
@Riverpod(keepAlive: true)
Configurator configurator(Ref ref) {
return Configurator();
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ part 'package_info_provider.g.dart';

/// Providers that need to initialize asynchronously only once at startup.
@Riverpod(keepAlive: true)
Future<PackageInfo> packageInfoInitializing(Ref ref) async =>
PackageInfo.fromPlatform();
Future<PackageInfo> packageInfoInitializing(Ref ref) async {
return PackageInfo.fromPlatform();
}

/// Provide metadata for the application.
///
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/flutter_app/lib/pages/initialization_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';

import '../initialization_provider.dart';

/// The first page.
class InitializationPage extends ConsumerWidget {
const InitializationPage({super.key});
const InitializationPage({super.key, required this.onInitialized});

final WidgetBuilder onInitialized;

@override
Widget build(BuildContext context, WidgetRef ref) {
return switch (ref.watch(initializationProvider)) {
AsyncData(isLoading: false) => throw AssertionError(),
AsyncData(isLoading: false) => onInitialized(context),
AsyncError(:final error) => _ErrorPage(
error,
onRetry: () => ref.invalidate(initializationProvider),
Expand Down
17 changes: 0 additions & 17 deletions packages/flutter_app/lib/router/app_routes.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

import '../pages/initialization_page.dart';
import '../pages/main/main_page.dart';
import 'branches/branches.dart';

part 'app_routes.g.dart';

@TypedGoRoute<InitializationRoute>(
name: InitializationRoute.name,
path: InitializationRoute.path,
)
class InitializationRoute extends GoRouteData {
const InitializationRoute();

static const String name = '/init';
static const String path = '/init';

@override
Page<void> buildPage(BuildContext context, GoRouterState state) {
return const NoTransitionPage(child: InitializationPage());
}
}

@TypedStatefulShellRoute<MainShellRouteData>(
branches: [
TypedStatefulShellBranch<HomeShellBranchData>(
Expand Down
25 changes: 0 additions & 25 deletions packages/flutter_app/lib/router/app_routes.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions packages/flutter_app/lib/router/router_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../initialization_provider.dart';
import '../package_adaptor/tracker_provider.dart';
import '../pages/not_found_page/error_page.dart';
import '../util/logger.dart';
Expand All @@ -16,16 +15,12 @@ part 'router_provider.g.dart';

@Riverpod(keepAlive: true)
Raw<GoRouter> router(Ref ref) {
final initialization = ref.watch(initializationProvider);
final tracker = ref.watch(trackerProvider);

late final GoRouter router;
router = GoRouter(
routes: $appRoutes,
redirect: (context, state) {
if (initialization.isLoading || initialization.hasError) {
return InitializationRoute.path;
}
if (state.matchedLocation == '/') {
return HomeRouteData.path;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_app/lib/router/router_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/flutter_app/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ CHECKOUT OPTIONS:
SPEC CHECKSUMS:
AppAuth: d4f13a8fe0baf391b2108511793e4b479691fb73
cloud_firestore: 9a20a45d1f46dda8d3486bc68866e8dca2d68548
connectivity_plus: ddd7f30999e1faaef5967c23d5b6d503d10434db
connectivity_plus: 4c41c08fc6d7c91f63bc7aec70ffe3730b04f563
device_info_plus: ce1b7762849d3ec103d0e0517299f2db7ad60720
file_selector_macos: 54fdab7caa3ac3fc43c9fac4d7d8d231277f8cf2
Firebase: cf1b19f21410b029b6786a54e9764a0cacad3c99
Expand Down
1 change: 1 addition & 0 deletions packages/themes/lib/src/altive_theme/light_theme_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ThemeData get lightThemeData {
chipTheme: appChipThemeData(colorScheme: colorScheme),
inputDecorationTheme: appInputDecorationTheme(colorScheme: colorScheme),
navigationBarTheme: navigationBarThemeData(colorScheme: colorScheme),
iconTheme: const IconThemeData(applyTextScaling: true),
// Extensions
extensions: [
const ThemeDescription(
Expand Down

0 comments on commit 76310c6

Please sign in to comment.