nc-photos/lib/widget/fancy_option_picker.dart
2021-08-02 14:47:18 +08:00

55 lines
1.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
class FancyOptionPickerItem {
FancyOptionPickerItem({
required this.label,
this.isSelected = false,
this.onSelect,
this.dense = false,
});
String label;
bool isSelected;
VoidCallback? onSelect;
bool dense;
}
/// A fancy looking dialog to pick an option
class FancyOptionPicker extends StatelessWidget {
FancyOptionPicker({
Key? key,
this.title,
required this.items,
}) : super(key: key);
@override
build(BuildContext context) {
return SimpleDialog(
title: title != null ? Text(title!) : null,
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,
),
onTap: e.isSelected ? null : e.onSelect,
dense: e.dense,
),
))
.toList(),
);
}
final String? title;
final List<FancyOptionPickerItem> items;
}