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

92 lines
2.2 KiB
Dart
Raw Normal View History

2021-07-10 21:25:23 +02:00
import 'package:flutter/material.dart';
2023-06-06 15:39:58 +02:00
import 'package:nc_photos/object_extension.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({
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
2023-06-06 15:39:58 +02:00
Widget build(BuildContext context) {
2021-07-10 21:25:23 +02:00
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(
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(),
);
}
2021-07-23 22:05:57 +02:00
final String? 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,
color: Theme.of(context).colorScheme.primary,
),
title: Text(
label,
style: isSelected
? TextStyle(
color: Theme.of(context).colorScheme.primary,
)
: null,
),
subtitle: description?.run(Text.new),
onTap: isSelected ? onUnselect : onSelect,
dense: dense,
);
}
final String label;
final String? description;
final bool isSelected;
final VoidCallback? onSelect;
final VoidCallback? onUnselect;
final bool dense;
}