open<T> static method

Future<T?> open<T>(
  1. T? initialValue, {
  2. Widget? title,
  3. required List<TdPickerItem<T>> options,
})

Implementation

static Future<T?> open<T>(
  T? initialValue, {
  Widget? title,
  required List<TdPickerItem<T>> options,
}) {
  final completer = Completer<T>();

  T? value = initialValue;

  TdPopupPlugin.open(
    builder: (context) {
      return Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          TdPopupAppbar(
            title: title,
            confirm: const Text('确定'),
            onConfirm: () {
              TdPopupPlugin.pop();

              completer.complete(value);
            },
            cancel: const Text('取消'),
            onCancel: () {
              TdPopupPlugin.pop();

              completer.complete();
            },
          ),
          TdPicker<T>(
            onChanged: (newValue) {
              value = newValue;
            },
            initialValue: initialValue,
            children: options,
          ),
        ],
      );
    },
  );

  return completer.future;
}