showAlertDeviceSelection function

dynamic showAlertDeviceSelection({
  1. required List data,
  2. required TypeDeviceSelection type,
  3. required DeviceSelectionResult deviceSelectionResult,
  4. required BuildContext context,
})

Implementation

showAlertDeviceSelection({
  required List<dynamic> data,
  required final TypeDeviceSelection type,
  required DeviceSelectionResult deviceSelectionResult,
  required BuildContext context,
}) async {
  dynamic chosenValue;
  await showDialog(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        title: Text("Select ${type.name.toString()}"),
        content: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
          SingleChildScrollView(
              scrollDirection: Axis.horizontal,
              child: DropdownButton<dynamic>(
                hint: Text('Select one option'),
                underline: Container(),
                items: data.map((e) {
                  dynamic value = "";
                  String key = "";
                  switch (type) {
                    case TypeDeviceSelection.monitor:
                      value = e.MonitorHandle.toString();
                      key = e.MonitorName;
                      break;
                    case TypeDeviceSelection.soundcard:
                      value = e.DeviceID;
                      key = e.Name;
                      break;
                    case TypeDeviceSelection.bitrate:
                      value = e;
                      key = '${e / 1000} mps';
                      break;
                    case TypeDeviceSelection.framerate:
                      value = e;
                      key = '$e fps';
                      break;
                    default:
                  }
                  return DropdownMenuItem<dynamic>(
                    value: value,
                    child: Text(
                      key,
                    ),
                  );
                }).toList(),
                onChanged: (dynamic value) {
                  chosenValue = value;
                  Navigator.of(context).pop();
                },
              )),
        ]),
      );
    },
  );
  return chosenValue;
}