mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-02-09 03:34:10 +01:00
fix: Persistent settings
This commit is contained in:
parent
d273b2ad84
commit
03b00b7d26
41
lib/components/settings_switch_list_tile.dart
Normal file
41
lib/components/settings_switch_list_tile.dart
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'matrix.dart';
|
||||||
|
|
||||||
|
class SettingsSwitchListTile extends StatefulWidget {
|
||||||
|
final bool defaultValue;
|
||||||
|
final String storeKey;
|
||||||
|
final String title;
|
||||||
|
final Function(bool) onChanged;
|
||||||
|
|
||||||
|
const SettingsSwitchListTile({
|
||||||
|
Key key,
|
||||||
|
this.defaultValue = false,
|
||||||
|
@required this.storeKey,
|
||||||
|
@required this.title,
|
||||||
|
this.onChanged,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_SettingsSwitchListTileState createState() => _SettingsSwitchListTileState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SettingsSwitchListTileState extends State<SettingsSwitchListTile> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return FutureBuilder<bool>(
|
||||||
|
future: Matrix.of(context).store.getItemBool(widget.storeKey),
|
||||||
|
builder: (context, snapshot) => SwitchListTile(
|
||||||
|
value: snapshot.data ?? widget.defaultValue,
|
||||||
|
title: Text(widget.title),
|
||||||
|
onChanged: (bool newValue) async {
|
||||||
|
widget.onChanged?.call(newValue);
|
||||||
|
await Matrix.of(context)
|
||||||
|
.store
|
||||||
|
.setItem(widget.storeKey, newValue.toString());
|
||||||
|
setState(() => null);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ import 'package:adaptive_dialog/adaptive_dialog.dart';
|
|||||||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||||
import 'package:fluffychat/components/dialogs/bootstrap_dialog.dart';
|
import 'package:fluffychat/components/dialogs/bootstrap_dialog.dart';
|
||||||
import 'package:fluffychat/components/sentry_switch_list_tile.dart';
|
import 'package:fluffychat/components/sentry_switch_list_tile.dart';
|
||||||
|
import 'package:fluffychat/components/settings_switch_list_tile.dart';
|
||||||
import 'package:flushbar/flushbar_helper.dart';
|
import 'package:flushbar/flushbar_helper.dart';
|
||||||
import 'package:famedlysdk/famedlysdk.dart';
|
import 'package:famedlysdk/famedlysdk.dart';
|
||||||
import 'package:file_picker_cross/file_picker_cross.dart';
|
import 'package:file_picker_cross/file_picker_cross.dart';
|
||||||
@ -382,36 +383,23 @@ class _SettingsState extends State<Settings> {
|
|||||||
AdaptivePageLayout.of(context).pushNamed('/settings/style'),
|
AdaptivePageLayout.of(context).pushNamed('/settings/style'),
|
||||||
trailing: Icon(Icons.style_outlined),
|
trailing: Icon(Icons.style_outlined),
|
||||||
),
|
),
|
||||||
SwitchListTile(
|
SettingsSwitchListTile(
|
||||||
title: Text(L10n.of(context).renderRichContent),
|
title: L10n.of(context).renderRichContent,
|
||||||
value: AppConfig.renderHtml,
|
onChanged: (b) => AppConfig.renderHtml = b,
|
||||||
onChanged: (bool newValue) async {
|
storeKey: SettingKeys.renderHtml,
|
||||||
AppConfig.renderHtml = newValue;
|
defaultValue: AppConfig.renderHtml,
|
||||||
await Matrix.of(context)
|
|
||||||
.store
|
|
||||||
.setItem(SettingKeys.renderHtml, newValue.toString());
|
|
||||||
setState(() => null);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
SwitchListTile(
|
SettingsSwitchListTile(
|
||||||
title: Text(L10n.of(context).hideRedactedEvents),
|
title: L10n.of(context).hideRedactedEvents,
|
||||||
value: AppConfig.hideRedactedEvents,
|
onChanged: (b) => AppConfig.hideRedactedEvents = b,
|
||||||
onChanged: (bool newValue) async {
|
storeKey: SettingKeys.hideRedactedEvents,
|
||||||
AppConfig.hideRedactedEvents = newValue;
|
defaultValue: AppConfig.hideRedactedEvents,
|
||||||
await Matrix.of(context).store.setItem(
|
|
||||||
SettingKeys.hideRedactedEvents, newValue.toString());
|
|
||||||
setState(() => null);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
SwitchListTile(
|
SettingsSwitchListTile(
|
||||||
title: Text(L10n.of(context).hideUnknownEvents),
|
title: L10n.of(context).hideUnknownEvents,
|
||||||
value: AppConfig.hideUnknownEvents,
|
onChanged: (b) => AppConfig.hideUnknownEvents = b,
|
||||||
onChanged: (bool newValue) async {
|
storeKey: SettingKeys.hideUnknownEvents,
|
||||||
AppConfig.hideUnknownEvents = newValue;
|
defaultValue: AppConfig.hideUnknownEvents,
|
||||||
await Matrix.of(context).store.setItem(
|
|
||||||
SettingKeys.hideUnknownEvents, newValue.toString());
|
|
||||||
setState(() => null);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10n.of(context).emoteSettings),
|
title: Text(L10n.of(context).emoteSettings),
|
||||||
|
Loading…
Reference in New Issue
Block a user