mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-17 03:06:39 -07:00
Init repo
This commit is contained in:
commit
764b6034e3
566 changed files with 212335 additions and 0 deletions
82
lib/providers/settings/photo_view_settings_provider.dart
Normal file
82
lib/providers/settings/photo_view_settings_provider.dart
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:fladder/providers/shared_provider.dart';
|
||||
|
||||
class PhotoViewSettingsModel {
|
||||
final bool repeat;
|
||||
final bool mute;
|
||||
final bool autoPlay;
|
||||
final bool theaterMode;
|
||||
final Duration timer;
|
||||
PhotoViewSettingsModel({
|
||||
this.repeat = true,
|
||||
this.mute = false,
|
||||
this.autoPlay = false,
|
||||
this.theaterMode = false,
|
||||
this.timer = const Duration(seconds: 15),
|
||||
});
|
||||
|
||||
PhotoViewSettingsModel copyWith({
|
||||
bool? repeat,
|
||||
bool? mute,
|
||||
bool? autoPlay,
|
||||
bool? theaterMode,
|
||||
Duration? timer,
|
||||
}) {
|
||||
return PhotoViewSettingsModel(
|
||||
repeat: repeat ?? this.repeat,
|
||||
mute: mute ?? this.mute,
|
||||
autoPlay: autoPlay ?? this.autoPlay,
|
||||
theaterMode: theaterMode ?? this.theaterMode,
|
||||
timer: timer ?? this.timer,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'repeat': repeat,
|
||||
'mute': mute,
|
||||
'autoPlay': autoPlay,
|
||||
'theaterMode': theaterMode,
|
||||
'timer': timer.inMilliseconds,
|
||||
};
|
||||
}
|
||||
|
||||
factory PhotoViewSettingsModel.fromMap(Map<String, dynamic> map) {
|
||||
return PhotoViewSettingsModel(
|
||||
repeat: map['repeat'] ?? false,
|
||||
mute: map['mute'] ?? false,
|
||||
autoPlay: map['autoPlay'] ?? false,
|
||||
theaterMode: map['theaterMode'] ?? false,
|
||||
timer: map['timer'] != null ? Duration(milliseconds: map['timer'] as int) : const Duration(seconds: 15),
|
||||
);
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory PhotoViewSettingsModel.fromJson(String source) => PhotoViewSettingsModel.fromMap(json.decode(source));
|
||||
}
|
||||
|
||||
final photoViewSettingsProvider = StateNotifierProvider<PhotoViewSettingsNotifier, PhotoViewSettingsModel>((ref) {
|
||||
return PhotoViewSettingsNotifier(ref);
|
||||
});
|
||||
|
||||
final testProviderProvider = StateProvider<int>((ref) {
|
||||
return 0;
|
||||
});
|
||||
|
||||
class PhotoViewSettingsNotifier extends StateNotifier<PhotoViewSettingsModel> {
|
||||
PhotoViewSettingsNotifier(this.ref) : super(PhotoViewSettingsModel());
|
||||
|
||||
final Ref ref;
|
||||
|
||||
@override
|
||||
set state(PhotoViewSettingsModel value) {
|
||||
super.state = value;
|
||||
ref.read(sharedUtilityProvider).photoViewSettings = value;
|
||||
}
|
||||
|
||||
PhotoViewSettingsModel update(PhotoViewSettingsModel Function(PhotoViewSettingsModel state) cb) => state = cb(state);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue