From 6adaeee02da46e2d89e90b5bd4c2225a45904123 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Mon, 23 Jan 2023 21:25:24 +0300 Subject: [PATCH] added env --- .vscode/launch.json | 20 ++++-------------- lib/application.dart | 10 +++++---- lib/data/models/ev_source_type.dart | 2 +- lib/environment.dart | 21 +++++++++++++++++++ lib/launch_app.dart | 9 ++++++++ lib/main.dart | 9 -------- lib/main_dev.dart | 5 +++++ lib/main_mock.dart | 9 -------- lib/main_prod.dart | 5 +++++ lib/screens/metering/flow_metering.dart | 2 +- .../widget_list_tile_report_issue.dart | 4 +++- .../widget_list_tile_source_code.dart | 4 +++- 12 files changed, 58 insertions(+), 42 deletions(-) create mode 100644 lib/environment.dart create mode 100644 lib/launch_app.dart delete mode 100644 lib/main.dart create mode 100644 lib/main_dev.dart delete mode 100644 lib/main_mock.dart create mode 100644 lib/main_prod.dart diff --git a/.vscode/launch.json b/.vscode/launch.json index 2e7e637..fb960be 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -14,7 +14,7 @@ "--dart-define", "cameraPreviewAspectRatio=2/3", ], - "program": "${workspaceFolder}/lib/main.dart", + "program": "${workspaceFolder}/lib/main_dev.dart", }, { "name": "dev (ios)", @@ -26,19 +26,7 @@ "--dart-define", "cameraPreviewAspectRatio=3/4", ], - "program": "${workspaceFolder}/lib/main.dart", - }, - { - "name": "dev (mock)", - "request": "launch", - "type": "dart", - "args": [ - "--flavor", - "dev", - "--dart-define", - "cameraPreviewAspectRatio=3/4", - ], - "program": "${workspaceFolder}/lib/main_mock.dart", + "program": "${workspaceFolder}/lib/main_dev.dart", }, { "name": "prod (android)", @@ -50,7 +38,7 @@ "--dart-define", "cameraPreviewAspectRatio=2/3", ], - "program": "${workspaceFolder}/lib/main.dart", + "program": "${workspaceFolder}/lib/main_prod.dart", }, { "name": "prod (ios)", @@ -62,7 +50,7 @@ "--dart-define", "cameraPreviewAspectRatio=3/4", ], - "program": "${workspaceFolder}/lib/main.dart", + "program": "${workspaceFolder}/lib/main_prod.dart", }, ], } \ No newline at end of file diff --git a/lib/application.dart b/lib/application.dart index 3343240..01b8f40 100644 --- a/lib/application.dart +++ b/lib/application.dart @@ -2,12 +2,13 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:lightmeter/data/haptics_service.dart'; +import 'package:lightmeter/data/models/ev_source_type.dart'; import 'package:provider/provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import 'data/models/ev_source_type.dart'; import 'data/permissions_service.dart'; import 'data/shared_prefs_service.dart'; +import 'environment.dart'; import 'generated/l10n.dart'; import 'res/theme.dart'; import 'screens/metering/flow_metering.dart'; @@ -17,9 +18,9 @@ import 'utils/stop_type_provider.dart'; final RouteObserver routeObserver = RouteObserver(); class Application extends StatelessWidget { - final EvSourceType evSource; + final Environment env; - const Application(this.evSource, {super.key}); + const Application(this.env, {super.key}); @override Widget build(BuildContext context) { @@ -29,10 +30,11 @@ class Application extends StatelessWidget { if (snapshot.data != null) { return MultiProvider( providers: [ + Provider.value(value: env), + Provider.value(value: EvSourceType.camera), Provider(create: (_) => UserPreferencesService(snapshot.data!)), Provider(create: (_) => const HapticsService()), Provider(create: (_) => PermissionsService()), - Provider.value(value: evSource), ], child: StopTypeProvider( child: ThemeProvider( diff --git a/lib/data/models/ev_source_type.dart b/lib/data/models/ev_source_type.dart index 458f707..bc67be9 100644 --- a/lib/data/models/ev_source_type.dart +++ b/lib/data/models/ev_source_type.dart @@ -1 +1 @@ -enum EvSourceType { camera, mock } +enum EvSourceType { camera, sensor } diff --git a/lib/environment.dart b/lib/environment.dart new file mode 100644 index 0000000..14b6ad8 --- /dev/null +++ b/lib/environment.dart @@ -0,0 +1,21 @@ +class Environment { + final String sourceCodeUrl; + final String issuesReportUrl; + final String contactEmail; + + const Environment({ + required this.sourceCodeUrl, + required this.issuesReportUrl, + required this.contactEmail, + }); + + const Environment.dev() + : sourceCodeUrl = 'https://github.com/vodemn/m3_lightmeter', + issuesReportUrl = 'https://github.com/vodemn/m3_lightmeter/issues', + contactEmail = ''; + + const Environment.prod() + : sourceCodeUrl = 'https://github.com/vodemn/m3_lightmeter', + issuesReportUrl = 'https://github.com/vodemn/m3_lightmeter/issues', + contactEmail = ''; +} diff --git a/lib/launch_app.dart b/lib/launch_app.dart new file mode 100644 index 0000000..f26dcca --- /dev/null +++ b/lib/launch_app.dart @@ -0,0 +1,9 @@ +import 'package:flutter/material.dart'; + +import 'application.dart'; +import 'environment.dart'; + +void launchApp(Environment env) { + WidgetsFlutterBinding.ensureInitialized(); + runApp(Application(env)); +} diff --git a/lib/main.dart b/lib/main.dart deleted file mode 100644 index 72c51db..0000000 --- a/lib/main.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:lightmeter/data/models/ev_source_type.dart'; - -import 'application.dart'; - -void main() { - WidgetsFlutterBinding.ensureInitialized(); - runApp(const Application(EvSourceType.camera)); -} diff --git a/lib/main_dev.dart b/lib/main_dev.dart new file mode 100644 index 0000000..fb3d8e3 --- /dev/null +++ b/lib/main_dev.dart @@ -0,0 +1,5 @@ +import 'package:lightmeter/environment.dart'; + +import 'launch_app.dart'; + +void main() => launchApp(const Environment.dev()); diff --git a/lib/main_mock.dart b/lib/main_mock.dart deleted file mode 100644 index d44956e..0000000 --- a/lib/main_mock.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:lightmeter/data/models/ev_source_type.dart'; - -import 'application.dart'; - -void main() { - WidgetsFlutterBinding.ensureInitialized(); - runApp(const Application(EvSourceType.mock)); -} \ No newline at end of file diff --git a/lib/main_prod.dart b/lib/main_prod.dart new file mode 100644 index 0000000..a1839f6 --- /dev/null +++ b/lib/main_prod.dart @@ -0,0 +1,5 @@ +import 'package:lightmeter/environment.dart'; + +import 'launch_app.dart'; + +void main() => launchApp(const Environment.prod()); diff --git a/lib/screens/metering/flow_metering.dart b/lib/screens/metering/flow_metering.dart index e81f7c5..f56acf5 100644 --- a/lib/screens/metering/flow_metering.dart +++ b/lib/screens/metering/flow_metering.dart @@ -40,7 +40,7 @@ class MeteringFlow extends StatelessWidget { context.read(), ), ), - if (context.read() == EvSourceType.mock) + if (context.read() == EvSourceType.sensor) BlocProvider( lazy: false, create: (context) => RandomEvBloc(context.read()), diff --git a/lib/screens/settings/components/report_issue/widget_list_tile_report_issue.dart b/lib/screens/settings/components/report_issue/widget_list_tile_report_issue.dart index 6d3215c..f6e3355 100644 --- a/lib/screens/settings/components/report_issue/widget_list_tile_report_issue.dart +++ b/lib/screens/settings/components/report_issue/widget_list_tile_report_issue.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; +import 'package:lightmeter/environment.dart'; import 'package:lightmeter/generated/l10n.dart'; +import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher.dart'; class ReportIssueListTile extends StatelessWidget { @@ -11,7 +13,7 @@ class ReportIssueListTile extends StatelessWidget { leading: const Icon(Icons.bug_report), title: Text(S.of(context).reportIssue), onTap: () { - launchUrl(Uri.parse("https://github.com/vodemn/m3_lightmeter/issues")); + launchUrl(Uri.parse(context.read().issuesReportUrl)); }, ); } diff --git a/lib/screens/settings/components/source_code/widget_list_tile_source_code.dart b/lib/screens/settings/components/source_code/widget_list_tile_source_code.dart index 75c59dc..c2184ba 100644 --- a/lib/screens/settings/components/source_code/widget_list_tile_source_code.dart +++ b/lib/screens/settings/components/source_code/widget_list_tile_source_code.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; +import 'package:lightmeter/environment.dart'; import 'package:lightmeter/generated/l10n.dart'; +import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher.dart'; class SourceCodeListTile extends StatelessWidget { @@ -11,7 +13,7 @@ class SourceCodeListTile extends StatelessWidget { leading: const Icon(Icons.code), title: Text(S.of(context).sourceCode), onTap: () { - launchUrl(Uri.parse("https://github.com/vodemn/m3_lightmeter")); + launchUrl(Uri.parse(context.read().sourceCodeUrl)); }, ); }