#26 android home widget

This commit is contained in:
lollipopkit
2023-07-19 18:26:10 +08:00
parent 0ee55d4873
commit 9ce221935e
29 changed files with 461 additions and 32 deletions

View File

@@ -2,8 +2,8 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 376;
static const String engine = "3.10.5";
static const String buildAt = "2023-07-08 15:09:08.542818";
static const int modifications = 2;
static const int build = 377;
static const String engine = "3.10.6";
static const String buildAt = "2023-07-16 23:02:53.506145";
static const int modifications = 3;
}

View File

@@ -72,6 +72,7 @@
"getPushTokenFailed": "Push-Token kann nicht abgerufen werden",
"gettingToken": "Getting token...",
"goto": "Pfad öffnen",
"homeWidgetUrlConfig": "Home-Widget-Link konfigurieren",
"host": "Host",
"httpFailedWithCode": "Anfrage fehlgeschlagen, Statuscode: {code}",
"image": "Image",

View File

@@ -72,6 +72,7 @@
"getPushTokenFailed": "Can't fetch push token",
"gettingToken": "Getting token...",
"goto": "Go to",
"homeWidgetUrlConfig": "Config home widget url",
"host": "Host",
"httpFailedWithCode": "request failed, status code: {code}",
"image": "Image",

View File

@@ -72,6 +72,7 @@
"getPushTokenFailed": "未能获取到推送token",
"gettingToken": "正在获取Token...",
"goto": "前往",
"homeWidgetUrlConfig": "桌面部件链接配置",
"host": "主机",
"httpFailedWithCode": "请求失败, 状态码: {code}",
"image": "镜像",

View File

@@ -72,6 +72,7 @@
"getPushTokenFailed": "未能獲取到推送token",
"gettingToken": "正在獲取Token...",
"goto": "前往",
"homeWidgetUrlConfig": "桌面部件鏈接配置",
"host": "主機",
"httpFailedWithCode": "請求失敗, 狀態碼: {code}",
"image": "鏡像",

View File

@@ -6,6 +6,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_highlight/theme_map.dart';
import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:toolbox/core/extension/locale.dart';
import 'package:toolbox/core/extension/navigator.dart';
import 'package:toolbox/core/route.dart';
@@ -51,6 +52,7 @@ class _SettingPageState extends State<SettingPage> {
late final ServerProvider _serverProvider;
late MediaQueryData _media;
late S _s;
late SharedPreferences _sp;
final _selectedColorValue = ValueNotifier(0);
final _launchPageIdx = ValueNotifier(0);
@@ -89,6 +91,8 @@ class _SettingPageState extends State<SettingPage> {
_editorDarkTheme.value = _setting.editorDarkTheme.fetch()!;
_keyboardType.value = _setting.keyboardType.fetch()!;
_rotateQuarter.value = _setting.fullScreenRotateQuarter.fetch()!;
SharedPreferences.setPrefix('');
SharedPreferences.getInstance().then((value) => _sp = value);
}
@override
@@ -141,6 +145,7 @@ class _SettingPageState extends State<SettingPage> {
}
if (isAndroid) {
children.add(_buildBgRun());
children.add(_buildAndroidWidgetSharedPreference());
}
return Column(
children: children.map((e) => RoundRectCard(e)).toList(),
@@ -836,4 +841,56 @@ class _SettingPageState extends State<SettingPage> {
).go(context),
);
}
void _saveWidgetSP(String data, Map<String, String> old) {
context.pop();
try {
final map = Map<String, String>.from(json.decode(data));
final keysDel = old.keys.toSet().difference(map.keys.toSet());
for (final key in keysDel) {
_sp.remove(key);
}
map.forEach((key, value) {
_sp.setString(key, value);
});
showSnackBar(context, Text(_s.success));
} catch (e) {
showSnackBar(context, Text(e.toString()));
}
}
Widget _buildAndroidWidgetSharedPreference() {
return ListTile(
title: Text(_s.homeWidgetUrlConfig),
trailing: const Icon(Icons.arrow_forward_ios, size: 13),
onTap: () {
final data = <String, String>{};
_sp.getKeys().forEach((key) {
final val = _sp.getString(key);
if (val != null) {
data[key] = val;
}
});
final ctrl = TextEditingController(text: json.encode(data));
showRoundDialog(
context: context,
title: Text(_s.homeWidgetUrlConfig),
child: Input(
controller: ctrl,
label: 'JSON',
type: TextInputType.visiblePassword,
maxLines: 7,
onSubmitted: (p0) => _saveWidgetSP(p0, data),
),
actions: [
TextButton(
onPressed: () {
_saveWidgetSP(ctrl.text, data);
},
child: Text(_s.ok),
),
]);
},
);
}
}