From 1991707be725f946ff5801455be52dff5939408f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ku=C3=9Fowski?= Date: Wed, 25 Jun 2025 10:37:35 +0200 Subject: [PATCH] fix: Config viewer not updating state --- lib/pages/chat/chat_input_row.dart | 1 + lib/pages/chat/input_bar.dart | 8 ++-- lib/widgets/config_viewer.dart | 72 ++++++++++++++---------------- 3 files changed, 39 insertions(+), 42 deletions(-) diff --git a/lib/pages/chat/chat_input_row.dart b/lib/pages/chat/chat_input_row.dart index 7fa1ed941..6f79b4110 100644 --- a/lib/pages/chat/chat_input_row.dart +++ b/lib/pages/chat/chat_input_row.dart @@ -289,6 +289,7 @@ class ChatInputRow extends StatelessWidget { bottom: 6.0, top: 3.0, ), + counter: const SizedBox.shrink(), hintText: L10n.of(context).writeAMessage, hintMaxLines: 1, border: InputBorder.none, diff --git a/lib/pages/chat/input_bar.dart b/lib/pages/chat/input_bar.dart index 5ec4c98a9..91ed43642 100644 --- a/lib/pages/chat/input_bar.dart +++ b/lib/pages/chat/input_bar.dart @@ -23,7 +23,7 @@ class InputBar extends StatelessWidget { final ValueChanged? onSubmitImage; final FocusNode? focusNode; final TextEditingController? controller; - final InputDecoration? decoration; + final InputDecoration decoration; final ValueChanged? onChanged; final bool? autofocus; final bool readOnly; @@ -37,7 +37,7 @@ class InputBar extends StatelessWidget { this.onSubmitImage, this.focusNode, this.controller, - this.decoration, + required this.decoration, this.onChanged, this.autofocus, this.textInputAction, @@ -437,7 +437,8 @@ class InputBar extends StatelessWidget { // it sets the types for the callback incorrectly onSubmitted!(text); }, - decoration: decoration!, + maxLength: 16384, + decoration: decoration, onChanged: (text) { // fix for the library for now // it sets the types for the callback incorrectly @@ -445,6 +446,7 @@ class InputBar extends StatelessWidget { }, textCapitalization: TextCapitalization.sentences, ), + suggestionsCallback: getSuggestions, itemBuilder: (c, s) => buildSuggestion(c, s, Matrix.of(context).client), onSelected: (Map suggestion) => diff --git a/lib/widgets/config_viewer.dart b/lib/widgets/config_viewer.dart index 5026ec4cc..adfb34407 100644 --- a/lib/widgets/config_viewer.dart +++ b/lib/widgets/config_viewer.dart @@ -7,18 +7,22 @@ import 'package:fluffychat/config/setting_keys.dart'; import 'package:fluffychat/widgets/adaptive_dialogs/show_text_input_dialog.dart'; import 'package:fluffychat/widgets/matrix.dart'; -class ConfigViewer extends StatelessWidget { +class ConfigViewer extends StatefulWidget { const ConfigViewer({super.key}); + @override + State createState() => _ConfigViewerState(); +} + +class _ConfigViewerState extends State { void _changeSetting( - BuildContext context, AppSettings appSetting, SharedPreferences store, - Function setState, String initialValue, ) async { if (appSetting is AppSettings) { - appSetting.setItem(store, !(initialValue == 'true')); + await appSetting.setItem(store, !(initialValue == 'true')); + setState(() {}); return; } @@ -31,13 +35,13 @@ class ConfigViewer extends StatelessWidget { if (value == null) return; if (appSetting is AppSettings) { - appSetting.setItem(store, value); + await appSetting.setItem(store, value); } if (appSetting is AppSettings) { - appSetting.setItem(store, int.parse(value)); + await appSetting.setItem(store, int.parse(value)); } if (appSetting is AppSettings) { - appSetting.setItem(store, double.parse(value)); + await appSetting.setItem(store, double.parse(value)); } setState(() {}); @@ -67,38 +71,28 @@ class ConfigViewer extends StatelessWidget { ), ), Expanded( - child: StatefulBuilder( - builder: (context, setState) { - return ListView.builder( - itemCount: AppSettings.values.length, - itemBuilder: (context, i) { - final store = Matrix.of(context).store; - final appSetting = AppSettings.values[i]; - var value = ''; - if (appSetting is AppSettings) { - value = appSetting.getItem(store); - } - if (appSetting is AppSettings) { - value = appSetting.getItem(store).toString(); - } - if (appSetting is AppSettings) { - value = appSetting.getItem(store).toString(); - } - if (appSetting is AppSettings) { - value = appSetting.getItem(store).toString(); - } - return ListTile( - title: Text(appSetting.name), - subtitle: Text(value), - onTap: () => _changeSetting( - context, - appSetting, - store, - setState, - value, - ), - ); - }, + child: ListView.builder( + itemCount: AppSettings.values.length, + itemBuilder: (context, i) { + final store = Matrix.of(context).store; + final appSetting = AppSettings.values[i]; + var value = ''; + if (appSetting is AppSettings) { + value = appSetting.getItem(store); + } + if (appSetting is AppSettings) { + value = appSetting.getItem(store).toString(); + } + if (appSetting is AppSettings) { + value = appSetting.getItem(store).toString(); + } + if (appSetting is AppSettings) { + value = appSetting.getItem(store).toString(); + } + return ListTile( + title: Text(appSetting.name), + subtitle: Text(value), + onTap: () => _changeSetting(appSetting, store, value), ); }, ),