mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-21 15:00:40 +00:00
replaced explicit routes names with enum values
This commit is contained in:
parent
0243598553
commit
9884a6147f
8 changed files with 39 additions and 17 deletions
|
@ -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<FilmEditArgs>()),
|
||||
NavigationRoutes.proFeaturesScreen.name: (_) => LightmeterProScreen(),
|
||||
NavigationRoutes.timerScreen.name: (context) => TimerFlow(args: context.routeArgs<TimerFlowArgs>()),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
|
7
lib/navigation/modal_route_args_parser.dart
Normal file
7
lib/navigation/modal_route_args_parser.dart
Normal file
|
@ -0,0 +1,7 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
|
||||
extension ModalRouteArgsParser on BuildContext {
|
||||
T routeArgs<T>() {
|
||||
return ModalRoute.of(this)!.settings.arguments! as T;
|
||||
}
|
||||
}
|
8
lib/navigation/routes.dart
Normal file
8
lib/navigation/routes.dart
Normal file
|
@ -0,0 +1,8 @@
|
|||
enum NavigationRoutes {
|
||||
meteringScreen,
|
||||
settingsScreen,
|
||||
filmsListScreen,
|
||||
filmEditScreen,
|
||||
proFeaturesScreen,
|
||||
timerScreen,
|
||||
}
|
|
@ -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<FilmsScreen> 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),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<MeteringBloc>().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<MeteringBloc>().add(const MeasureEvent()),
|
||||
onSettings: () => pushNamed(context, 'settings'),
|
||||
onSettings: () => pushNamed(
|
||||
context,
|
||||
NavigationRoutes.settingsScreen.name,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue