new: edit settings in json

This commit is contained in:
lollipopkit
2023-08-28 18:08:26 +08:00
parent 11c3bf795b
commit 0420793e21
13 changed files with 83 additions and 31 deletions

View File

@@ -233,36 +233,7 @@ class _HomePageState extends State<HomePage>
leading: const Icon(Icons.settings),
title: Text(_s.setting),
onTap: () => AppRoute.setting().go(context),
onLongPress: () async {
final map = _setting.toJson();
final go = await showRoundDialog(
context: context,
child: Text(_s.attention),
actions: [
TextButton(
onPressed: () => context.pop(true),
child: Text(
_s.ok,
style: const TextStyle(color: Colors.red),
),
),
],
);
if (go != true) {
return;
}
/// Encode [map] to String with indent `\t`
final text = const JsonEncoder.withIndent('\t').convert(map);
final result = await AppRoute.editor(
text: text,
langCode: 'json',
).go(context);
if (result == null) {
return;
}
_setting.box.putAll(json.decode(result) as Map<String, dynamic>);
},
onLongPress: _onLongPressSetting,
),
ListTile(
leading: const Icon(Icons.vpn_key),
@@ -383,4 +354,36 @@ class _HomePageState extends State<HomePage>
homeWidgetChannel.invokeMethod('update');
}
}
Future<void> _onLongPressSetting() async {
final go = await showRoundDialog(
context: context,
title: Text(_s.attention),
child: Text(_s.atOwnRisk),
actions: [
TextButton(
onPressed: () => context.pop(true),
child: Text(
_s.ok,
style: const TextStyle(color: Colors.red),
),
),
],
);
if (go != true) {
return;
}
/// Encode [map] to String with indent `\t`
final map = _setting.toJson();
final text = jsonEncoder.convert(map);
final result = await AppRoute.editor(
text: text,
langCode: 'json',
).go(context);
if (result == null) {
return;
}
_setting.box.putAll(json.decode(result) as Map<String, dynamic>);
}
}