Skip to content

Commit

Permalink
fix: input box bug in settings (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaoMint authored Feb 18, 2024
1 parent 300346b commit 6d742be
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lib/views/pages/extension/extension_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class _ExtensionSettingsPageState extends State<ExtensionSettingsPage> {
setState(() {});
}
},
text: setting.value ?? setting.defaultValue,
buildText: () {
return setting.value ?? setting.defaultValue;
},
buildSubtitle: () {
if (Platform.isAndroid) {
return '${setting.value ?? setting.defaultValue}\n${setting.description ?? ''}';
Expand Down
16 changes: 12 additions & 4 deletions lib/views/pages/settings/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class _SettingsPageState extends State<SettingsPage> {
defaultLanguage: MiruStorage.getSetting(SettingKey.language),
);
},
text: MiruStorage.getSetting(SettingKey.tmdbKey),
buildText: () {
return MiruStorage.getSetting(SettingKey.tmdbKey);
},
),
// 语言设置
SettingsRadiosTile(
Expand Down Expand Up @@ -179,7 +181,9 @@ class _SettingsPageState extends State<SettingsPage> {
MiruStorage.setSetting(SettingKey.miruRepoUrl, value);
Get.find<ExtensionRepoPageController>().onRefresh();
},
text: MiruStorage.getSetting(SettingKey.miruRepoUrl),
buildText: () {
return MiruStorage.getSetting(SettingKey.miruRepoUrl);
},
),
const SizedBox(height: 8),
],
Expand Down Expand Up @@ -422,7 +426,9 @@ class _SettingsPageState extends State<SettingsPage> {
onChanged: (value) {
MiruStorage.setUASetting(value);
},
text: MiruStorage.getUASetting(),
buildText: () {
return MiruStorage.getUASetting();
},
),
SettingsRadiosTile(
title: 'settings.proxy-type'.i18n,
Expand All @@ -449,7 +455,9 @@ class _SettingsPageState extends State<SettingsPage> {
MiruStorage.setSetting(SettingKey.proxy, value);
MiruRequest.refreshProxy();
},
text: MiruStorage.getSetting(SettingKey.proxy),
buildText: () {
return MiruStorage.getSetting(SettingKey.proxy);
},
),
],
),
Expand Down
22 changes: 18 additions & 4 deletions lib/views/widgets/settings/settings_input_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ 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,
});
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;
Expand All @@ -28,6 +28,20 @@ class SettingsIntpuTile extends fluent.StatefulWidget {
}

class _SettingsIntpuTileState extends fluent.State<SettingsIntpuTile> {
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,
Expand All @@ -41,7 +55,7 @@ class _SettingsIntpuTileState extends fluent.State<SettingsIntpuTile> {
return AlertDialog(
title: Text(widget.title),
content: TextField(
controller: TextEditingController(text: widget.text),
controller: _controller,
onChanged: (value) {
widget.onChanged(value);
setState(() {});
Expand Down Expand Up @@ -70,7 +84,7 @@ class _SettingsIntpuTileState extends fluent.State<SettingsIntpuTile> {
buildSubtitle: widget.buildSubtitle,
trailing: Expanded(
child: fluent.TextBox(
controller: TextEditingController(text: widget.text),
controller: _controller,
onChanged: (value) {
widget.onChanged(value);
},
Expand Down

0 comments on commit 6d742be

Please sign in to comment.