initial commit (migrated)

This commit is contained in:
fiatcode 2025-10-20 16:43:59 +07:00
commit b594facb51
143 changed files with 11057 additions and 0 deletions

View file

@ -0,0 +1,11 @@
/// Config base class
abstract class Config<T> {
/// Get config value
Future<T?> get();
/// Set config value
Future<void> set(T value);
/// Remove config value
Future<void> remove();
}

View file

@ -0,0 +1,47 @@
import 'package:kuwot/core/data/local/config.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// Theme mode shared preferences key
const themeModeConfigKey = 'themeMode';
/// Theme mode configuration
class ThemeModeConfig extends Config<ThemeMode> {
/// Default constructor
ThemeModeConfig({required this.sharedPreferences});
/// Shared preferences instance
final SharedPreferences sharedPreferences;
@override
Future<ThemeMode> get() async {
final mode = sharedPreferences.getString(themeModeConfigKey);
switch (mode) {
case 'dark':
return ThemeMode.dark;
case 'light':
return ThemeMode.light;
case 'system':
return ThemeMode.system;
default:
return ThemeMode.system;
}
}
@override
Future<void> set(ThemeMode value) async {
switch (value) {
case ThemeMode.dark:
await sharedPreferences.setString(themeModeConfigKey, 'dark');
case ThemeMode.light:
await sharedPreferences.setString(themeModeConfigKey, 'light');
case ThemeMode.system:
await sharedPreferences.setString(themeModeConfigKey, 'system');
}
}
@override
Future<void> remove() async {
await sharedPreferences.remove(themeModeConfigKey);
}
}

View file

@ -0,0 +1,45 @@
import 'dart:convert';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:kuwot/core/data/local/config.dart';
import 'package:shared_preferences/shared_preferences.dart';
part 'translation_target_config.freezed.dart';
part 'translation_target_config.g.dart';
const translationTargetConfigKey = 'translationTarget';
const defaultTranslationTarget = TranslationTarget(id: 'en', name: 'English');
@freezed
abstract class TranslationTarget with _$TranslationTarget {
const factory TranslationTarget({required String id, required String name}) =
_TranslationTarget;
factory TranslationTarget.fromJson(Map<String, dynamic> json) =>
_$TranslationTargetFromJson(json);
}
class TranslationTargetConfig extends Config<TranslationTarget> {
TranslationTargetConfig({required this.sharedPreferences});
final SharedPreferences sharedPreferences;
@override
Future<TranslationTarget?> get() async {
final data = sharedPreferences.getString(translationTargetConfigKey);
return data != null ? TranslationTarget.fromJson(jsonDecode(data)) : null;
}
@override
Future<void> set(TranslationTarget value) async {
await sharedPreferences.setString(
translationTargetConfigKey,
jsonEncode(value.toJson()),
);
}
@override
Future<void> remove() async {
await sharedPreferences.remove(translationTargetConfigKey);
}
}

View file

@ -0,0 +1,280 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'translation_target_config.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$TranslationTarget {
String get id; String get name;
/// Create a copy of TranslationTarget
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$TranslationTargetCopyWith<TranslationTarget> get copyWith => _$TranslationTargetCopyWithImpl<TranslationTarget>(this as TranslationTarget, _$identity);
/// Serializes this TranslationTarget to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is TranslationTarget&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,id,name);
@override
String toString() {
return 'TranslationTarget(id: $id, name: $name)';
}
}
/// @nodoc
abstract mixin class $TranslationTargetCopyWith<$Res> {
factory $TranslationTargetCopyWith(TranslationTarget value, $Res Function(TranslationTarget) _then) = _$TranslationTargetCopyWithImpl;
@useResult
$Res call({
String id, String name
});
}
/// @nodoc
class _$TranslationTargetCopyWithImpl<$Res>
implements $TranslationTargetCopyWith<$Res> {
_$TranslationTargetCopyWithImpl(this._self, this._then);
final TranslationTarget _self;
final $Res Function(TranslationTarget) _then;
/// Create a copy of TranslationTarget
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? name = null,}) {
return _then(_self.copyWith(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// Adds pattern-matching-related methods to [TranslationTarget].
extension TranslationTargetPatterns on TranslationTarget {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _TranslationTarget value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _TranslationTarget() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _TranslationTarget value) $default,){
final _that = this;
switch (_that) {
case _TranslationTarget():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _TranslationTarget value)? $default,){
final _that = this;
switch (_that) {
case _TranslationTarget() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String id, String name)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _TranslationTarget() when $default != null:
return $default(_that.id,_that.name);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String id, String name) $default,) {final _that = this;
switch (_that) {
case _TranslationTarget():
return $default(_that.id,_that.name);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String id, String name)? $default,) {final _that = this;
switch (_that) {
case _TranslationTarget() when $default != null:
return $default(_that.id,_that.name);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _TranslationTarget implements TranslationTarget {
const _TranslationTarget({required this.id, required this.name});
factory _TranslationTarget.fromJson(Map<String, dynamic> json) => _$TranslationTargetFromJson(json);
@override final String id;
@override final String name;
/// Create a copy of TranslationTarget
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$TranslationTargetCopyWith<_TranslationTarget> get copyWith => __$TranslationTargetCopyWithImpl<_TranslationTarget>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$TranslationTargetToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _TranslationTarget&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,id,name);
@override
String toString() {
return 'TranslationTarget(id: $id, name: $name)';
}
}
/// @nodoc
abstract mixin class _$TranslationTargetCopyWith<$Res> implements $TranslationTargetCopyWith<$Res> {
factory _$TranslationTargetCopyWith(_TranslationTarget value, $Res Function(_TranslationTarget) _then) = __$TranslationTargetCopyWithImpl;
@override @useResult
$Res call({
String id, String name
});
}
/// @nodoc
class __$TranslationTargetCopyWithImpl<$Res>
implements _$TranslationTargetCopyWith<$Res> {
__$TranslationTargetCopyWithImpl(this._self, this._then);
final _TranslationTarget _self;
final $Res Function(_TranslationTarget) _then;
/// Create a copy of TranslationTarget
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? name = null,}) {
return _then(_TranslationTarget(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
// dart format on

View file

@ -0,0 +1,13 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'translation_target_config.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_TranslationTarget _$TranslationTargetFromJson(Map<String, dynamic> json) =>
_TranslationTarget(id: json['id'] as String, name: json['name'] as String);
Map<String, dynamic> _$TranslationTargetToJson(_TranslationTarget instance) =>
<String, dynamic>{'id': instance.id, 'name': instance.name};