aboutsummaryrefslogtreecommitdiff
path: root/lib/widgets/dialogs/selection_dialogs/common.dart
blob: fe34e4f976f7fc2193ac3d294eeadfc17a1e59ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import 'package:aves/theme/durations.dart';
import 'package:aves/widgets/dialogs/selection_dialogs/single_selection.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';

Future<void> showSelectionDialog<T>({
  required BuildContext context,
  required WidgetBuilder builder,
  required void Function(T value) onSelection,
}) async {
  final value = await showDialog<T>(
    context: context,
    builder: builder,
    routeSettings: const RouteSettings(name: AvesSingleSelectionDialog.routeName),
  );
  // wait for the dialog to hide
  await Future.delayed(ADurations.dialogTransitionLoose * timeDilation);
  if (value != null) {
    onSelection(value);
  }
}

typedef TextBuilder<T> = String? Function(T value);