showSmoothListOfChoicesModalSheet<T> function
- required BuildContext context,
- required String title,
- required Iterable<
String> labels, - required Iterable<
T> values, - bool dynamicSize = false,
- Iterable<
String> ? subtitles, - bool addEndArrowToItems = false,
- Widget? header,
- Iterable<
Widget> ? prefixIcons, - Color? prefixIconTint,
- Iterable<
Widget> ? suffixIcons, - Color? suffixIconTint,
- EdgeInsetsGeometry? padding,
- EdgeInsetsGeometry? contentPadding,
- EdgeInsetsGeometry? dividerPadding,
- TextStyle? textStyle,
- Color? headerBackgroundColor,
- Color? prefixIndicatorColor,
- SmoothModalSheetType type = SmoothModalSheetType.info,
A modal sheet with a limited list (no scroll)
Implementation
Future<T?> showSmoothListOfChoicesModalSheet<T>({
required BuildContext context,
required String title,
required Iterable<String> labels,
required Iterable<T> values,
// If the size may change once the modal is shown
bool dynamicSize = false,
Iterable<String>? subtitles,
bool addEndArrowToItems = false,
Widget? header,
Widget? footer,
Iterable<Widget>? prefixIcons,
Color? prefixIconTint,
Iterable<Widget>? suffixIcons,
Color? suffixIconTint,
EdgeInsetsGeometry? padding,
EdgeInsetsGeometry? contentPadding,
EdgeInsetsGeometry? dividerPadding,
TextStyle? textStyle,
Color? headerBackgroundColor,
Color? footerBackgroundColor,
Color? prefixIndicatorColor,
double footerSpace = 0.0,
SmoothModalSheetType type = SmoothModalSheetType.info,
bool? useRootNavigator,
}) {
assert(labels.length == values.length);
assert(prefixIcons == null || values.length == prefixIcons.length);
assert(suffixIcons == null || values.length == suffixIcons.length);
assert(prefixIconTint == null || prefixIcons != null);
assert(suffixIconTint == null || suffixIcons != null);
final List<Widget> items = <Widget>[];
if (header != null) {
items.add(header);
}
for (int i = 0; i < labels.length; i++) {
items.add(
Builder(
builder: (BuildContext context) {
return ListTile(
leading: prefixIcons != null
? IconTheme.merge(
data: IconThemeData(color: prefixIconTint),
child: prefixIcons.elementAt(i),
)
: null,
title: Text(
labels.elementAt(i),
style:
textStyle ??
TextStyle(
fontWeight: subtitles != null
? FontWeight.bold
: FontWeight.w500,
),
),
subtitle: subtitles != null ? Text(subtitles.elementAt(i)) : null,
contentPadding:
contentPadding ??
EdgeInsetsDirectional.only(
start: LARGE_SPACE,
end: addEndArrowToItems ? 16.25 : LARGE_SPACE,
),
trailing: (suffixIcons != null
? IconTheme.merge(
data: IconThemeData(color: suffixIconTint),
child: suffixIcons.elementAt(i),
)
: (addEndArrowToItems
? const _SmoothListOfChoicesEndArrow()
: null)),
onTap: () => Navigator.of(context).pop(values.elementAt(i)),
);
},
),
);
if (i < labels.length - 1) {
const Widget divider = Divider(height: 1.0);
if (dividerPadding != null) {
items.add(Padding(padding: dividerPadding, child: divider));
} else {
items.add(divider);
}
}
}
if (footer != null) {
if (footerSpace > 0.0) {
items.add(SizedBox(height: footerSpace));
}
Widget footerChild = footer;
if (footerBackgroundColor != null) {
footerChild = ColoredBox(
color: footerBackgroundColor,
child: footerChild,
);
}
items.add(footerChild);
}
if (dynamicSize) {
return showSmoothModalSheet<T>(
context: context,
useRootNavigator: useRootNavigator ?? false,
builder: (_) => SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SmoothModalSheetHeader(
title: title,
prefix: SmoothModalSheetHeaderPrefixIndicator(
color: prefixIndicatorColor,
),
backgroundColor: headerBackgroundColor,
type: type,
),
...items,
],
),
),
);
}
return showSmoothAutoSizeModalSheet<T>(
context: context,
useRootNavigator: useRootNavigator ?? false,
useSafeArea: false,
header: SmoothModalSheetHeader(
title: title,
prefix: SmoothModalSheetHeaderPrefixIndicator(
color: prefixIndicatorColor,
),
backgroundColor: headerBackgroundColor,
type: type,
),
bodyBuilder: (_) => SafeArea(
child: Column(mainAxisSize: MainAxisSize.min, children: items),
),
);
}