diff --git a/lib/application.dart b/lib/application.dart index 94f4750..24efde5 100644 --- a/lib/application.dart +++ b/lib/application.dart @@ -3,18 +3,17 @@ import 'package:flutter/services.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:lightmeter/data/models/supported_locale.dart'; import 'package:lightmeter/generated/l10n.dart'; +import 'package:lightmeter/navigation/modal_route_args_parser.dart'; +import 'package:lightmeter/navigation/routes.dart'; import 'package:lightmeter/platform_config.dart'; import 'package:lightmeter/providers/user_preferences_provider.dart'; import 'package:lightmeter/screens/film_edit/flow_film_edit.dart'; -import 'package:lightmeter/screens/film_edit/screen_film_edit.dart'; import 'package:lightmeter/screens/films/screen_films.dart'; import 'package:lightmeter/screens/lightmeter_pro/screen_lightmeter_pro.dart'; import 'package:lightmeter/screens/metering/flow_metering.dart'; import 'package:lightmeter/screens/settings/flow_settings.dart'; import 'package:lightmeter/screens/shared/release_notes_dialog/flow_dialog_release_notes.dart'; import 'package:lightmeter/screens/timer/flow_timer.dart'; -import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; -import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; class Application extends StatelessWidget { const Application({super.key}); @@ -46,14 +45,14 @@ class Application extends StatelessWidget { data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0), child: child!, ), - initialRoute: "metering", + initialRoute: NavigationRoutes.meteringScreen.name, routes: { - "metering": (_) => const ReleaseNotesFlow(child: MeteringFlow()), - "settings": (_) => const SettingsFlow(), - "films": (_) => const FilmsScreen(), - "filmEdit": (context) => FilmEditFlow(args: ModalRoute.of(context)!.settings.arguments! as FilmEditArgs), - "lightmeterPro": (_) => LightmeterProScreen(), - "timer": (context) => TimerFlow(args: ModalRoute.of(context)!.settings.arguments! as TimerFlowArgs), + NavigationRoutes.meteringScreen.name: (_) => const ReleaseNotesFlow(child: MeteringFlow()), + NavigationRoutes.settingsScreen.name: (_) => const SettingsFlow(), + NavigationRoutes.filmsListScreen.name: (_) => const FilmsScreen(), + NavigationRoutes.filmEditScreen.name: (context) => FilmEditFlow(args: context.routeArgs()), + NavigationRoutes.proFeaturesScreen.name: (_) => LightmeterProScreen(), + NavigationRoutes.timerScreen.name: (context) => TimerFlow(args: context.routeArgs()), }, ), ); diff --git a/lib/navigation/modal_route_args_parser.dart b/lib/navigation/modal_route_args_parser.dart new file mode 100644 index 0000000..4064a9d --- /dev/null +++ b/lib/navigation/modal_route_args_parser.dart @@ -0,0 +1,7 @@ +import 'package:flutter/widgets.dart'; + +extension ModalRouteArgsParser on BuildContext { + T routeArgs() { + return ModalRoute.of(this)!.settings.arguments! as T; + } +} diff --git a/lib/navigation/routes.dart b/lib/navigation/routes.dart new file mode 100644 index 0000000..7f8ac24 --- /dev/null +++ b/lib/navigation/routes.dart @@ -0,0 +1,8 @@ +enum NavigationRoutes { + meteringScreen, + settingsScreen, + filmsListScreen, + filmEditScreen, + proFeaturesScreen, + timerScreen, +} diff --git a/lib/screens/films/screen_films.dart b/lib/screens/films/screen_films.dart index b8547dc..62f9a24 100644 --- a/lib/screens/films/screen_films.dart +++ b/lib/screens/films/screen_films.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/generated/l10n.dart'; +import 'package:lightmeter/navigation/routes.dart'; import 'package:lightmeter/providers/films_provider.dart'; import 'package:lightmeter/res/dimens.dart'; import 'package:lightmeter/screens/film_edit/flow_film_edit.dart'; @@ -71,14 +72,14 @@ class _FilmsScreenState extends State with SingleTickerProviderStat void _addFilm() { Navigator.of(context).pushNamed( - 'filmEdit', + NavigationRoutes.filmEditScreen.name, arguments: const FilmEditArgs(film: FilmExponential(name: '', iso: 100, exponent: 1.3)), ); } void _editFilm(FilmExponential film) { Navigator.of(context).pushNamed( - 'filmEdit', + NavigationRoutes.filmEditScreen.name, arguments: FilmEditArgs(film: film), ); } diff --git a/lib/screens/metering/components/shared/readings_container/components/lightmeter_pro/widget_lightmeter_pro.dart b/lib/screens/metering/components/shared/readings_container/components/lightmeter_pro/widget_lightmeter_pro.dart index 245bab3..f1b77ff 100644 --- a/lib/screens/metering/components/shared/readings_container/components/lightmeter_pro/widget_lightmeter_pro.dart +++ b/lib/screens/metering/components/shared/readings_container/components/lightmeter_pro/widget_lightmeter_pro.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/generated/l10n.dart'; +import 'package:lightmeter/navigation/routes.dart'; import 'package:lightmeter/screens/metering/components/shared/readings_container/components/shared/reading_value_container/widget_container_reading_value.dart'; class LightmeterProAnimatedDialog extends StatelessWidget { @@ -9,7 +10,7 @@ class LightmeterProAnimatedDialog extends StatelessWidget { Widget build(BuildContext context) { return GestureDetector( onTap: () { - Navigator.of(context).pushNamed("lightmeterPro"); + Navigator.of(context).pushNamed(NavigationRoutes.proFeaturesScreen.name); }, child: ReadingValueContainer( color: Theme.of(context).colorScheme.secondary, diff --git a/lib/screens/metering/screen_metering.dart b/lib/screens/metering/screen_metering.dart index 12f910d..7771bf2 100644 --- a/lib/screens/metering/screen_metering.dart +++ b/lib/screens/metering/screen_metering.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:lightmeter/data/models/ev_source_type.dart'; import 'package:lightmeter/data/models/exposure_pair.dart'; +import 'package:lightmeter/navigation/routes.dart'; import 'package:lightmeter/providers/equipment_profile_provider.dart'; import 'package:lightmeter/providers/services_provider.dart'; import 'package:lightmeter/providers/user_preferences_provider.dart'; @@ -36,7 +37,7 @@ class MeteringScreen extends StatelessWidget { onNdChanged: (value) => context.read().add(NdChangedEvent(value)), onExposurePairTap: (value) => pushNamed( context, - 'timer', + NavigationRoutes.timerScreen.name, arguments: TimerFlowArgs( exposurePair: value, isoValue: state.iso, @@ -55,7 +56,10 @@ class MeteringScreen extends StatelessWidget { ? UserPreferencesProvider.of(context).toggleEvSourceType : null, onMeasure: () => context.read().add(const MeasureEvent()), - onSettings: () => pushNamed(context, 'settings'), + onSettings: () => pushNamed( + context, + NavigationRoutes.settingsScreen.name, + ), ), ), ], diff --git a/lib/screens/settings/components/lightmeter_pro/components/buy_pro/widget_list_tile_buy_pro.dart b/lib/screens/settings/components/lightmeter_pro/components/buy_pro/widget_list_tile_buy_pro.dart index 3ab7ae5..93c39e6 100644 --- a/lib/screens/settings/components/lightmeter_pro/components/buy_pro/widget_list_tile_buy_pro.dart +++ b/lib/screens/settings/components/lightmeter_pro/components/buy_pro/widget_list_tile_buy_pro.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/generated/l10n.dart'; +import 'package:lightmeter/navigation/routes.dart'; import 'package:lightmeter/res/dimens.dart'; import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart'; @@ -15,7 +16,7 @@ class BuyProListTile extends StatelessWidget { title: Text(S.of(context).getPro), onTap: !isPending ? () { - Navigator.of(context).pushNamed("lightmeterPro"); + Navigator.of(context).pushNamed(NavigationRoutes.proFeaturesScreen.name); } : null, trailing: isPending diff --git a/lib/screens/settings/components/metering/components/films/widget_list_tile_films.dart b/lib/screens/settings/components/metering/components/films/widget_list_tile_films.dart index a2a0ab9..0cc1733 100644 --- a/lib/screens/settings/components/metering/components/films/widget_list_tile_films.dart +++ b/lib/screens/settings/components/metering/components/films/widget_list_tile_films.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/generated/l10n.dart'; +import 'package:lightmeter/navigation/routes.dart'; import 'package:lightmeter/screens/settings/components/shared/iap_list_tile/widget_list_tile_iap.dart'; class FilmsListTile extends StatelessWidget { @@ -10,7 +11,7 @@ class FilmsListTile extends StatelessWidget { return IAPListTile( leading: const Icon(Icons.camera_roll_outlined), title: Text(S.of(context).films), - onTap: () => Navigator.of(context).pushNamed('films'), + onTap: () => Navigator.of(context).pushNamed(NavigationRoutes.filmsListScreen.name), ); } }