Files
tatuchat/lib/widgets/settings_switch_list_tile.dart
Welton Moura 0037b0b9cf
Some checks failed
Main Deploy Workflow / deploy_web (push) Has been cancelled
Main Deploy Workflow / deploy_playstore_internal (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled
Initial commit
2026-09-11 15:59:56 -03:00

45 lines
1.3 KiB
Dart

// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
//
// SPDX-License-Identifier: AGPL-3.0-or-later
import 'package:tatchat/config/setting_keys.dart';
import 'package:material_ui/material_ui.dart';
class SettingsSwitchListTile extends StatefulWidget {
final AppSettings<bool?> setting;
final String title;
final String? subtitle;
final Function(bool)? onChanged;
final bool? defaultValue;
const SettingsSwitchListTile.adaptive({
super.key,
required this.setting,
required this.title,
this.subtitle,
this.onChanged,
this.defaultValue,
});
@override
SettingsSwitchListTileState createState() => SettingsSwitchListTileState();
}
class SettingsSwitchListTileState extends State<SettingsSwitchListTile> {
@override
Widget build(BuildContext context) {
final subtitle = widget.subtitle;
return SwitchListTile.adaptive(
value: widget.setting.value ?? widget.defaultValue ?? false,
title: Text(widget.title),
subtitle: subtitle == null ? null : Text(subtitle),
onChanged: (bool newValue) async {
widget.onChanged?.call(newValue);
await widget.setting.setItem(newValue);
setState(() {});
},
);
}
}