opt.: migrate to new fl_lib (#649)

Fixes #648
This commit is contained in:
lollipopkit🏳️‍⚧️
2024-12-02 21:06:44 +08:00
committed by GitHub
parent b882baeafa
commit ddd32e82d4
50 changed files with 10858 additions and 225 deletions

View File

@@ -14,6 +14,7 @@ import 'package:server_box/data/res/misc.dart';
import 'package:server_box/data/res/store.dart';
import 'package:icons_plus/icons_plus.dart';
import 'package:server_box/data/store/no_backup.dart';
import 'package:webdav_client/webdav_client.dart';
class BackupPage extends StatefulWidget {
const BackupPage({super.key});
@@ -105,7 +106,7 @@ final class _BackupPageState extends State<BackupPage>
leading: const Icon(Icons.cloud),
title: const Text('iCloud'),
trailing: StoreSwitch(
prop: _noBak.icloudSync,
prop: PrefProps.icloudSync,
validator: (p0) {
if (p0 && _noBak.webdavSync.fetch()) {
context.showSnackBar(l10n.autoBackupConflict);
@@ -150,7 +151,7 @@ final class _BackupPageState extends State<BackupPage>
return false;
}
}
if (_noBak.icloudSync.fetch()) {
if (PrefProps.icloudSync.get()) {
context.showSnackBar(l10n.autoBackupConflict);
return false;
}
@@ -159,7 +160,7 @@ final class _BackupPageState extends State<BackupPage>
callback: (val) async {
if (val) {
webdavLoading.value = true;
await bakSync.sync(rs: webdav);
await bakSync.sync(rs: Webdav.shared);
webdavLoading.value = false;
}
},
@@ -326,7 +327,7 @@ final class _BackupPageState extends State<BackupPage>
Future<void> _onTapWebdavDl(BuildContext context) async {
webdavLoading.value = true;
try {
final files = await webdav.list();
final files = await Webdav.shared.list();
if (files.isEmpty) return context.showSnackBar(l10n.dirEmpty);
final fileName = await context.showPickSingleDialog(
@@ -335,7 +336,7 @@ final class _BackupPageState extends State<BackupPage>
);
if (fileName == null) return;
await webdav.download(relativePath: fileName);
await Webdav.shared.download(relativePath: fileName);
final dlFile = await File('${Paths.doc}/$fileName').readAsString();
final dlBak = await Computer.shared.start(Backup.fromJsonString, dlFile);
await dlBak.merge(force: true);
@@ -353,7 +354,7 @@ final class _BackupPageState extends State<BackupPage>
final bakName = '$date-${Miscs.bakFileName}';
try {
await Backup.backup(bakName);
await webdav.upload(relativePath: bakName);
await Webdav.shared.upload(relativePath: bakName);
Loggers.app.info('Upload webdav backup success');
} catch (e, s) {
context.showErrDialog(e, s, l10n.upload);
@@ -403,12 +404,8 @@ final class _BackupPageState extends State<BackupPage>
try {
await Webdav.test(url.text, user.text, pwd.text);
context.showSnackBar(libL10n.success);
webdav.init(WebdavInitArgs(
url: url.text,
user: user.text,
pwd: pwd.text,
prefix: 'serverbox/',
));
Webdav.shared.client =
WebdavClient(url: url.text, user: user.text, pwd: pwd.text);
} catch (e, s) {
context.showErrDialog(e, s, 'Webdav');
}

View File

@@ -175,7 +175,7 @@ class _ContainerPageState extends State<ContainerPage> {
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(_container.type.name.upperFirst),
Text(_container.type.name.capitalize),
Text(_container.version ?? l10n.unknown),
],
),

View File

@@ -23,4 +23,4 @@ final class _AppBar extends StatelessWidget implements PreferredSizeWidget {
};
return Size.fromHeight(height);
}
}
}

View File

@@ -144,7 +144,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
Widget _buildLogo(Server si) {
var logoUrl = si.spi.custom?.logoUrl ??
_settings.serverLogoUrl.fetch().selfIfNotNullEmpty;
_settings.serverLogoUrl.fetch().selfNotEmptyOrNull;
if (logoUrl == null) return UIs.placeholder;
final dist = si.status.more[StatusCmdType.sys]?.dist;

View File

@@ -438,7 +438,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
leading: const Icon(MingCute.doc_line),
title: Text(libL10n.doc),
trailing: const Icon(Icons.open_in_new, size: 17),
onTap: () => l10n.customCmdDocUrl.launch(),
onTap: l10n.customCmdDocUrl.launchUrl,
).cardx,
],
);
@@ -572,13 +572,13 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
}
final customCmds = _customCmds.value;
final custom = ServerCustom(
pveAddr: _pveAddrCtrl.text.selfIfNotNullEmpty,
pveAddr: _pveAddrCtrl.text.selfNotEmptyOrNull,
pveIgnoreCert: _pveIgnoreCert.value,
cmds: customCmds.isEmpty ? null : customCmds,
preferTempDev: _preferTempDevCtrl.text.selfIfNotNullEmpty,
logoUrl: _logoUrlCtrl.text.selfIfNotNullEmpty,
netDev: _netDevCtrl.text.selfIfNotNullEmpty,
scriptDir: _scriptDirCtrl.text.selfIfNotNullEmpty,
preferTempDev: _preferTempDevCtrl.text.selfNotEmptyOrNull,
logoUrl: _logoUrlCtrl.text.selfNotEmptyOrNull,
netDev: _netDevCtrl.text.selfNotEmptyOrNull,
scriptDir: _scriptDirCtrl.text.selfNotEmptyOrNull,
);
final wolEmpty = _wolMacCtrl.text.isEmpty &&
@@ -589,7 +589,7 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
: WakeOnLanCfg(
mac: _wolMacCtrl.text,
ip: _wolIpCtrl.text,
pwd: _wolPwdCtrl.text.selfIfNotNullEmpty,
pwd: _wolPwdCtrl.text.selfNotEmptyOrNull,
);
if (wol != null) {
final wolValidation = wol.validate();
@@ -606,12 +606,12 @@ class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
ip: _ipController.text,
port: int.parse(_portController.text),
user: _usernameController.text,
pwd: _passwordController.text.selfIfNotNullEmpty,
pwd: _passwordController.text.selfNotEmptyOrNull,
keyId: _keyIdx.value != null
? PrivateKeyProvider.pkis.value.elementAt(_keyIdx.value!).id
: null,
tags: _tags.value.isEmpty ? null : _tags.value.toList(),
alterUrl: _altUrlController.text.selfIfNotNullEmpty,
alterUrl: _altUrlController.text.selfNotEmptyOrNull,
autoConnect: _autoConnect.value,
jumpId: _jumpServer.value,
custom: custom,

View File

@@ -4,7 +4,8 @@ import 'dart:io';
import 'package:fl_lib/fl_lib.dart';
import 'package:flutter/material.dart';
import 'package:flutter_highlight/theme_map.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:server_box/generated/l10n/l10n.dart';
import 'package:icons_plus/icons_plus.dart';
import 'package:server_box/core/extension/context/locale.dart';
import 'package:server_box/data/res/github_id.dart';
@@ -140,12 +141,12 @@ final class _AppAboutPageState extends State<AppAboutPage>
Btn.elevated(
icon: const Icon(Icons.edit_document),
text: 'Wiki',
onTap: Urls.appWiki.launch,
onTap: Urls.appWiki.launchUrl,
),
Btn.elevated(
icon: const Icon(Icons.feedback),
text: libL10n.feedback,
onTap: Urls.appHelp.launch,
onTap: Urls.appHelp.launchUrl,
),
Btn.elevated(
icon: const Icon(MingCute.question_fill),
@@ -298,7 +299,7 @@ final class _AppSettingsPageState extends State<AppSettingsPage> {
Widget _buildCheckUpdate() {
return ListTile(
leading: const Icon(Icons.update),
title: Text(libL10n.autoCheckUpdate),
title: Text(libL10n.checkUpdate),
subtitle: ValBuilder(
listenable: AppUpdateIface.newestBuild,
builder: (val) {
@@ -404,7 +405,7 @@ final class _AppSettingsPageState extends State<AppSettingsPage> {
}
void _onSaveColor(String s) {
final color = s.hexToColor;
final color = s.fromColorHex;
if (color == null) {
context.showSnackBar(libL10n.fail);
return;
@@ -837,15 +838,10 @@ final class _AppSettingsPageState extends State<AppSettingsPage> {
leading: const Icon(Icons.delete_forever),
trailing: const Icon(Icons.keyboard_arrow_right),
onTap: () async {
final keys = Stores.server.box.keys.toList();
keys.removeWhere((element) => element == BoxX.lastModifiedKey);
final strKeys = List<String>.empty(growable: true);
for (final key in keys) {
if (key is String) strKeys.add(key);
}
final keys = Stores.server.keys();
final deleteKeys = await context.showPickDialog<String>(
clearable: true,
items: strKeys,
items: keys.toList(),
);
if (deleteKeys == null) return;
@@ -965,8 +961,8 @@ final class _AppSettingsPageState extends State<AppSettingsPage> {
);
}
void _showFontSizeDialog(StorePropertyBase<double> property) {
final ctrller = TextEditingController(text: property.fetch().toString());
void _showFontSizeDialog(HiveProp<double> property) {
final ctrller = TextEditingController(text: property.get().toString());
void onSave() {
context.pop();
final fontSize = double.tryParse(ctrller.text);
@@ -977,7 +973,7 @@ final class _AppSettingsPageState extends State<AppSettingsPage> {
);
return;
}
property.put(fontSize);
property.set(fontSize);
}
context.showRoundDialog(
@@ -1081,7 +1077,7 @@ final class _AppSettingsPageState extends State<AppSettingsPage> {
return ExpandTile(
leading: const Icon(MingCute.more_3_fill),
title: Text(l10n.more),
initiallyExpanded: isDesktop,
initiallyExpanded: false,
children: [
_buildRememberPwdInMem(),
_buildTextScaler(),
@@ -1144,7 +1140,7 @@ final class _AppSettingsPageState extends State<AppSettingsPage> {
return ExpandTile(
leading: const Icon(MingCute.more_3_fill),
title: Text(l10n.more),
initiallyExpanded: isDesktop,
initiallyExpanded: false,
children: [
_buildBeta(),
if (isMobile) _buildWakeLock(),
@@ -1249,7 +1245,7 @@ final class _AppSettingsPageState extends State<AppSettingsPage> {
ListTile(
title: Text(libL10n.doc),
trailing: const Icon(Icons.open_in_new),
onTap: () => Urls.appWiki.launch(),
onTap: Urls.appWiki.launchUrl,
),
],
),
@@ -1326,7 +1322,7 @@ final class _AppSettingsPageState extends State<AppSettingsPage> {
}
Future<void> _editRawSettings() async {
final map = Stores.setting.box.toJson(includeInternal: false);
final map = await Stores.setting.getAllMap(includeInternalKeys: true);
final keys = map.keys;
/// Encode [map] to String with indent `\t`

View File

@@ -42,11 +42,11 @@ class _AndroidSettingsPageState extends State<AndroidSettingsPage> {
final keysDel = old.keys.toSet().difference(map.keys.toSet());
for (final key in keysDel) {
if (!key.startsWith(_homeWidgetPrefPrefix)) continue;
PrefStore.remove(key);
PrefStore.shared.remove(key);
}
for (final entry in map.entries) {
if (!entry.key.startsWith(_homeWidgetPrefPrefix)) continue;
PrefStore.set(entry.key, entry.value);
PrefStore.shared.set(entry.key, entry.value);
}
context.showSnackBar(libL10n.success);
} catch (e) {
@@ -60,8 +60,10 @@ class _AndroidSettingsPageState extends State<AndroidSettingsPage> {
trailing: const Icon(Icons.keyboard_arrow_right),
onTap: () async {
final data = <String, String>{};
for (final key in PrefStore.keys()) {
final val = PrefStore.get<String>(key);
final keys = await PrefStore.shared.keys();
for (final key in keys) {
final val = PrefStore.shared.get<String>(key);
if (val != null) {
data[key] = val;
}

View File

@@ -112,7 +112,7 @@ class SSHPageState extends State<SSHPage>
2 => true,
_ => context.isDark,
};
_media = context.media;
_media = context.mediaQuery;
_terminalTheme = _isDark ? TerminalThemes.dark : TerminalThemes.light;
_terminalTheme = _terminalTheme.copyWith(selectionCursor: UIs.primaryColor);

View File

@@ -268,7 +268,7 @@ class _AddPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
const viewPadding = 7.0;
final viewWidth = context.media.size.width - 2 * viewPadding;
final viewWidth = context.mediaQuery.size.width - 2 * viewPadding;
final itemCount = ServerProvider.servers.length;
const itemPadding = 1.0;

View File

@@ -51,7 +51,7 @@ class _LocalFilePageState extends State<LocalFilePage>
@override
Widget build(BuildContext context) {
super.build(context);
final title = _path.path.fileName ?? libL10n.file;
final title = _path.path.fileNameGetter ?? libL10n.file;
return Scaffold(
appBar: CustomAppBar(
title: AnimatedSwitcher(

View File

@@ -591,7 +591,7 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
String _getRemotePath(SftpName name) {
final prePath = _status.path.path;
// Only support Linux as remote now, so the seperator is '/'
return prePath.joinPath(name.filename, seperator: '/');
return prePath.joinPath(name.filename, separator: '/');
}
/// Local file dir + server id + remote path

View File

@@ -137,22 +137,22 @@ final class _SystemdPageState extends State<SystemdPage> {
children: [
Icon(func.icon, size: 19),
const SizedBox(width: 10),
Text(func.name.upperFirst),
Text(func.name.capitalize),
],
),
);
}
Widget _buildScopeTag(SystemdUnitScope scope) {
return _buildTag(scope.name.upperFirst, scope.color, true);
return _buildTag(scope.name.capitalize, scope.color, true);
}
Widget _buildStateTag(SystemdUnitState state) {
return _buildTag(state.name.upperFirst, state.color);
return _buildTag(state.name.capitalize, state.color);
}
Widget _buildTypeTag(SystemdUnitType type) {
return _buildTag(type.name.upperFirst);
return _buildTag(type.name.capitalize);
}
Widget _buildTag(String tag, [Color? color, bool noPad = false]) {