settings / preferences upate

This commit is contained in:
Christien Rioux 2024-07-26 16:51:03 -04:00
parent 1455aabe6c
commit d962f98786
26 changed files with 1015 additions and 125 deletions

View file

@ -1,6 +1,7 @@
import 'package:change_case/change_case.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import '../../notifications/notifications.dart';
import '../../theme/theme.dart';
part 'preferences.freezed.dart';
@ -11,19 +12,15 @@ part 'preferences.g.dart';
@freezed
class LockPreference with _$LockPreference {
const factory LockPreference({
required int inactivityLockSecs,
required bool lockWhenSwitching,
required bool lockWithSystemLock,
@Default(0) int inactivityLockSecs,
@Default(false) bool lockWhenSwitching,
@Default(false) bool lockWithSystemLock,
}) = _LockPreference;
factory LockPreference.fromJson(dynamic json) =>
_$LockPreferenceFromJson(json as Map<String, dynamic>);
static const LockPreference defaults = LockPreference(
inactivityLockSecs: 0,
lockWhenSwitching: false,
lockWithSystemLock: false,
);
static const LockPreference defaults = LockPreference();
}
// Theme supports multiple translations
@ -42,16 +39,15 @@ enum LanguagePreference {
@freezed
class Preferences with _$Preferences {
const factory Preferences({
required ThemePreferences themePreferences,
required LanguagePreference language,
required LockPreference locking,
@Default(ThemePreferences.defaults) ThemePreferences themePreference,
@Default(LanguagePreference.defaults) LanguagePreference languagePreference,
@Default(LockPreference.defaults) LockPreference lockPreference,
@Default(NotificationsPreference.defaults)
NotificationsPreference notificationsPreference,
}) = _Preferences;
factory Preferences.fromJson(dynamic json) =>
_$PreferencesFromJson(json as Map<String, dynamic>);
static const Preferences defaults = Preferences(
themePreferences: ThemePreferences.defaults,
language: LanguagePreference.defaults,
locking: LockPreference.defaults);
static const Preferences defaults = Preferences();
}

View file

@ -126,18 +126,21 @@ class __$$LockPreferenceImplCopyWithImpl<$Res>
@JsonSerializable()
class _$LockPreferenceImpl implements _LockPreference {
const _$LockPreferenceImpl(
{required this.inactivityLockSecs,
required this.lockWhenSwitching,
required this.lockWithSystemLock});
{this.inactivityLockSecs = 0,
this.lockWhenSwitching = false,
this.lockWithSystemLock = false});
factory _$LockPreferenceImpl.fromJson(Map<String, dynamic> json) =>
_$$LockPreferenceImplFromJson(json);
@override
@JsonKey()
final int inactivityLockSecs;
@override
@JsonKey()
final bool lockWhenSwitching;
@override
@JsonKey()
final bool lockWithSystemLock;
@override
@ -180,9 +183,9 @@ class _$LockPreferenceImpl implements _LockPreference {
abstract class _LockPreference implements LockPreference {
const factory _LockPreference(
{required final int inactivityLockSecs,
required final bool lockWhenSwitching,
required final bool lockWithSystemLock}) = _$LockPreferenceImpl;
{final int inactivityLockSecs,
final bool lockWhenSwitching,
final bool lockWithSystemLock}) = _$LockPreferenceImpl;
factory _LockPreference.fromJson(Map<String, dynamic> json) =
_$LockPreferenceImpl.fromJson;
@ -205,9 +208,12 @@ Preferences _$PreferencesFromJson(Map<String, dynamic> json) {
/// @nodoc
mixin _$Preferences {
ThemePreferences get themePreferences => throw _privateConstructorUsedError;
LanguagePreference get language => throw _privateConstructorUsedError;
LockPreference get locking => throw _privateConstructorUsedError;
ThemePreferences get themePreference => throw _privateConstructorUsedError;
LanguagePreference get languagePreference =>
throw _privateConstructorUsedError;
LockPreference get lockPreference => throw _privateConstructorUsedError;
NotificationsPreference get notificationsPreference =>
throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
@ -222,12 +228,14 @@ abstract class $PreferencesCopyWith<$Res> {
_$PreferencesCopyWithImpl<$Res, Preferences>;
@useResult
$Res call(
{ThemePreferences themePreferences,
LanguagePreference language,
LockPreference locking});
{ThemePreferences themePreference,
LanguagePreference languagePreference,
LockPreference lockPreference,
NotificationsPreference notificationsPreference});
$ThemePreferencesCopyWith<$Res> get themePreferences;
$LockPreferenceCopyWith<$Res> get locking;
$ThemePreferencesCopyWith<$Res> get themePreference;
$LockPreferenceCopyWith<$Res> get lockPreference;
$NotificationsPreferenceCopyWith<$Res> get notificationsPreference;
}
/// @nodoc
@ -243,39 +251,53 @@ class _$PreferencesCopyWithImpl<$Res, $Val extends Preferences>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? themePreferences = null,
Object? language = null,
Object? locking = null,
Object? themePreference = null,
Object? languagePreference = null,
Object? lockPreference = null,
Object? notificationsPreference = null,
}) {
return _then(_value.copyWith(
themePreferences: null == themePreferences
? _value.themePreferences
: themePreferences // ignore: cast_nullable_to_non_nullable
themePreference: null == themePreference
? _value.themePreference
: themePreference // ignore: cast_nullable_to_non_nullable
as ThemePreferences,
language: null == language
? _value.language
: language // ignore: cast_nullable_to_non_nullable
languagePreference: null == languagePreference
? _value.languagePreference
: languagePreference // ignore: cast_nullable_to_non_nullable
as LanguagePreference,
locking: null == locking
? _value.locking
: locking // ignore: cast_nullable_to_non_nullable
lockPreference: null == lockPreference
? _value.lockPreference
: lockPreference // ignore: cast_nullable_to_non_nullable
as LockPreference,
notificationsPreference: null == notificationsPreference
? _value.notificationsPreference
: notificationsPreference // ignore: cast_nullable_to_non_nullable
as NotificationsPreference,
) as $Val);
}
@override
@pragma('vm:prefer-inline')
$ThemePreferencesCopyWith<$Res> get themePreferences {
return $ThemePreferencesCopyWith<$Res>(_value.themePreferences, (value) {
return _then(_value.copyWith(themePreferences: value) as $Val);
$ThemePreferencesCopyWith<$Res> get themePreference {
return $ThemePreferencesCopyWith<$Res>(_value.themePreference, (value) {
return _then(_value.copyWith(themePreference: value) as $Val);
});
}
@override
@pragma('vm:prefer-inline')
$LockPreferenceCopyWith<$Res> get locking {
return $LockPreferenceCopyWith<$Res>(_value.locking, (value) {
return _then(_value.copyWith(locking: value) as $Val);
$LockPreferenceCopyWith<$Res> get lockPreference {
return $LockPreferenceCopyWith<$Res>(_value.lockPreference, (value) {
return _then(_value.copyWith(lockPreference: value) as $Val);
});
}
@override
@pragma('vm:prefer-inline')
$NotificationsPreferenceCopyWith<$Res> get notificationsPreference {
return $NotificationsPreferenceCopyWith<$Res>(
_value.notificationsPreference, (value) {
return _then(_value.copyWith(notificationsPreference: value) as $Val);
});
}
}
@ -289,14 +311,17 @@ abstract class _$$PreferencesImplCopyWith<$Res>
@override
@useResult
$Res call(
{ThemePreferences themePreferences,
LanguagePreference language,
LockPreference locking});
{ThemePreferences themePreference,
LanguagePreference languagePreference,
LockPreference lockPreference,
NotificationsPreference notificationsPreference});
@override
$ThemePreferencesCopyWith<$Res> get themePreferences;
$ThemePreferencesCopyWith<$Res> get themePreference;
@override
$LockPreferenceCopyWith<$Res> get locking;
$LockPreferenceCopyWith<$Res> get lockPreference;
@override
$NotificationsPreferenceCopyWith<$Res> get notificationsPreference;
}
/// @nodoc
@ -310,23 +335,28 @@ class __$$PreferencesImplCopyWithImpl<$Res>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? themePreferences = null,
Object? language = null,
Object? locking = null,
Object? themePreference = null,
Object? languagePreference = null,
Object? lockPreference = null,
Object? notificationsPreference = null,
}) {
return _then(_$PreferencesImpl(
themePreferences: null == themePreferences
? _value.themePreferences
: themePreferences // ignore: cast_nullable_to_non_nullable
themePreference: null == themePreference
? _value.themePreference
: themePreference // ignore: cast_nullable_to_non_nullable
as ThemePreferences,
language: null == language
? _value.language
: language // ignore: cast_nullable_to_non_nullable
languagePreference: null == languagePreference
? _value.languagePreference
: languagePreference // ignore: cast_nullable_to_non_nullable
as LanguagePreference,
locking: null == locking
? _value.locking
: locking // ignore: cast_nullable_to_non_nullable
lockPreference: null == lockPreference
? _value.lockPreference
: lockPreference // ignore: cast_nullable_to_non_nullable
as LockPreference,
notificationsPreference: null == notificationsPreference
? _value.notificationsPreference
: notificationsPreference // ignore: cast_nullable_to_non_nullable
as NotificationsPreference,
));
}
}
@ -335,23 +365,30 @@ class __$$PreferencesImplCopyWithImpl<$Res>
@JsonSerializable()
class _$PreferencesImpl implements _Preferences {
const _$PreferencesImpl(
{required this.themePreferences,
required this.language,
required this.locking});
{this.themePreference = ThemePreferences.defaults,
this.languagePreference = LanguagePreference.defaults,
this.lockPreference = LockPreference.defaults,
this.notificationsPreference = NotificationsPreference.defaults});
factory _$PreferencesImpl.fromJson(Map<String, dynamic> json) =>
_$$PreferencesImplFromJson(json);
@override
final ThemePreferences themePreferences;
@JsonKey()
final ThemePreferences themePreference;
@override
final LanguagePreference language;
@JsonKey()
final LanguagePreference languagePreference;
@override
final LockPreference locking;
@JsonKey()
final LockPreference lockPreference;
@override
@JsonKey()
final NotificationsPreference notificationsPreference;
@override
String toString() {
return 'Preferences(themePreferences: $themePreferences, language: $language, locking: $locking)';
return 'Preferences(themePreference: $themePreference, languagePreference: $languagePreference, lockPreference: $lockPreference, notificationsPreference: $notificationsPreference)';
}
@override
@ -359,17 +396,21 @@ class _$PreferencesImpl implements _Preferences {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PreferencesImpl &&
(identical(other.themePreferences, themePreferences) ||
other.themePreferences == themePreferences) &&
(identical(other.language, language) ||
other.language == language) &&
(identical(other.locking, locking) || other.locking == locking));
(identical(other.themePreference, themePreference) ||
other.themePreference == themePreference) &&
(identical(other.languagePreference, languagePreference) ||
other.languagePreference == languagePreference) &&
(identical(other.lockPreference, lockPreference) ||
other.lockPreference == lockPreference) &&
(identical(
other.notificationsPreference, notificationsPreference) ||
other.notificationsPreference == notificationsPreference));
}
@JsonKey(ignore: true)
@override
int get hashCode =>
Object.hash(runtimeType, themePreferences, language, locking);
int get hashCode => Object.hash(runtimeType, themePreference,
languagePreference, lockPreference, notificationsPreference);
@JsonKey(ignore: true)
@override
@ -387,19 +428,23 @@ class _$PreferencesImpl implements _Preferences {
abstract class _Preferences implements Preferences {
const factory _Preferences(
{required final ThemePreferences themePreferences,
required final LanguagePreference language,
required final LockPreference locking}) = _$PreferencesImpl;
{final ThemePreferences themePreference,
final LanguagePreference languagePreference,
final LockPreference lockPreference,
final NotificationsPreference notificationsPreference}) =
_$PreferencesImpl;
factory _Preferences.fromJson(Map<String, dynamic> json) =
_$PreferencesImpl.fromJson;
@override
ThemePreferences get themePreferences;
ThemePreferences get themePreference;
@override
LanguagePreference get language;
LanguagePreference get languagePreference;
@override
LockPreference get locking;
LockPreference get lockPreference;
@override
NotificationsPreference get notificationsPreference;
@override
@JsonKey(ignore: true)
_$$PreferencesImplCopyWith<_$PreferencesImpl> get copyWith =>

View file

@ -8,9 +8,9 @@ part of 'preferences.dart';
_$LockPreferenceImpl _$$LockPreferenceImplFromJson(Map<String, dynamic> json) =>
_$LockPreferenceImpl(
inactivityLockSecs: (json['inactivity_lock_secs'] as num).toInt(),
lockWhenSwitching: json['lock_when_switching'] as bool,
lockWithSystemLock: json['lock_with_system_lock'] as bool,
inactivityLockSecs: (json['inactivity_lock_secs'] as num?)?.toInt() ?? 0,
lockWhenSwitching: json['lock_when_switching'] as bool? ?? false,
lockWithSystemLock: json['lock_with_system_lock'] as bool? ?? false,
);
Map<String, dynamic> _$$LockPreferenceImplToJson(
@ -23,14 +23,24 @@ Map<String, dynamic> _$$LockPreferenceImplToJson(
_$PreferencesImpl _$$PreferencesImplFromJson(Map<String, dynamic> json) =>
_$PreferencesImpl(
themePreferences: ThemePreferences.fromJson(json['theme_preferences']),
language: LanguagePreference.fromJson(json['language']),
locking: LockPreference.fromJson(json['locking']),
themePreference: json['theme_preference'] == null
? ThemePreferences.defaults
: ThemePreferences.fromJson(json['theme_preference']),
languagePreference: json['language_preference'] == null
? LanguagePreference.defaults
: LanguagePreference.fromJson(json['language_preference']),
lockPreference: json['lock_preference'] == null
? LockPreference.defaults
: LockPreference.fromJson(json['lock_preference']),
notificationsPreference: json['notifications_preference'] == null
? NotificationsPreference.defaults
: NotificationsPreference.fromJson(json['notifications_preference']),
);
Map<String, dynamic> _$$PreferencesImplToJson(_$PreferencesImpl instance) =>
<String, dynamic>{
'theme_preferences': instance.themePreferences.toJson(),
'language': instance.language.toJson(),
'locking': instance.locking.toJson(),
'theme_preference': instance.themePreference.toJson(),
'language_preference': instance.languagePreference.toJson(),
'lock_preference': instance.lockPreference.toJson(),
'notifications_preference': instance.notificationsPreference.toJson(),
};

View file

@ -6,6 +6,7 @@ import 'package:flutter_translate/flutter_translate.dart';
import 'package:go_router/go_router.dart';
import '../layout/default_app_bar.dart';
import '../notifications/notifications.dart';
import '../theme/theme.dart';
import '../veilid_processor/veilid_processor.dart';
import 'settings.dart';
@ -49,6 +50,8 @@ class SettingsPageState extends State<SettingsPage> {
context: context, onChanged: () => setState(() {})),
buildSettingsPageBrightnessPreferences(
context: context, onChanged: () => setState(() {})),
buildSettingsPageNotificationPreferences(
context: context, onChanged: () => setState(() {})),
].map((x) => x.paddingLTRB(0, 0, 0, 8)).toList(),
),
).paddingSymmetric(horizontal: 24, vertical: 16),