2021-01-19 15:36:21 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'matrix.dart';
|
|
|
|
|
|
|
|
class SettingsSwitchListTile extends StatefulWidget {
|
|
|
|
final bool defaultValue;
|
|
|
|
final String storeKey;
|
|
|
|
final String title;
|
2022-01-29 11:35:03 +00:00
|
|
|
final Function(bool)? onChanged;
|
2021-01-19 15:36:21 +00:00
|
|
|
|
2021-11-27 09:10:29 +00:00
|
|
|
const SettingsSwitchListTile.adaptive({
|
2023-10-28 11:03:16 +00:00
|
|
|
super.key,
|
2021-01-19 15:36:21 +00:00
|
|
|
this.defaultValue = false,
|
2022-01-29 11:35:03 +00:00
|
|
|
required this.storeKey,
|
|
|
|
required this.title,
|
2021-01-19 15:36:21 +00:00
|
|
|
this.onChanged,
|
2023-10-28 11:03:16 +00:00
|
|
|
});
|
2021-01-19 15:36:21 +00:00
|
|
|
|
|
|
|
@override
|
2022-08-14 14:59:21 +00:00
|
|
|
SettingsSwitchListTileState createState() => SettingsSwitchListTileState();
|
2021-01-19 15:36:21 +00:00
|
|
|
}
|
|
|
|
|
2022-08-14 14:59:21 +00:00
|
|
|
class SettingsSwitchListTileState extends State<SettingsSwitchListTile> {
|
2021-01-19 15:36:21 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-11-01 17:00:10 +00:00
|
|
|
return SwitchListTile.adaptive(
|
|
|
|
value: Matrix.of(context).store.getBool(widget.storeKey) ??
|
|
|
|
widget.defaultValue,
|
|
|
|
title: Text(widget.title),
|
|
|
|
onChanged: (bool newValue) async {
|
|
|
|
widget.onChanged?.call(newValue);
|
|
|
|
await Matrix.of(context).store.setBool(widget.storeKey, newValue);
|
|
|
|
setState(() {});
|
|
|
|
},
|
2021-01-19 15:36:21 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|