extract SettingsDropdownTile for settings dropdowns
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Settings row with a trailing [DropdownButton]. Each option renders as an
|
||||
/// icon + label row; the currently selected option is disabled in the menu,
|
||||
/// matching the settings styling. [onChanged] receives the picked (non-null)
|
||||
/// value.
|
||||
class SettingsDropdownTile<T> extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final T value;
|
||||
final List<T> options;
|
||||
final IconData Function(T) optionIcon;
|
||||
final String Function(T) optionLabel;
|
||||
final ValueChanged<T> onChanged;
|
||||
|
||||
const SettingsDropdownTile({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.value,
|
||||
required this.options,
|
||||
required this.optionIcon,
|
||||
required this.optionLabel,
|
||||
required this.onChanged,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: Icon(icon),
|
||||
title: Text(title),
|
||||
trailing: DropdownButton<T>(
|
||||
value: value,
|
||||
icon: const Icon(Icons.arrow_drop_down),
|
||||
items: options
|
||||
.map(
|
||||
(e) => DropdownMenuItem<T>(
|
||||
value: e,
|
||||
enabled: e != value,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(optionIcon(e)),
|
||||
const SizedBox(width: 10),
|
||||
Text(optionLabel(e)),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
onChanged: (e) {
|
||||
if (e != null) onChanged(e);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user