mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2025-08-05 04:36:41 +00:00
added saveLogbookPhotos
option
This commit is contained in:
parent
416c3b7d9c
commit
812d3b281a
8 changed files with 66 additions and 11 deletions
|
@ -12,7 +12,7 @@ dependencies:
|
|||
m3_lightmeter_resources:
|
||||
git:
|
||||
url: "https://github.com/vodemn/m3_lightmeter_resources"
|
||||
ref: v2.1.0
|
||||
ref: v2.2.0
|
||||
shared_preferences:
|
||||
|
||||
dev_dependencies:
|
||||
|
@ -20,5 +20,10 @@ dev_dependencies:
|
|||
sdk: flutter
|
||||
flutter_lints: ^2.0.0
|
||||
|
||||
|
||||
dependency_overrides:
|
||||
m3_lightmeter_resources:
|
||||
path: /Users/vodemn/Documents/GitHub/Vodemn/m3_lightmeter_resources
|
||||
|
||||
flutter:
|
||||
uses-material-design: true
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
"cancel": "Abbrechen",
|
||||
"select": "Auswählen",
|
||||
"save": "Speichern",
|
||||
"saveNewPhotos": "Neue Fotos speichern",
|
||||
"settings": "Einstellungen",
|
||||
"metering": "Messung",
|
||||
"fractionalStops": "Zwischenstufen",
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
"cancel": "Cancel",
|
||||
"select": "Select",
|
||||
"save": "Save",
|
||||
"saveNewPhotos": "Save new photos",
|
||||
"settings": "Settings",
|
||||
"metering": "Metering",
|
||||
"fractionalStops": "Fractional stops",
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
"cancel": "Annuler",
|
||||
"select": "Sélectionner",
|
||||
"save": "Enregistrer",
|
||||
"saveNewPhotos": "Enregistrer les nouvelles photos",
|
||||
"settings": "Paramètres",
|
||||
"metering": "Mesure",
|
||||
"fractionalStops": "Arrêts fractionnaires",
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
"cancel": "Отменить",
|
||||
"select": "Выбрать",
|
||||
"save": "Сохранить",
|
||||
"saveNewPhotos": "Сохранять новые фото",
|
||||
"settings": "Настройки",
|
||||
"metering": "Измерения",
|
||||
"fractionalStops": "Дробные значения",
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
"cancel": "取消",
|
||||
"select": "选择",
|
||||
"save": "保存",
|
||||
"saveNewPhotos": "保存新照片",
|
||||
"settings": "设置",
|
||||
"metering": "测量",
|
||||
"fractionalStops": "EV 步进值",
|
||||
|
|
|
@ -30,6 +30,7 @@ class LogbookPhotosProvider extends StatefulWidget {
|
|||
|
||||
class LogbookPhotosProviderState extends State<LogbookPhotosProvider> {
|
||||
final Map<String, LogbookPhoto> _photos = {};
|
||||
bool _isEnabled = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
@ -41,10 +42,17 @@ class LogbookPhotosProviderState extends State<LogbookPhotosProvider> {
|
|||
Widget build(BuildContext context) {
|
||||
return LogbookPhotos(
|
||||
photos: context.isPro ? _photos.values.toList(growable: false) : [],
|
||||
isEnabled: _isEnabled,
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
|
||||
void saveLogbookPhotos(bool save) {
|
||||
setState(() {
|
||||
_isEnabled = save;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _init() async {
|
||||
_photos.addAll(
|
||||
Map.fromIterable(
|
||||
|
@ -62,8 +70,7 @@ class LogbookPhotosProviderState extends State<LogbookPhotosProvider> {
|
|||
required int iso,
|
||||
required int nd,
|
||||
}) async {
|
||||
if (context.isPro) {
|
||||
// Get coordinates from geolocation service
|
||||
if (context.isPro && _isEnabled) {
|
||||
final geolocationService = ServicesProvider.of(context).geolocationService;
|
||||
final coordinates = await geolocationService.getCurrentPosition();
|
||||
|
||||
|
@ -76,7 +83,7 @@ class LogbookPhotosProviderState extends State<LogbookPhotosProvider> {
|
|||
nd: nd,
|
||||
coordinates: coordinates,
|
||||
);
|
||||
await widget.storageService.addPhoto(photo);
|
||||
//await widget.storageService.addPhoto(photo);
|
||||
_photos[photo.id] = photo;
|
||||
setState(() {});
|
||||
} else {
|
||||
|
@ -106,21 +113,45 @@ class LogbookPhotosProviderState extends State<LogbookPhotosProvider> {
|
|||
}
|
||||
}
|
||||
|
||||
class LogbookPhotos extends InheritedWidget {
|
||||
enum _LogbookPhotosModelAspect { photosList, isEnabled }
|
||||
|
||||
class LogbookPhotos extends InheritedModel<_LogbookPhotosModelAspect> {
|
||||
final List<LogbookPhoto> photos;
|
||||
final bool isEnabled;
|
||||
|
||||
const LogbookPhotos({
|
||||
required this.photos,
|
||||
required this.isEnabled,
|
||||
required super.child,
|
||||
});
|
||||
|
||||
static List<LogbookPhoto> of(BuildContext context, {bool listen = false}) {
|
||||
static List<LogbookPhoto> of(BuildContext context, {bool listen = true}) {
|
||||
return (listen
|
||||
? context.dependOnInheritedWidgetOfExactType<LogbookPhotos>()
|
||||
? InheritedModel.inheritFrom<LogbookPhotos>(context, aspect: _LogbookPhotosModelAspect.photosList)
|
||||
: context.getInheritedWidgetOfExactType<LogbookPhotos>())!
|
||||
.photos;
|
||||
}
|
||||
|
||||
static bool isEnabledOf(BuildContext context, {bool listen = true}) {
|
||||
return (listen
|
||||
? InheritedModel.inheritFrom<LogbookPhotos>(context, aspect: _LogbookPhotosModelAspect.isEnabled)
|
||||
: context.getInheritedWidgetOfExactType<LogbookPhotos>())!
|
||||
.isEnabled;
|
||||
}
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(LogbookPhotos oldWidget) => !const DeepCollectionEquality().equals(oldWidget.photos, photos);
|
||||
bool updateShouldNotify(LogbookPhotos oldWidget) =>
|
||||
!const DeepCollectionEquality().equals(oldWidget.photos, photos) || oldWidget.isEnabled != isEnabled;
|
||||
|
||||
@override
|
||||
bool updateShouldNotifyDependent(LogbookPhotos oldWidget, Set<_LogbookPhotosModelAspect> aspects) {
|
||||
if (aspects.contains(_LogbookPhotosModelAspect.photosList) &&
|
||||
!const DeepCollectionEquality().equals(oldWidget.photos, photos)) {
|
||||
return true;
|
||||
}
|
||||
if (aspects.contains(_LogbookPhotosModelAspect.isEnabled) && oldWidget.isEnabled != isEnabled) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ import 'package:lightmeter/platform_config.dart';
|
|||
import 'package:lightmeter/providers/logbook_photos_provider.dart';
|
||||
import 'package:lightmeter/res/dimens.dart';
|
||||
import 'package:lightmeter/screens/logbook/components/grid_tile/widget_grid_tile_logbook_photo.dart';
|
||||
import 'package:lightmeter/screens/shared/sliver_screen/screen_sliver.dart';
|
||||
import 'package:lightmeter/screens/shared/icon_placeholder/widget_icon_placeholder.dart';
|
||||
import 'package:lightmeter/screens/shared/sliver_screen/screen_sliver.dart';
|
||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||
|
||||
class LogbookScreen extends StatefulWidget {
|
||||
|
@ -22,8 +22,22 @@ class _LogbookScreenState extends State<LogbookScreen> with SingleTickerProvider
|
|||
return SliverScreen(
|
||||
title: Text(S.of(context).logbook),
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: Card(
|
||||
margin: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: Dimens.paddingM),
|
||||
child: SwitchListTile(
|
||||
secondary: const Icon(Icons.book_outlined),
|
||||
title: Text(S.of(context).saveNewPhotos),
|
||||
value: LogbookPhotos.isEnabledOf(context),
|
||||
onChanged: LogbookPhotosProvider.of(context).saveLogbookPhotos,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
_PicturesGridBuilder(
|
||||
values: LogbookPhotos.of(context, listen: true),
|
||||
values: LogbookPhotos.of(context),
|
||||
onEdit: _editProfile,
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
|
@ -66,7 +80,7 @@ class _PicturesGridBuilder extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
return SliverPadding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
|
||||
padding: const EdgeInsets.all(Dimens.paddingM),
|
||||
sliver: SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
maxCrossAxisExtent:
|
||||
|
|
Loading…
Reference in a new issue