fix: Config viewer not updating state
This commit is contained in:
parent
15d42a1fbd
commit
1991707be7
3 changed files with 39 additions and 42 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class InputBar extends StatelessWidget {
|
|||
final ValueChanged<Uint8List?>? onSubmitImage;
|
||||
final FocusNode? focusNode;
|
||||
final TextEditingController? controller;
|
||||
final InputDecoration? decoration;
|
||||
final InputDecoration decoration;
|
||||
final ValueChanged<String>? 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<String, String?> suggestion) =>
|
||||
|
|
|
|||
|
|
@ -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<ConfigViewer> createState() => _ConfigViewerState();
|
||||
}
|
||||
|
||||
class _ConfigViewerState extends State<ConfigViewer> {
|
||||
void _changeSetting(
|
||||
BuildContext context,
|
||||
AppSettings appSetting,
|
||||
SharedPreferences store,
|
||||
Function setState,
|
||||
String initialValue,
|
||||
) async {
|
||||
if (appSetting is AppSettings<bool>) {
|
||||
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<String>) {
|
||||
appSetting.setItem(store, value);
|
||||
await appSetting.setItem(store, value);
|
||||
}
|
||||
if (appSetting is AppSettings<int>) {
|
||||
appSetting.setItem(store, int.parse(value));
|
||||
await appSetting.setItem(store, int.parse(value));
|
||||
}
|
||||
if (appSetting is AppSettings<double>) {
|
||||
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<String>) {
|
||||
value = appSetting.getItem(store);
|
||||
}
|
||||
if (appSetting is AppSettings<int>) {
|
||||
value = appSetting.getItem(store).toString();
|
||||
}
|
||||
if (appSetting is AppSettings<bool>) {
|
||||
value = appSetting.getItem(store).toString();
|
||||
}
|
||||
if (appSetting is AppSettings<double>) {
|
||||
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<String>) {
|
||||
value = appSetting.getItem(store);
|
||||
}
|
||||
if (appSetting is AppSettings<int>) {
|
||||
value = appSetting.getItem(store).toString();
|
||||
}
|
||||
if (appSetting is AppSettings<bool>) {
|
||||
value = appSetting.getItem(store).toString();
|
||||
}
|
||||
if (appSetting is AppSettings<double>) {
|
||||
value = appSetting.getItem(store).toString();
|
||||
}
|
||||
return ListTile(
|
||||
title: Text(appSetting.name),
|
||||
subtitle: Text(value),
|
||||
onTap: () => _changeSetting(appSetting, store, value),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue