Files
Client/lib/view/pages/settings/widgets/settings_dropdown_tile.dart
T

75 lines
1.9 KiB
Dart

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),
alignment: AlignmentDirectional.centerEnd,
selectedItemBuilder: (context) => options
.map(
(e) => Align(
alignment: AlignmentDirectional.centerEnd,
child: _optionRow(e),
),
)
.toList(),
items: options
.map(
(e) => DropdownMenuItem<T>(
value: e,
enabled: e != value,
child: _optionRow(e),
),
)
.toList(),
onChanged: (e) {
if (e != null) onChanged(e);
},
),
);
}
Widget _optionRow(T e) => Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(optionIcon(e)),
const SizedBox(width: 10),
Flexible(
child: Text(
optionLabel(e),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
);
}