chooser<T> static method

Future<T?> chooser<T>(
  1. BuildContext context, {
  2. String title = "Choose",
  3. String? content,
  4. bool barrierDismisable = true,
  5. required List<PopupWidgetOptions<T>> data,
  6. required dynamic onSelected(
    1. String text,
    2. T? value
    ),
  7. Color color = Colors.blue,
})

Implementation

static Future<T?> chooser<T>(
  BuildContext context, {
  String title = "Choose",
  String? content,
  bool barrierDismisable = true,
  required List<PopupWidgetOptions<T>> data,
  required Function(String text, T? value) onSelected,
  Color color = Colors.blue,
}) async {
  var size = MediaQuery.of(context).size;
  var dialog = Dialog(
    backgroundColor: Colors.white,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(10),
    ),
    child: Container(
      width: _isLargeDevice(size) ? 350 : size.width - 40,
      constraints: BoxConstraints(
        maxHeight: size.height - 80,
      ),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(10),
        color: Colors.white,
      ),
      child: SingleChildScrollView(
        child: Container(
          padding: const EdgeInsets.symmetric(horizontal: 20),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              const SizedBox(height: 10),
              Text(
                title,
                style: Theme.of(context).textTheme.bodyText1!.copyWith(
                      fontWeight: FontWeight.bold,
                    ),
              ),
              if (content != null) const Divider(),
              if (content != null) Text(content),
              const Divider(),
              ...data.map((e) {
                return Container(
                  padding: const EdgeInsets.only(bottom: 10),
                  width: double.infinity,
                  child: ButtonWidget(
                    onPressed: () {
                      onSelected(e.text, e.value);
                    },
                    text: e.text,
                    background: Colors.white,
                    radius: 10,
                    textStyle: Theme.of(context)
                        .textTheme
                        .bodyText1!
                        .copyWith(color: color),
                    borderColor: color,
                  ),
                );
              }).toList(),
              const SizedBox(height: 10),
            ],
          ),
        ),
      ),
    ),
  );
  return showDialog(
      context: context,
      barrierDismissible: barrierDismisable,
      builder: (context) {
        return dialog;
      });
}