2021-01-19 16:36:21 +01:00
|
|
|
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;
|
|
|
|
|
2021-11-27 10:10:29 +01:00
|
|
|
const SettingsSwitchListTile.adaptive({
|
2021-01-19 16:36:21 +01:00
|
|
|
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>(
|
2021-08-07 19:36:42 +02:00
|
|
|
future: Matrix.of(context)
|
|
|
|
.store
|
|
|
|
.getItemBool(widget.storeKey, widget.defaultValue),
|
2021-11-27 10:10:29 +01:00
|
|
|
builder: (context, snapshot) => SwitchListTile.adaptive(
|
2021-01-19 16:36:21 +01:00
|
|
|
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);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|