nc-photos/np_ui/lib/src/fancy_option_picker.dart

92 lines
2.1 KiB
Dart
Raw Normal View History

2021-07-10 21:25:23 +02:00
import 'package:flutter/material.dart';
2024-05-08 18:12:18 +02:00
import 'package:np_common/object_util.dart';
2021-07-10 21:25:23 +02:00
class FancyOptionPickerItem {
2023-06-06 15:39:58 +02:00
const 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
});
2023-06-06 15:39:58 +02:00
final String label;
final String? description;
final bool isSelected;
final VoidCallback? onSelect;
final VoidCallback? onUnselect;
final 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({
2024-05-08 18:12:18 +02:00
super.key,
2021-07-10 21:25:23 +02:00
this.title,
2021-07-23 22:05:57 +02:00
required this.items,
2024-05-08 18:12:18 +02:00
});
2021-07-10 21:25:23 +02:00
@override
2023-06-06 15:39:58 +02:00
Widget build(BuildContext context) {
2021-07-10 21:25:23 +02:00
return SimpleDialog(
title: title,
2021-07-10 21:25:23 +02:00
children: items
.map((e) => SimpleDialogOption(
2023-06-06 15:39:58 +02:00
child: FancyOptionPickerItemView(
label: e.label,
description: e.description,
isSelected: e.isSelected,
onSelect: e.onSelect,
onUnselect: e.onUnselect,
dense: e.dense,
2021-07-10 21:25:23 +02:00
),
))
.toList(),
);
}
final Widget? title;
2021-07-10 21:25:23 +02:00
final List<FancyOptionPickerItem> items;
}
2023-06-06 15:39:58 +02:00
class FancyOptionPickerItemView extends StatelessWidget {
const FancyOptionPickerItemView({
super.key,
required this.label,
this.description,
required this.isSelected,
this.onSelect,
this.onUnselect,
required this.dense,
});
@override
Widget build(BuildContext context) {
return ListTile(
leading: Icon(
isSelected ? Icons.check : null,
2024-05-16 18:37:33 +02:00
color: Theme.of(context).colorScheme.secondary,
2023-06-06 15:39:58 +02:00
),
title: Text(
label,
style: isSelected
? TextStyle(
2024-05-16 18:37:33 +02:00
color: Theme.of(context).colorScheme.secondary,
2023-06-06 15:39:58 +02:00
)
: null,
),
2024-05-08 18:12:18 +02:00
subtitle: description?.let(Text.new),
2023-06-06 15:39:58 +02:00
onTap: isSelected ? onUnselect : onSelect,
dense: dense,
);
}
final String label;
final String? description;
final bool isSelected;
final VoidCallback? onSelect;
final VoidCallback? onUnselect;
final bool dense;
}