From 324bbba8d2bb2297d850dbe3c5869cd899d92db9 Mon Sep 17 00:00:00 2001 From: wanghongenpin Date: Thu, 16 Jan 2025 18:33:12 +0800 Subject: [PATCH] request rewrite body json format --- .../setting/rewrite/rewrite_update.dart | 5 ++--- .../setting/rewrite/rewrite_replace.dart | 20 +++++++++++++++++-- .../setting/rewrite/rewrite_update.dart | 18 ++++++++++++++++- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/lib/ui/desktop/toolbar/setting/rewrite/rewrite_update.dart b/lib/ui/desktop/toolbar/setting/rewrite/rewrite_update.dart index b81e352..bc376a1 100644 --- a/lib/ui/desktop/toolbar/setting/rewrite/rewrite_update.dart +++ b/lib/ui/desktop/toolbar/setting/rewrite/rewrite_update.dart @@ -229,9 +229,8 @@ class _RewriteUpdateAddState extends State { child: Text(localizations.testData, style: const TextStyle(fontSize: 14))), const SizedBox(width: 10), if (!isMatch) - Expanded( - child: - Text(localizations.noChangesDetected, style: TextStyle(color: Colors.red, fontSize: 14))), + Text(localizations.noChangesDetected, style: TextStyle(color: Colors.red, fontSize: 14)), + Expanded(child: SizedBox()), IconButton( tooltip: 'JSON Format', icon: Icon(Icons.data_object, diff --git a/lib/ui/mobile/setting/rewrite/rewrite_replace.dart b/lib/ui/mobile/setting/rewrite/rewrite_replace.dart index 907af45..b7d796a 100644 --- a/lib/ui/mobile/setting/rewrite/rewrite_replace.dart +++ b/lib/ui/mobile/setting/rewrite/rewrite_replace.dart @@ -154,6 +154,8 @@ class RewriteReplaceState extends State { .toList()); } + bool jsonFormatted = false; + //body Widget body() { bool isCN = Localizations.localeOf(context) == const Locale.fromSubtags(languageCode: 'zh'); @@ -183,8 +185,21 @@ class RewriteReplaceState extends State { }))), Expanded( child: Row(mainAxisAlignment: MainAxisAlignment.end, children: [ + IconButton( + tooltip: 'JSON Format', + icon: + Icon(Icons.data_object, size: 20, color: jsonFormatted ? Theme.of(context).colorScheme.primary : null), + onPressed: () { + setState(() { + jsonFormatted = !jsonFormatted; + bodyTextController.text = + jsonFormatted ? JSON.pretty(bodyTextController.text) : JSON.compact(bodyTextController.text); + }); + }, + ), + const SizedBox(width: 5), Text(localizations.enable), - const SizedBox(width: 10), + const SizedBox(width: 5), SwitchWidget( value: rewriteItem.enabled, scale: 0.65, @@ -481,7 +496,8 @@ class HeadersState extends State with AutomaticKeepAliveClientMixin { physics: const ClampingScrollPhysics(), separatorBuilder: (context, index) => index == list.length ? const SizedBox() : const Divider(thickness: 0.2), - itemBuilder: (context, index) => index < list.length?list[index] + itemBuilder: (context, index) => index < list.length + ? list[index] : TextButton( child: Text("${localizations.add}Header", textAlign: TextAlign.center), onPressed: () { diff --git a/lib/ui/mobile/setting/rewrite/rewrite_update.dart b/lib/ui/mobile/setting/rewrite/rewrite_update.dart index 0f81d77..6e01b63 100644 --- a/lib/ui/mobile/setting/rewrite/rewrite_update.dart +++ b/lib/ui/mobile/setting/rewrite/rewrite_update.dart @@ -118,6 +118,8 @@ class _RewriteUpdateAddState extends State { var valueController = TextEditingController(); var dataController = HighlightTextEditingController(); + bool jsonFormatted = false; + AppLocalizations get i18n => AppLocalizations.of(context)!; @override @@ -218,7 +220,21 @@ class _RewriteUpdateAddState extends State { Align( alignment: Alignment.centerLeft, child: Text(i18n.testData, style: const TextStyle(fontSize: 14))), const SizedBox(width: 10), - if (!isMatch) Text(i18n.noChangesDetected, style: TextStyle(color: Colors.red, fontSize: 14)) + if (!isMatch) Text(i18n.noChangesDetected, style: TextStyle(color: Colors.red, fontSize: 14)), + Expanded(child: SizedBox()), + IconButton( + tooltip: 'JSON Format', + icon: Icon(Icons.data_object, + size: 20, color: jsonFormatted ? Theme.of(context).colorScheme.primary : null), + onPressed: () { + setState(() { + jsonFormatted = !jsonFormatted; + dataController.text = + jsonFormatted ? JSON.pretty(dataController.text) : JSON.compact(dataController.text); + }); + }, + ), + const SizedBox(width: 3), ]), const SizedBox(height: 5), formField(i18n.enterMatchData, lines: 15, required: false, controller: dataController),