added env

This commit is contained in:
Vadim 2023-01-23 21:25:24 +03:00
parent fbc3804768
commit 6adaeee02d
12 changed files with 58 additions and 42 deletions

20
.vscode/launch.json vendored
View file

@ -14,7 +14,7 @@
"--dart-define", "--dart-define",
"cameraPreviewAspectRatio=2/3", "cameraPreviewAspectRatio=2/3",
], ],
"program": "${workspaceFolder}/lib/main.dart", "program": "${workspaceFolder}/lib/main_dev.dart",
}, },
{ {
"name": "dev (ios)", "name": "dev (ios)",
@ -26,19 +26,7 @@
"--dart-define", "--dart-define",
"cameraPreviewAspectRatio=3/4", "cameraPreviewAspectRatio=3/4",
], ],
"program": "${workspaceFolder}/lib/main.dart", "program": "${workspaceFolder}/lib/main_dev.dart",
},
{
"name": "dev (mock)",
"request": "launch",
"type": "dart",
"args": [
"--flavor",
"dev",
"--dart-define",
"cameraPreviewAspectRatio=3/4",
],
"program": "${workspaceFolder}/lib/main_mock.dart",
}, },
{ {
"name": "prod (android)", "name": "prod (android)",
@ -50,7 +38,7 @@
"--dart-define", "--dart-define",
"cameraPreviewAspectRatio=2/3", "cameraPreviewAspectRatio=2/3",
], ],
"program": "${workspaceFolder}/lib/main.dart", "program": "${workspaceFolder}/lib/main_prod.dart",
}, },
{ {
"name": "prod (ios)", "name": "prod (ios)",
@ -62,7 +50,7 @@
"--dart-define", "--dart-define",
"cameraPreviewAspectRatio=3/4", "cameraPreviewAspectRatio=3/4",
], ],
"program": "${workspaceFolder}/lib/main.dart", "program": "${workspaceFolder}/lib/main_prod.dart",
}, },
], ],
} }

View file

@ -2,12 +2,13 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:lightmeter/data/haptics_service.dart'; import 'package:lightmeter/data/haptics_service.dart';
import 'package:lightmeter/data/models/ev_source_type.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'data/models/ev_source_type.dart';
import 'data/permissions_service.dart'; import 'data/permissions_service.dart';
import 'data/shared_prefs_service.dart'; import 'data/shared_prefs_service.dart';
import 'environment.dart';
import 'generated/l10n.dart'; import 'generated/l10n.dart';
import 'res/theme.dart'; import 'res/theme.dart';
import 'screens/metering/flow_metering.dart'; import 'screens/metering/flow_metering.dart';
@ -17,9 +18,9 @@ import 'utils/stop_type_provider.dart';
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>(); final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
class Application extends StatelessWidget { class Application extends StatelessWidget {
final EvSourceType evSource; final Environment env;
const Application(this.evSource, {super.key}); const Application(this.env, {super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -29,10 +30,11 @@ class Application extends StatelessWidget {
if (snapshot.data != null) { if (snapshot.data != null) {
return MultiProvider( return MultiProvider(
providers: [ providers: [
Provider.value(value: env),
Provider.value(value: EvSourceType.camera),
Provider(create: (_) => UserPreferencesService(snapshot.data!)), Provider(create: (_) => UserPreferencesService(snapshot.data!)),
Provider(create: (_) => const HapticsService()), Provider(create: (_) => const HapticsService()),
Provider(create: (_) => PermissionsService()), Provider(create: (_) => PermissionsService()),
Provider.value(value: evSource),
], ],
child: StopTypeProvider( child: StopTypeProvider(
child: ThemeProvider( child: ThemeProvider(

View file

@ -1 +1 @@
enum EvSourceType { camera, mock } enum EvSourceType { camera, sensor }

21
lib/environment.dart Normal file
View file

@ -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 = '';
}

9
lib/launch_app.dart Normal file
View file

@ -0,0 +1,9 @@
import 'package:flutter/material.dart';
import 'application.dart';
import 'environment.dart';
void launchApp(Environment env) {
WidgetsFlutterBinding.ensureInitialized();
runApp(Application(env));
}

View file

@ -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));
}

5
lib/main_dev.dart Normal file
View file

@ -0,0 +1,5 @@
import 'package:lightmeter/environment.dart';
import 'launch_app.dart';
void main() => launchApp(const Environment.dev());

View file

@ -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));
}

5
lib/main_prod.dart Normal file
View file

@ -0,0 +1,5 @@
import 'package:lightmeter/environment.dart';
import 'launch_app.dart';
void main() => launchApp(const Environment.prod());

View file

@ -40,7 +40,7 @@ class MeteringFlow extends StatelessWidget {
context.read<HapticsInteractor>(), context.read<HapticsInteractor>(),
), ),
), ),
if (context.read<EvSourceType>() == EvSourceType.mock) if (context.read<EvSourceType>() == EvSourceType.sensor)
BlocProvider( BlocProvider(
lazy: false, lazy: false,
create: (context) => RandomEvBloc(context.read<MeteringCommunicationBloc>()), create: (context) => RandomEvBloc(context.read<MeteringCommunicationBloc>()),

View file

@ -1,5 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:lightmeter/environment.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
class ReportIssueListTile extends StatelessWidget { class ReportIssueListTile extends StatelessWidget {
@ -11,7 +13,7 @@ class ReportIssueListTile extends StatelessWidget {
leading: const Icon(Icons.bug_report), leading: const Icon(Icons.bug_report),
title: Text(S.of(context).reportIssue), title: Text(S.of(context).reportIssue),
onTap: () { onTap: () {
launchUrl(Uri.parse("https://github.com/vodemn/m3_lightmeter/issues")); launchUrl(Uri.parse(context.read<Environment>().issuesReportUrl));
}, },
); );
} }

View file

@ -1,5 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:lightmeter/environment.dart';
import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/generated/l10n.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
class SourceCodeListTile extends StatelessWidget { class SourceCodeListTile extends StatelessWidget {
@ -11,7 +13,7 @@ class SourceCodeListTile extends StatelessWidget {
leading: const Icon(Icons.code), leading: const Icon(Icons.code),
title: Text(S.of(context).sourceCode), title: Text(S.of(context).sourceCode),
onTap: () { onTap: () {
launchUrl(Uri.parse("https://github.com/vodemn/m3_lightmeter")); launchUrl(Uri.parse(context.read<Environment>().sourceCodeUrl));
}, },
); );
} }