showItemPicker<T> function

Future<T?> showItemPicker<T>(
  1. BuildContext context, {
  2. required ItemChildDelegate<T> items,
  3. required ItemPickerBuilder<T> builder,
  4. T? initialValue,
  5. ItemPickerLayout layout = const GridItemPickerLayout(),
  6. AlignmentGeometry? alignment,
  7. AlignmentGeometry? anchorAlignment,
  8. BoxConstraints? constraints,
  9. Offset? offset,
})

Implementation

Future<T?> showItemPicker<T>(
  BuildContext context, {
  required ItemChildDelegate<T> items,
  required ItemPickerBuilder<T> builder,
  T? initialValue,
  ItemPickerLayout layout = const GridItemPickerLayout(),
  AlignmentGeometry? alignment,
  AlignmentGeometry? anchorAlignment,
  BoxConstraints? constraints,
  Offset? offset,
}) {
  final theme = Theme.of(context);
  return showPopover<T>(
    context: context,
    alignment: alignment ?? AlignmentDirectional.topStart,
    anchorAlignment: anchorAlignment ?? AlignmentDirectional.bottomStart,
    offset: offset ?? Offset(0, 8.0 * theme.scaling),
    builder: (context) {
      final theme = Theme.of(context);
      final mediaQuery = MediaQuery.of(context);
      return SurfaceCard(
        padding: EdgeInsets.zero,
        child: ConstrainedBox(
          constraints: constraints ??
              BoxConstraints(
                maxWidth: 320 * theme.scaling,
                maxHeight: 320 * theme.scaling,
              ),
          child: MediaQuery(
            data: mediaQuery.copyWith(
                padding:
                    mediaQuery.padding + EdgeInsets.all(8.0 * theme.scaling)),
            child: ItemPickerDialog<T>(
              items: items,
              builder: builder,
              value: initialValue,
              layout: layout,
              onChanged: (value) {
                closeOverlay<T>(context, value);
              },
            ),
          ),
        ),
      );
    },
  ).future;
}