mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
new: edit settings in json
This commit is contained in:
@@ -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>);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user