mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-21 15:00:40 +00:00
Added UserPreferencesService
This commit is contained in:
parent
07dc5d8f57
commit
52d8578d77
22 changed files with 99 additions and 59 deletions
|
@ -5,7 +5,9 @@ import 'package:lightmeter/data/ev_source/ev_source_type.dart';
|
|||
import 'package:lightmeter/data/permissions_service.dart';
|
||||
import 'package:lightmeter/screens/settings/settings_screen.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'data/shared_prefs_service.dart';
|
||||
import 'generated/l10n.dart';
|
||||
import 'res/theme.dart';
|
||||
import 'screens/metering/flow_metering.dart';
|
||||
|
@ -38,35 +40,46 @@ class _ApplicationState extends State<Application> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Provider.value(
|
||||
value: widget.evSource,
|
||||
child: Provider(
|
||||
create: (context) => PermissionsService(),
|
||||
child: StopTypeProvider(
|
||||
child: MaterialApp(
|
||||
theme: ThemeData(
|
||||
useMaterial3: true,
|
||||
colorScheme: lightColorScheme,
|
||||
),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
return FutureBuilder<SharedPreferences>(
|
||||
future: SharedPreferences.getInstance(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.data != null) {
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
Provider(create: (_) => UserPreferencesService(snapshot.data!)),
|
||||
Provider.value(value: widget.evSource),
|
||||
],
|
||||
supportedLocales: S.delegate.supportedLocales,
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
|
||||
child: child!,
|
||||
child: Provider(
|
||||
create: (context) => PermissionsService(),
|
||||
child: StopTypeProvider(
|
||||
child: MaterialApp(
|
||||
theme: ThemeData(
|
||||
useMaterial3: true,
|
||||
colorScheme: lightColorScheme,
|
||||
),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: S.delegate.supportedLocales,
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
|
||||
child: child!,
|
||||
),
|
||||
home: const MeteringFlow(),
|
||||
routes: {
|
||||
"metering": (context) => const MeteringFlow(),
|
||||
"settings": (context) => const SettingsScreen(),
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
home: const MeteringFlow(),
|
||||
routes: {
|
||||
"metering": (context) => const MeteringFlow(),
|
||||
"settings": (context) => const SettingsScreen(),
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
19
lib/data/shared_prefs_service.dart
Normal file
19
lib/data/shared_prefs_service.dart
Normal file
|
@ -0,0 +1,19 @@
|
|||
import 'package:lightmeter/data/models/nd_value.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'models/iso_value.dart';
|
||||
|
||||
class UserPreferencesService {
|
||||
static const _isoKey = "ISO";
|
||||
static const _ndFilterKey = "ND";
|
||||
|
||||
final SharedPreferences _sharedPreferences;
|
||||
|
||||
UserPreferencesService(this._sharedPreferences);
|
||||
|
||||
IsoValue get iso => isoValues.firstWhere((v) => v.value == (_sharedPreferences.getInt(_isoKey) ?? 100));
|
||||
set iso(IsoValue value) => _sharedPreferences.setInt(_isoKey, value.value);
|
||||
|
||||
NdValue get ndFilter => ndValues.firstWhere((v) => v.value == (_sharedPreferences.getInt(_ndFilterKey) ?? 0));
|
||||
set ndFilter(NdValue value) => _sharedPreferences.setInt(_ndFilterKey, value.value);
|
||||
}
|
|
@ -2,12 +2,11 @@ import 'dart:async';
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:lightmeter/models/aperture_value.dart';
|
||||
import 'package:lightmeter/models/exposure_pair.dart';
|
||||
import 'package:lightmeter/models/iso_value.dart';
|
||||
import 'package:lightmeter/models/nd_value.dart';
|
||||
import 'package:lightmeter/models/photography_value.dart';
|
||||
import 'package:lightmeter/models/shutter_speed_value.dart';
|
||||
import 'package:lightmeter/data/models/aperture_value.dart';
|
||||
import 'package:lightmeter/data/models/exposure_pair.dart';
|
||||
import 'package:lightmeter/data/models/photography_value.dart';
|
||||
import 'package:lightmeter/data/models/shutter_speed_value.dart';
|
||||
import 'package:lightmeter/data/shared_prefs_service.dart';
|
||||
import 'package:lightmeter/screens/metering/communication/event_communication_metering.dart' as communication_events;
|
||||
import 'package:lightmeter/screens/metering/communication/state_communication_metering.dart' as communication_states;
|
||||
import 'package:lightmeter/utils/log_2.dart';
|
||||
|
@ -18,6 +17,7 @@ import 'state_metering.dart';
|
|||
|
||||
class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
||||
final MeteringCommunicationBloc _communicationBloc;
|
||||
final UserPreferencesService _userPreferencesService;
|
||||
late final StreamSubscription<communication_states.ScreenState> _communicationSubscription;
|
||||
|
||||
List<ApertureValue> get _apertureValues => apertureValues.whereStopType(stopType);
|
||||
|
@ -25,13 +25,16 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
|||
|
||||
StopType stopType;
|
||||
|
||||
MeteringBloc(this._communicationBloc, this.stopType)
|
||||
: super(
|
||||
MeteringBloc(
|
||||
this._communicationBloc,
|
||||
this._userPreferencesService,
|
||||
this.stopType,
|
||||
) : super(
|
||||
MeteringState(
|
||||
iso: isoValues.where((element) => element.value == 100).first,
|
||||
iso: _userPreferencesService.iso,
|
||||
ev: 0.0,
|
||||
evCompensation: 0.0,
|
||||
nd: ndValues.first,
|
||||
nd: _userPreferencesService.ndFilter,
|
||||
exposurePairs: [],
|
||||
),
|
||||
) {
|
||||
|
@ -73,6 +76,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
|||
}
|
||||
|
||||
void _onIsoChanged(IsoChangedEvent event, Emitter emit) {
|
||||
_userPreferencesService.iso = event.isoValue;
|
||||
final ev = state.ev + log2(event.isoValue.value / state.iso.value);
|
||||
emit(MeteringState(
|
||||
iso: event.isoValue,
|
||||
|
@ -84,6 +88,7 @@ class MeteringBloc extends Bloc<MeteringEvent, MeteringState> {
|
|||
}
|
||||
|
||||
void _onNdChanged(NdChangedEvent event, Emitter emit) {
|
||||
_userPreferencesService.ndFilter = event.ndValue;
|
||||
final ev = state.ev - event.ndValue.stopReduction + state.nd.stopReduction;
|
||||
emit(MeteringState(
|
||||
iso: state.iso,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:lightmeter/models/photography_value.dart';
|
||||
import 'package:lightmeter/data/models/photography_value.dart';
|
||||
import 'package:lightmeter/res/dimens.dart';
|
||||
|
||||
class ExposurePaitListItem<T extends PhotographyStopValue> extends StatelessWidget {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:lightmeter/models/exposure_pair.dart';
|
||||
import 'package:lightmeter/data/models/exposure_pair.dart';
|
||||
import 'package:lightmeter/res/dimens.dart';
|
||||
import 'package:lightmeter/screens/metering/components/exposure_pairs_list/components/exposure_pair_item.dart';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:lightmeter/generated/l10n.dart';
|
||||
import 'package:lightmeter/models/photography_value.dart';
|
||||
import 'package:lightmeter/data/models/photography_value.dart';
|
||||
import 'package:lightmeter/res/dimens.dart';
|
||||
|
||||
typedef DialogPickerItemBuilder<T extends PhotographyValue> = Widget Function(BuildContext, T);
|
||||
|
|
|
@ -2,10 +2,10 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:lightmeter/data/ev_source/camera/bloc_camera.dart';
|
||||
import 'package:lightmeter/generated/l10n.dart';
|
||||
import 'package:lightmeter/models/exposure_pair.dart';
|
||||
import 'package:lightmeter/models/iso_value.dart';
|
||||
import 'package:lightmeter/models/nd_value.dart';
|
||||
import 'package:lightmeter/models/photography_value.dart';
|
||||
import 'package:lightmeter/data/models/exposure_pair.dart';
|
||||
import 'package:lightmeter/data/models/iso_value.dart';
|
||||
import 'package:lightmeter/data/models/nd_value.dart';
|
||||
import 'package:lightmeter/data/models/photography_value.dart';
|
||||
import 'package:lightmeter/res/dimens.dart';
|
||||
|
||||
import 'components/camera_preview.dart';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:lightmeter/models/iso_value.dart';
|
||||
import 'package:lightmeter/models/nd_value.dart';
|
||||
import 'package:lightmeter/models/photography_value.dart';
|
||||
import 'package:lightmeter/data/models/iso_value.dart';
|
||||
import 'package:lightmeter/data/models/nd_value.dart';
|
||||
import 'package:lightmeter/data/models/photography_value.dart';
|
||||
|
||||
abstract class MeteringEvent {
|
||||
const MeteringEvent();
|
||||
|
|
|
@ -3,7 +3,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||
import 'package:lightmeter/data/ev_source/camera/bloc_camera.dart';
|
||||
import 'package:lightmeter/data/ev_source/ev_source_type.dart';
|
||||
import 'package:lightmeter/data/ev_source/random_ev/bloc_random_ev.dart';
|
||||
import 'package:lightmeter/models/photography_value.dart';
|
||||
import 'package:lightmeter/data/models/photography_value.dart';
|
||||
import 'package:lightmeter/data/shared_prefs_service.dart';
|
||||
import 'package:lightmeter/screens/metering/bloc_metering.dart';
|
||||
import 'package:lightmeter/screens/metering/communication/bloc_communication_metering.dart';
|
||||
|
||||
|
@ -20,6 +21,7 @@ class MeteringFlow extends StatelessWidget {
|
|||
BlocProvider(
|
||||
create: (context) => MeteringBloc(
|
||||
context.read<MeteringCommunicationBloc>(),
|
||||
context.read<UserPreferencesService>(),
|
||||
context.read<StopType>(),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:lightmeter/models/photography_value.dart';
|
||||
import 'package:lightmeter/data/models/photography_value.dart';
|
||||
import 'package:lightmeter/res/dimens.dart';
|
||||
import 'package:lightmeter/screens/settings/settings_screen.dart';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:lightmeter/models/exposure_pair.dart';
|
||||
import 'package:lightmeter/models/iso_value.dart';
|
||||
import 'package:lightmeter/models/nd_value.dart';
|
||||
import 'package:lightmeter/data/models/exposure_pair.dart';
|
||||
import 'package:lightmeter/data/models/iso_value.dart';
|
||||
import 'package:lightmeter/data/models/nd_value.dart';
|
||||
|
||||
class MeteringState {
|
||||
final double ev;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:lightmeter/generated/l10n.dart';
|
||||
import 'package:lightmeter/models/photography_value.dart';
|
||||
import 'package:lightmeter/data/models/photography_value.dart';
|
||||
|
||||
class FractionalStopsDialog extends StatefulWidget {
|
||||
final StopType selectedType;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:lightmeter/generated/l10n.dart';
|
||||
import 'package:lightmeter/models/photography_value.dart';
|
||||
import 'package:lightmeter/data/models/photography_value.dart';
|
||||
import 'package:lightmeter/utils/stop_type_provider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:lightmeter/models/photography_value.dart';
|
||||
import 'package:lightmeter/data/models/photography_value.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class StopTypeProvider extends StatefulWidget {
|
||||
|
|
|
@ -19,6 +19,7 @@ dependencies:
|
|||
material_color_utilities: ^0.2.0
|
||||
permission_handler: 10.2.0
|
||||
provider: ^6.0.4
|
||||
shared_preferences: 2.0.15
|
||||
|
||||
dev_dependencies:
|
||||
google_fonts: ^3.0.1
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:lightmeter/models/aperture_value.dart';
|
||||
import 'package:lightmeter/models/iso_value.dart';
|
||||
import 'package:lightmeter/models/photography_value.dart';
|
||||
import 'package:lightmeter/models/shutter_speed_value.dart';
|
||||
import 'package:lightmeter/data/models/aperture_value.dart';
|
||||
import 'package:lightmeter/data/models/iso_value.dart';
|
||||
import 'package:lightmeter/data/models/photography_value.dart';
|
||||
import 'package:lightmeter/data/models/shutter_speed_value.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
|
|
Loading…
Reference in a new issue