Skip to content

Commit

Permalink
feat: Remove declarative routing to support deplinking (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirland authored Feb 18, 2023
1 parent 93ab933 commit 0d7455c
Show file tree
Hide file tree
Showing 20 changed files with 280 additions and 416 deletions.
1 change: 1 addition & 0 deletions lib/core/common/extension/stream_future_extensions.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: unused-files
import 'package:fluttips/core/common/logger.dart';
import 'package:fluttips/core/common/result.dart';
import 'package:rxdart/rxdart.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/core/common/store/secure_storage_cached_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SharedPreferencesSourceOfTruth
@override
@protected
Future<void> write(String key, String? value) async {
await super.write(key, value);
await _storage.write(key: key, value: value);
await super.write(key, value);
}
}
7 changes: 6 additions & 1 deletion lib/core/di/di_utils_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:fluttips/core/source/database.dart';
import 'package:fluttips/core/source/providers/shared_preferences_provider.dart';
import 'package:fluttips/ui/app_router.dart';
import 'package:fluttips/ui/router/app_status_router_guard.dart';
import 'package:get_it/get_it.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:fluttips/core/common/config.dart';
Expand All @@ -25,7 +26,11 @@ class UtilsDiModule {

extension _GetItUtilsDiModuleExtensions on GetIt {
void _setupModule() {
registerSingleton(AppRouter());
registerSingleton(NotOnboardedGuard(get()));
registerSingleton(OnboardedGuard(get()));
registerSingleton(
AppRouter(notOnboardedGuard: get(), onboardedGuard: get()),
);
}

void _setupProviders() {
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ class MyApp extends StatelessWidget {
designSize: const Size(812, 360),
minTextAdapt: false,
splitScreenMode: false,
builder: (_, __) => const MainScreen(),
builder: (_, __) => MainScreen(),
);
}
10 changes: 3 additions & 7 deletions lib/ui/about/about_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:fluttips/core/di/di_provider.dart';
import 'package:fluttips/ui/app_router.dart';
import 'package:fluttips/core/common/config.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:fluttips/gen/assets.gen.dart';

part 'about_cubit.freezed.dart';

Expand All @@ -21,13 +20,10 @@ class AboutCubit extends Cubit<AboutBaseState> {

AboutCubit(this._errorHandler) : super(const AboutBaseState.state());

void onTermsAndConditionsButtonPressed() => _router.navigate(
WebViewRoute(path: Assets.policyAndTerms.termsAndConditions),
);
void onTermsAndConditionsButtonPressed() =>
_router.navigate(TermsAndConditionsRoute());

void onPrivacyPolicyButtonPressed() => _router.navigate(
WebViewRoute(path: Assets.policyAndTerms.privacyPolicy),
);
void onPrivacyPolicyButtonPressed() => _router.navigate(PrivacyPolicyRoute());

Future<void> sendEmail() async {
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
Expand Down
48 changes: 29 additions & 19 deletions lib/ui/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import 'package:fluttips/ui/about/about_screen.dart';
import 'package:fluttips/ui/catalog/catalog_screen.dart';
import 'package:fluttips/ui/home/home_screen.dart';
import 'package:fluttips/ui/onboarding/onboarding_screen.dart';
import 'package:fluttips/ui/privacy_policy/privacy_policy_screen.dart';
import 'package:fluttips/ui/privacy_policy/terms_and_condition_screen.dart';
import 'package:fluttips/ui/router/app_status_router_guard.dart';
import 'package:fluttips/ui/section/section_router.dart';
import 'package:fluttips/ui/videos_details_screen/videos_details_screen.dart';
import 'package:fluttips/ui/webView/webview_screen.dart';
import 'package:fluttips/ui/favourites_tip_details/favourites_tip_details_screen.dart';
import 'package:fluttips/ui/favourites_tip_simple_list/favourites_tip_simple_list_screen.dart';
import 'package:fluttips/ui/image_tip_details/image_tip_details_screen.dart';
Expand All @@ -25,8 +27,12 @@ part 'app_router.gr.dart';
AutoRoute(
name: 'UncompletedOnboardingRouter',
page: SectionRouter,
initial: true,
path: '/onboarding',
guards: [NotOnboardedGuard],
children: [
AutoRoute(
path: '',
initial: true,
name: 'OnboardingRoute',
page: OnboardingScreen,
Expand All @@ -36,54 +42,58 @@ part 'app_router.gr.dart';
AutoRoute(
name: 'UserOnboardedRouter',
page: SectionRouter,
path: '',
path: '/',
guards: [OnboardedGuard],
children: [
AutoRoute(
page: HomeScreen,
initial: true,
path: 'home',
children: [
AutoRoute(
path: AppRouter.tipsPath,
path: 'images',
name: 'HomeTipsScreenRoute',
page: ImageTipDetailsScreen,
),
AutoRoute(
path: AppRouter.videosPath,
path: 'videos',
name: 'HomeVideosScreenRoute',
page: VideosDetailsScreen,
),
AutoRoute(
path: AppRouter.favouritesTipsPath,
path: 'favourites',
name: 'HomeFavouritesTipsScreenRoute',
page: FavouritesTipSimpleListScreen,
),
AutoRoute(
path: AppRouter.aboutPath,
path: 'about',
name: 'HomeAboutScreenRoute',
page: AboutScreen,
),
],
),
AutoRoute(
path: AppRouter.webViewPath,
name: 'WebViewRoute',
page: WebViewScreen,
),
AutoRoute(
path: AppRouter.listFavouritesTipsPath,
path: 'favourite_images',
name: 'FavoritesTipDetailsScreen',
page: FavouritesTipDetailsScreen,
),
],
),
AutoRoute(
path: '/privacy_policy',
name: 'PrivacyPolicyRoute',
page: PrivacyPolicyScreen,
),
AutoRoute(
path: '/terms_and_conditions',
name: 'TermsAndConditionsRoute',
page: TermsAndConditionsScreen,
),
],
)
class AppRouter extends _$AppRouter {
static const signInPath = 'signin';
static const tipsPath = 'tips';
static const videosPath = 'videos';
static const favouritesTipsPath = 'favourite';
static const listFavouritesTipsPath = 'list_favourite';
static const aboutPath = 'about';
static const webViewPath = 'webView';
AppRouter({
required super.notOnboardedGuard,
required super.onboardedGuard,
});
}
Loading

0 comments on commit 0d7455c

Please sign in to comment.