extract SettingsCheckboxTile for settings toggles
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../utils/haptics.dart';
|
||||
import '../../../../widget/centered_leading.dart';
|
||||
|
||||
/// Settings row with a trailing checkbox. Fires [Haptics.selection] before
|
||||
/// invoking [onChanged] (with the resolved non-null value), so the sections
|
||||
/// don't repeat that. The leading icon is vertically centered when a [subtitle]
|
||||
/// is present, matching the surrounding settings styling.
|
||||
class SettingsCheckboxTile extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
final bool value;
|
||||
final ValueChanged<bool> onChanged;
|
||||
|
||||
const SettingsCheckboxTile({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.value,
|
||||
required this.onChanged,
|
||||
this.subtitle,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final leadingIcon = Icon(icon);
|
||||
return ListTile(
|
||||
leading: subtitle == null ? leadingIcon : CenteredLeading(leadingIcon),
|
||||
title: Text(title),
|
||||
subtitle: subtitle == null ? null : Text(subtitle!),
|
||||
trailing: Checkbox(
|
||||
value: value,
|
||||
onChanged: (e) {
|
||||
Haptics.selection();
|
||||
onChanged(e ?? false);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user