dlgChoose method

Future<int> dlgChoose({
  1. required String title,
  2. required List<String> options,
})

Shows a popup dialog with a list of options returning the index selected or -1 if canceled.

Implementation

Future<int> dlgChoose({
  required String title,
  required List<String> options,
}) async {
  // Form up our dropdown options
  final dropdownItems = <DropdownMenuEntry<int>>[];
  for (final (index, option) in options.indexed) {
    dropdownItems.add(DropdownMenuEntry(label: option, value: index));
  }
  int? answer = 0;
  return (await dlgCustom<int?>(
        actions: [
          _buildButton<int>("OK", answer),
        ],
        content: uiComboBox(
          dropdownMenuEntries: dropdownItems,
          enableFilter: false,
          enableSearch: false,
          initialSelection: 0,
          onSelected: (v) => answer = v,
          style: DropdownMenuThemeData(
            inputDecorationTheme: InputDecorationTheme(
              isDense: true,
              iconColor: _getTheme().contentColor,
              suffixIconColor: _getTheme().contentColor,
              focusedBorder: UnderlineInputBorder(
                borderSide: BorderSide(color: _getTheme().contentColor!),
              ),
              enabledBorder: UnderlineInputBorder(
                borderSide: BorderSide(color: _getTheme().contentColor!),
              ),
              border: UnderlineInputBorder(
                borderSide: BorderSide(color: _getTheme().contentColor!),
              ),
            ),
            menuStyle: const MenuStyle(
              padding: WidgetStatePropertyAll(EdgeInsets.zero),
              visualDensity: VisualDensity.compact,
            ),
            textStyle: TextStyle(
              color: _getTheme().contentColor,
              decorationColor: _getTheme().contentColor,
            ),
          ),
          width: 200,
        ),
        title: title,
      )) ??
      -1;
}