Skip to content

Commit

Permalink
Fix trying to set text preview string during build
Browse files Browse the repository at this point in the history
  • Loading branch information
amake committed Jan 27, 2025
1 parent 735c1f5 commit 5bc6910
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/src/pages/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class _TextPreview extends StatefulWidget {

class _TextPreviewState extends State<_TextPreview> {
late final TextEditingController _controller;
InheritedPreferences get _prefs =>
Preferences.of(context, PrefsAspect.customization);

@override
void initState() {
Expand All @@ -74,8 +76,7 @@ class _TextPreviewState extends State<_TextPreview> {
void didChangeDependencies() {
super.didChangeDependencies();
if (!_inited) {
_controller.text =
Preferences.of(context, PrefsAspect.customization).textPreviewString;
_controller.text = _prefs.textPreviewString;
_inited = true;
}
}
Expand All @@ -86,9 +87,12 @@ class _TextPreviewState extends State<_TextPreview> {
super.dispose();
}

Future<void> _onTextChanged() async =>
await Preferences.of(context, PrefsAspect.customization)
.setTextPreviewString(_controller.text);
Future<void> _onTextChanged() async {
final current = _prefs.textPreviewString;
if (_controller.text != current) {
_prefs.setTextPreviewString(_controller.text);
}
}

@override
Widget build(BuildContext context) {
Expand Down

0 comments on commit 5bc6910

Please sign in to comment.