nc-photos/app/lib/widget/fancy_option_picker.dart

60 lines
1.5 KiB
Dart
Raw Normal View History

2021-07-10 21:25:23 +02:00
import 'package:flutter/material.dart';
class FancyOptionPickerItem {
FancyOptionPickerItem({
2021-07-23 22:05:57 +02:00
required this.label,
2021-08-28 22:58:10 +02:00
this.description,
2021-07-10 21:25:23 +02:00
this.isSelected = false,
this.onSelect,
2022-01-29 14:10:48 +01:00
this.onUnselect,
this.dense = false,
2021-07-10 21:25:23 +02:00
});
String label;
2021-08-28 22:58:10 +02:00
String? description;
2021-07-10 21:25:23 +02:00
bool isSelected;
2021-07-23 22:05:57 +02:00
VoidCallback? onSelect;
2022-01-29 14:10:48 +01:00
VoidCallback? onUnselect;
bool dense;
2021-07-10 21:25:23 +02:00
}
/// A fancy looking dialog to pick an option
class FancyOptionPicker extends StatelessWidget {
2021-09-15 08:58:06 +02:00
const FancyOptionPicker({
2021-07-23 22:05:57 +02:00
Key? key,
2021-07-10 21:25:23 +02:00
this.title,
2021-07-23 22:05:57 +02:00
required this.items,
2021-07-10 21:25:23 +02:00
}) : super(key: key);
@override
build(BuildContext context) {
return SimpleDialog(
2021-07-23 22:05:57 +02:00
title: title != null ? Text(title!) : null,
2021-07-10 21:25:23 +02:00
children: items
.map((e) => SimpleDialogOption(
child: ListTile(
leading: Icon(
e.isSelected ? Icons.check : null,
color: Theme.of(context).colorScheme.primary,
),
title: Text(
e.label,
style: e.isSelected
? TextStyle(
color: Theme.of(context).colorScheme.primary,
)
: null,
),
2021-08-28 22:58:10 +02:00
subtitle: e.description == null ? null : Text(e.description!),
2022-01-29 14:10:48 +01:00
onTap: e.isSelected ? e.onUnselect : e.onSelect,
dense: e.dense,
2021-07-10 21:25:23 +02:00
),
))
.toList(),
);
}
2021-07-23 22:05:57 +02:00
final String? title;
2021-07-10 21:25:23 +02:00
final List<FancyOptionPickerItem> items;
}