feat: 实现起卦、设置与积分系统
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../l10n/app_localizations.dart';
|
||||
|
||||
String displayLanguageLabel(AppLocalizations l10n, String languageTag) {
|
||||
return switch (languageTag) {
|
||||
'en-US' => l10n.english,
|
||||
_ => l10n.chinese,
|
||||
};
|
||||
}
|
||||
|
||||
class PreferenceSettings {
|
||||
const PreferenceSettings({
|
||||
this.interfaceLanguage = 'zh-CN',
|
||||
this.aiLanguage = 'zh-CN',
|
||||
this.timezone = 'Asia/Shanghai',
|
||||
this.country = 'CN',
|
||||
});
|
||||
|
||||
final String interfaceLanguage;
|
||||
final String aiLanguage;
|
||||
final String timezone;
|
||||
final String country;
|
||||
|
||||
PreferenceSettings copyWith({
|
||||
String? interfaceLanguage,
|
||||
String? aiLanguage,
|
||||
String? timezone,
|
||||
String? country,
|
||||
}) {
|
||||
return PreferenceSettings(
|
||||
interfaceLanguage: interfaceLanguage ?? this.interfaceLanguage,
|
||||
aiLanguage: aiLanguage ?? this.aiLanguage,
|
||||
timezone: timezone ?? this.timezone,
|
||||
country: country ?? this.country,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ProfileSettingsV1 {
|
||||
const ProfileSettingsV1({
|
||||
this.version = 1,
|
||||
this.preferences = const PreferenceSettings(),
|
||||
this.privacy = const <String, Object?>{},
|
||||
this.notification = const <String, Object?>{},
|
||||
});
|
||||
|
||||
final int version;
|
||||
final PreferenceSettings preferences;
|
||||
final Map<String, Object?> privacy;
|
||||
final Map<String, Object?> notification;
|
||||
|
||||
ProfileSettingsV1 copyWith({
|
||||
int? version,
|
||||
PreferenceSettings? preferences,
|
||||
Map<String, Object?>? privacy,
|
||||
Map<String, Object?>? notification,
|
||||
}) {
|
||||
return ProfileSettingsV1(
|
||||
version: version ?? this.version,
|
||||
preferences: preferences ?? this.preferences,
|
||||
privacy: privacy ?? this.privacy,
|
||||
notification: notification ?? this.notification,
|
||||
);
|
||||
}
|
||||
|
||||
factory ProfileSettingsV1.defaultsForLocale(Locale locale) {
|
||||
final tag = languageTagFromLocale(locale);
|
||||
return ProfileSettingsV1(
|
||||
preferences: PreferenceSettings(interfaceLanguage: tag, aiLanguage: tag),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String languageTagFromLocale(Locale locale) {
|
||||
switch (locale.languageCode) {
|
||||
case 'en':
|
||||
return 'en-US';
|
||||
case 'zh':
|
||||
default:
|
||||
return 'zh-CN';
|
||||
}
|
||||
}
|
||||
|
||||
Locale localeFromLanguageTag(String tag) {
|
||||
if (tag.toLowerCase().startsWith('en')) {
|
||||
return const Locale('en');
|
||||
}
|
||||
return const Locale('zh');
|
||||
}
|
||||
Reference in New Issue
Block a user