extract SettingsDropdownTile for settings dropdowns

This commit is contained in:
2026-07-12 23:42:56 +02:00
parent 4aa31a2e44
commit 9994a1f3fa
3 changed files with 87 additions and 77 deletions
@@ -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);
},
),
);
}
}