fix: Config viewer not updating state
This commit is contained in:
parent
15d42a1fbd
commit
1991707be7
3 changed files with 39 additions and 42 deletions
|
|
@ -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
Add a link
Reference in a new issue