mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-24 08:20:40 +00:00
Compare commits
No commits in common. "8bc35633a750a86abd2d8ec5d0919996a06af239" and "dff3eefc4b6cb5205bc09633fce95b3c5c06c570" have entirely different histories.
8bc35633a7
...
dff3eefc4b
5 changed files with 59 additions and 84 deletions
|
@ -14,7 +14,7 @@ class FilmsStorageService {
|
||||||
String get selectedFilmId => '';
|
String get selectedFilmId => '';
|
||||||
set selectedFilmId(String id) {}
|
set selectedFilmId(String id) {}
|
||||||
|
|
||||||
Future<void> addFilm(FilmExponential _, {bool isUsed = true}) async {}
|
Future<void> addFilm(FilmExponential _) async {}
|
||||||
|
|
||||||
Future<void> updateFilm(FilmExponential _) async {}
|
Future<void> updateFilm(FilmExponential _) async {}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_native_splash/flutter_native_splash.dart';
|
|
||||||
import 'package:lightmeter/data/analytics/analytics.dart';
|
import 'package:lightmeter/data/analytics/analytics.dart';
|
||||||
import 'package:lightmeter/data/analytics/api/analytics_firebase.dart';
|
import 'package:lightmeter/data/analytics/api/analytics_firebase.dart';
|
||||||
import 'package:lightmeter/data/caffeine_service.dart';
|
import 'package:lightmeter/data/caffeine_service.dart';
|
||||||
|
@ -19,88 +18,61 @@ import 'package:m3_lightmeter_iap/m3_lightmeter_iap.dart';
|
||||||
import 'package:platform/platform.dart';
|
import 'package:platform/platform.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class ApplicationWrapper extends StatefulWidget {
|
class ApplicationWrapper extends StatelessWidget {
|
||||||
final Environment env;
|
final Environment env;
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
|
||||||
const ApplicationWrapper(this.env, {required this.child, super.key});
|
const ApplicationWrapper(this.env, {required this.child, super.key});
|
||||||
|
|
||||||
@override
|
|
||||||
State<ApplicationWrapper> createState() => _ApplicationWrapperState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ApplicationWrapperState extends State<ApplicationWrapper> {
|
|
||||||
late final remoteConfigService = widget.env.buildType != BuildType.dev
|
|
||||||
? const RemoteConfigService(LightmeterAnalytics(api: LightmeterAnalyticsFirebase()))
|
|
||||||
: const MockRemoteConfigService();
|
|
||||||
|
|
||||||
late final IAPStorageService iapStorageService;
|
|
||||||
late final UserPreferencesService userPreferencesService;
|
|
||||||
late final bool hasLightSensor;
|
|
||||||
|
|
||||||
final filmsStorageService = FilmsStorageService();
|
|
||||||
final filmsProviderKey = GlobalKey<FilmsProviderState>();
|
|
||||||
|
|
||||||
late final Future<void> _initFuture;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_initFuture = _initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return FilmsProvider(
|
final remoteConfigService = env.buildType != BuildType.dev
|
||||||
key: filmsProviderKey,
|
? const RemoteConfigService(LightmeterAnalytics(api: LightmeterAnalyticsFirebase()))
|
||||||
filmsStorageService: filmsStorageService,
|
: const MockRemoteConfigService();
|
||||||
child: FutureBuilder(
|
final filmsStorageService = FilmsStorageService();
|
||||||
future: _initFuture,
|
return FutureBuilder(
|
||||||
builder: (context, snapshot) {
|
future: Future.wait<dynamic>([
|
||||||
if (snapshot.error != null) {
|
SharedPreferences.getInstance(),
|
||||||
return Center(child: Text(snapshot.error!.toString()));
|
const LightSensorService(LocalPlatform()).hasSensor(),
|
||||||
} else if (snapshot.connectionState == ConnectionState.done) {
|
remoteConfigService.activeAndFetchFeatures(),
|
||||||
return ServicesProvider(
|
filmsStorageService.init(),
|
||||||
analytics: const LightmeterAnalytics(api: LightmeterAnalyticsFirebase()),
|
]),
|
||||||
caffeineService: const CaffeineService(),
|
builder: (_, snapshot) {
|
||||||
environment: widget.env.copyWith(hasLightSensor: hasLightSensor),
|
if (snapshot.data != null) {
|
||||||
hapticsService: const HapticsService(),
|
final iapService = IAPStorageService(snapshot.data![0] as SharedPreferences);
|
||||||
lightSensorService: const LightSensorService(LocalPlatform()),
|
final userPreferencesService = UserPreferencesService(snapshot.data![0] as SharedPreferences);
|
||||||
permissionsService: const PermissionsService(),
|
final hasLightSensor = snapshot.data![1] as bool;
|
||||||
userPreferencesService: userPreferencesService,
|
return ServicesProvider(
|
||||||
volumeEventsService: const VolumeEventsService(LocalPlatform()),
|
analytics: const LightmeterAnalytics(api: LightmeterAnalyticsFirebase()),
|
||||||
child: RemoteConfigProvider(
|
caffeineService: const CaffeineService(),
|
||||||
remoteConfigService: remoteConfigService,
|
environment: env.copyWith(hasLightSensor: hasLightSensor),
|
||||||
child: EquipmentProfileProvider(
|
hapticsService: const HapticsService(),
|
||||||
storageService: iapStorageService,
|
lightSensorService: const LightSensorService(LocalPlatform()),
|
||||||
|
permissionsService: const PermissionsService(),
|
||||||
|
userPreferencesService: userPreferencesService,
|
||||||
|
volumeEventsService: const VolumeEventsService(LocalPlatform()),
|
||||||
|
child: RemoteConfigProvider(
|
||||||
|
remoteConfigService: remoteConfigService,
|
||||||
|
child: EquipmentProfileProvider(
|
||||||
|
storageService: iapService,
|
||||||
|
child: FilmsProvider(
|
||||||
|
filmsStorageService: filmsStorageService,
|
||||||
child: UserPreferencesProvider(
|
child: UserPreferencesProvider(
|
||||||
hasLightSensor: hasLightSensor,
|
hasLightSensor: hasLightSensor,
|
||||||
userPreferencesService: userPreferencesService,
|
userPreferencesService: userPreferencesService,
|
||||||
child: widget.child,
|
child: child,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
}
|
);
|
||||||
|
} else if (snapshot.error != null) {
|
||||||
|
return Center(child: Text(snapshot.error!.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
return const SizedBox();
|
// TODO(@vodemn): maybe user splashscreen instead
|
||||||
},
|
return const SizedBox();
|
||||||
),
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _initialize() async {
|
|
||||||
await Future.wait([
|
|
||||||
SharedPreferences.getInstance(),
|
|
||||||
const LightSensorService(LocalPlatform()).hasSensor(),
|
|
||||||
remoteConfigService.activeAndFetchFeatures(),
|
|
||||||
filmsStorageService.init().then((_) => filmsProviderKey.currentState?.init()),
|
|
||||||
]).then((value) {
|
|
||||||
final sharedPrefs = (value[0] as SharedPreferences?)!;
|
|
||||||
iapStorageService = IAPStorageService(sharedPrefs);
|
|
||||||
userPreferencesService = UserPreferencesService(sharedPrefs);
|
|
||||||
hasLightSensor = value[1] as bool? ?? false;
|
|
||||||
FlutterNativeSplash.remove();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,10 +24,16 @@ class FilmsProvider extends StatefulWidget {
|
||||||
class FilmsProviderState extends State<FilmsProvider> {
|
class FilmsProviderState extends State<FilmsProvider> {
|
||||||
final Map<String, SelectableFilm<Film>> predefinedFilms = {};
|
final Map<String, SelectableFilm<Film>> predefinedFilms = {};
|
||||||
final Map<String, SelectableFilm<FilmExponential>> customFilms = {};
|
final Map<String, SelectableFilm<FilmExponential>> customFilms = {};
|
||||||
String _selectedId = '';
|
late String _selectedId;
|
||||||
|
|
||||||
Film get _selectedFilm => customFilms[_selectedId]?.film ?? predefinedFilms[_selectedId]?.film ?? const FilmStub();
|
Film get _selectedFilm => customFilms[_selectedId]?.film ?? predefinedFilms[_selectedId]?.film ?? const FilmStub();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_init();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Films(
|
return Films(
|
||||||
|
@ -38,14 +44,6 @@ class FilmsProviderState extends State<FilmsProvider> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> init() async {
|
|
||||||
_selectedId = widget.filmsStorageService.selectedFilmId;
|
|
||||||
predefinedFilms.addAll(await widget.filmsStorageService.getPredefinedFilms());
|
|
||||||
customFilms.addAll(await widget.filmsStorageService.getCustomFilms());
|
|
||||||
_discardSelectedIfNotIncluded();
|
|
||||||
if (mounted) setState(() {});
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Both type of films **/
|
/* Both type of films **/
|
||||||
|
|
||||||
Future<void> toggleFilm(Film film, bool enabled) async {
|
Future<void> toggleFilm(Film film, bool enabled) async {
|
||||||
|
@ -91,6 +89,14 @@ class FilmsProviderState extends State<FilmsProvider> {
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _init() async {
|
||||||
|
_selectedId = widget.filmsStorageService.selectedFilmId;
|
||||||
|
predefinedFilms.addAll(await widget.filmsStorageService.getPredefinedFilms());
|
||||||
|
customFilms.addAll(await widget.filmsStorageService.getCustomFilms());
|
||||||
|
_discardSelectedIfNotIncluded();
|
||||||
|
if (mounted) setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
void _discardSelectedIfNotIncluded() {
|
void _discardSelectedIfNotIncluded() {
|
||||||
if (_selectedId == const FilmStub().id) {
|
if (_selectedId == const FilmStub().id) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -2,7 +2,6 @@ import 'dart:async';
|
||||||
|
|
||||||
import 'package:firebase_core/firebase_core.dart';
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_native_splash/flutter_native_splash.dart';
|
|
||||||
import 'package:lightmeter/application.dart';
|
import 'package:lightmeter/application.dart';
|
||||||
import 'package:lightmeter/application_wrapper.dart';
|
import 'package:lightmeter/application_wrapper.dart';
|
||||||
import 'package:lightmeter/constants.dart';
|
import 'package:lightmeter/constants.dart';
|
||||||
|
@ -17,8 +16,7 @@ const _errorsLogger = LightmeterAnalytics(api: LightmeterAnalyticsFirebase());
|
||||||
Future<void> runLightmeterApp(Environment env) async {
|
Future<void> runLightmeterApp(Environment env) async {
|
||||||
runZonedGuarded(
|
runZonedGuarded(
|
||||||
() async {
|
() async {
|
||||||
final widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
|
|
||||||
if (env.buildType == BuildType.prod) {
|
if (env.buildType == BuildType.prod) {
|
||||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||||
}
|
}
|
||||||
|
@ -30,7 +28,6 @@ Future<void> runLightmeterApp(Environment env) async {
|
||||||
products: [
|
products: [
|
||||||
IAPProduct(
|
IAPProduct(
|
||||||
storeId: IAPProductType.paidFeatures.storeId,
|
storeId: IAPProductType.paidFeatures.storeId,
|
||||||
status: IAPProductStatus.purchased,
|
|
||||||
price: '0.0\$',
|
price: '0.0\$',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
@ -24,7 +24,6 @@ dependencies:
|
||||||
flutter_bloc: 8.1.3
|
flutter_bloc: 8.1.3
|
||||||
flutter_localizations:
|
flutter_localizations:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
flutter_native_splash: 2.3.5
|
|
||||||
intl: 0.18.1
|
intl: 0.18.1
|
||||||
intl_utils: 2.8.2
|
intl_utils: 2.8.2
|
||||||
light_sensor: 3.0.0
|
light_sensor: 3.0.0
|
||||||
|
@ -49,6 +48,7 @@ dev_dependencies:
|
||||||
args: 2.5.0
|
args: 2.5.0
|
||||||
bloc_test: 9.1.3
|
bloc_test: 9.1.3
|
||||||
build_runner: 2.4.6
|
build_runner: 2.4.6
|
||||||
|
flutter_native_splash: 2.3.5
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
golden_toolkit: 0.15.0
|
golden_toolkit: 0.15.0
|
||||||
|
|
Loading…
Reference in a new issue