From 6d742bec5aebe810d456f2fc2606e817d9ea9113 Mon Sep 17 00:00:00 2001 From: MiaoMint <44718819+MiaoMint@users.noreply.github.com> Date: Mon, 19 Feb 2024 01:21:42 +0800 Subject: [PATCH] fix: input box bug in settings (#229) --- .../extension/extension_settings_page.dart | 4 +++- lib/views/pages/settings/settings_page.dart | 16 ++++++++++---- .../widgets/settings/settings_input_tile.dart | 22 +++++++++++++++---- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/lib/views/pages/extension/extension_settings_page.dart b/lib/views/pages/extension/extension_settings_page.dart index 680cfd50..14ca5a09 100644 --- a/lib/views/pages/extension/extension_settings_page.dart +++ b/lib/views/pages/extension/extension_settings_page.dart @@ -72,7 +72,9 @@ class _ExtensionSettingsPageState extends State { setState(() {}); } }, - text: setting.value ?? setting.defaultValue, + buildText: () { + return setting.value ?? setting.defaultValue; + }, buildSubtitle: () { if (Platform.isAndroid) { return '${setting.value ?? setting.defaultValue}\n${setting.description ?? ''}'; diff --git a/lib/views/pages/settings/settings_page.dart b/lib/views/pages/settings/settings_page.dart index a4647239..9df467ff 100644 --- a/lib/views/pages/settings/settings_page.dart +++ b/lib/views/pages/settings/settings_page.dart @@ -84,7 +84,9 @@ class _SettingsPageState extends State { defaultLanguage: MiruStorage.getSetting(SettingKey.language), ); }, - text: MiruStorage.getSetting(SettingKey.tmdbKey), + buildText: () { + return MiruStorage.getSetting(SettingKey.tmdbKey); + }, ), // 语言设置 SettingsRadiosTile( @@ -179,7 +181,9 @@ class _SettingsPageState extends State { MiruStorage.setSetting(SettingKey.miruRepoUrl, value); Get.find().onRefresh(); }, - text: MiruStorage.getSetting(SettingKey.miruRepoUrl), + buildText: () { + return MiruStorage.getSetting(SettingKey.miruRepoUrl); + }, ), const SizedBox(height: 8), ], @@ -422,7 +426,9 @@ class _SettingsPageState extends State { onChanged: (value) { MiruStorage.setUASetting(value); }, - text: MiruStorage.getUASetting(), + buildText: () { + return MiruStorage.getUASetting(); + }, ), SettingsRadiosTile( title: 'settings.proxy-type'.i18n, @@ -449,7 +455,9 @@ class _SettingsPageState extends State { MiruStorage.setSetting(SettingKey.proxy, value); MiruRequest.refreshProxy(); }, - text: MiruStorage.getSetting(SettingKey.proxy), + buildText: () { + return MiruStorage.getSetting(SettingKey.proxy); + }, ), ], ), diff --git a/lib/views/widgets/settings/settings_input_tile.dart b/lib/views/widgets/settings/settings_input_tile.dart index aa1b8639..edc6dd0d 100644 --- a/lib/views/widgets/settings/settings_input_tile.dart +++ b/lib/views/widgets/settings/settings_input_tile.dart @@ -10,7 +10,7 @@ class SettingsIntpuTile extends fluent.StatefulWidget { this.icon, required this.title, required this.onChanged, - required this.text, + required this.buildText, required this.buildSubtitle, this.trailing = const Icon(Icons.chevron_right), this.isCard = false, @@ -18,7 +18,7 @@ class SettingsIntpuTile extends fluent.StatefulWidget { final Widget? icon; final String title; final String Function() buildSubtitle; - final String text; + final String Function() buildText; final Widget trailing; final Function(String) onChanged; final bool isCard; @@ -28,6 +28,20 @@ class SettingsIntpuTile extends fluent.StatefulWidget { } class _SettingsIntpuTileState extends fluent.State { + TextEditingController? _controller; + + @override + void initState() { + super.initState(); + _controller = TextEditingController(text: widget.buildText()); + } + + @override + void dispose() { + _controller?.dispose(); + super.dispose(); + } + Widget _buildAndroid(BuildContext context) { return ListTile( leading: widget.icon, @@ -41,7 +55,7 @@ class _SettingsIntpuTileState extends fluent.State { return AlertDialog( title: Text(widget.title), content: TextField( - controller: TextEditingController(text: widget.text), + controller: _controller, onChanged: (value) { widget.onChanged(value); setState(() {}); @@ -70,7 +84,7 @@ class _SettingsIntpuTileState extends fluent.State { buildSubtitle: widget.buildSubtitle, trailing: Expanded( child: fluent.TextBox( - controller: TextEditingController(text: widget.text), + controller: _controller, onChanged: (value) { widget.onChanged(value); },