opt.: l10n

This commit is contained in:
lollipopkit
2024-05-16 17:25:38 +08:00
parent ba4abcecfb
commit 9eb16f4703
9 changed files with 70 additions and 25 deletions

View File

@@ -65,8 +65,8 @@ class MyApp extends StatelessWidget {
return MaterialApp(
locale: locale,
localizationsDelegates: S.localizationsDelegates,
supportedLocales: S.supportedLocales,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
title: BuildData.name,
themeMode: themeMode,
theme: light,

View File

@@ -1,7 +1,4 @@
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_gen/gen_l10n/l10n_en.dart';
late S _s;
S get l10n => _s;
set l10n(S s) {
_s = s;
}
AppLocalizations l10n = AppLocalizationsEn();

View File

@@ -3,6 +3,8 @@ import 'dart:io';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:wake_on_lan/wake_on_lan.dart';
part 'wol_cfg.g.dart';
@HiveType(typeId: 8)
final class WakeOnLanCfg {
@HiveField(0)

View File

@@ -0,0 +1,47 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'wol_cfg.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class WakeOnLanCfgAdapter extends TypeAdapter<WakeOnLanCfg> {
@override
final int typeId = 8;
@override
WakeOnLanCfg read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return WakeOnLanCfg(
mac: fields[0] as String,
ip: fields[1] as String,
pwd: fields[2] as String?,
);
}
@override
void write(BinaryWriter writer, WakeOnLanCfg obj) {
writer
..writeByte(3)
..writeByte(0)
..write(obj.mac)
..writeByte(1)
..write(obj.ip)
..writeByte(2)
..write(obj.pwd);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is WakeOnLanCfgAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}

View File

@@ -63,7 +63,7 @@ class _HomePageState extends State<HomePage>
@override
void didChangeDependencies() {
super.didChangeDependencies();
l10n = S.of(context)!;
l10n = AppLocalizations.of(context)!;
_isLandscape.value =
MediaQuery.of(context).orientation == Orientation.landscape;
}

View File

@@ -532,7 +532,7 @@ class _SettingPageState extends State<SettingPage> {
onTap: () async {
final selected = await context.showPickSingleDialog(
title: l10n.language,
items: S.supportedLocales,
items: AppLocalizations.supportedLocales,
name: (p0) => p0.code,
initial: _setting.locale.fetch().toLocale,
);