alertList method

void alertList(
  1. String title,
  2. List<String> items, {
  3. String? msg,
  4. double? cornerRadius,
  5. double? paddingBody = 15,
  6. double? paddingScreen = 15,
  7. double? buttonCornerRadius = 100,
  8. double? heightButtons = 40,
  9. double? verticalListSpace = 5,
  10. String? titleButton,
  11. Function? buttonClick,
  12. double? fixedSize,
})

Method to show an alert with a list of items.

Implementation

void alertList(
  String title,
  List<String> items, {
  String? msg,
  double? cornerRadius,
  double? paddingBody = 15,
  double? paddingScreen = 15,
  double? buttonCornerRadius = 100,
  double? heightButtons = 40,
  double? verticalListSpace = 5,
  String? titleButton,
  Function? buttonClick,
  double? fixedSize,
}) {
  try {
    hideAlert();
    isOpened = true;
    showDialog(
      context: _context,
      builder: (BuildContext context) {
        return Dialog(
          insetPadding: EdgeInsets.all(AwesomeAlertTheme().defaultPaddingAlert ?? paddingScreen ?? 15),
          backgroundColor: Colors.white,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(cornerRadius ?? AwesomeAlertTheme().borderRadius)),
          ),
          child: ConstrainedBox(
            constraints: (fixedSize != null || AwesomeAlertTheme().fixedSize != null)
                ? BoxConstraints(maxWidth: fixedSize ?? AwesomeAlertTheme().fixedSize ?? 700)
                : BoxConstraints(),
            child: SingleChildScrollView(
              child: Container(
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(Radius.circular(cornerRadius ?? AwesomeAlertTheme().borderRadius)),
                ),
                child: Padding(
                  padding: EdgeInsets.all(paddingBody ?? 15),
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Padding(
                        padding: EdgeInsets.fromLTRB(0, 15, 0, 15),
                        child: Text(
                          title,
                          style: TextStyle(
                            fontWeight: FontWeight.w600,
                            color: Theme.of(context).colorScheme.primary,
                            fontSize: 22,
                            height: 1,
                          ),
                          textAlign: TextAlign.center,
                        ),
                      ),
                      msg != null ? Text(msg) : const SizedBox(),
                      SizedBox(height: msg == null ? 0 : 10),
                      items.isNotEmpty
                          ? ListView.builder(
                              physics: NeverScrollableScrollPhysics(),
                              shrinkWrap: true, // Permite que a lista se ajuste ao conteúdo
                              itemCount: items.length,
                              itemBuilder: (context, index) {
                                return Padding(
                                  padding: EdgeInsets.symmetric(vertical: verticalListSpace ?? 5),
                                  child: Text("* ${items[index]}"),
                                );
                              },
                            )
                          : const SizedBox(),
                      SizedBox(height: 15),
                      Row(
                        children: [
                          Expanded(
                            child: MaterialButton(
                              onPressed: () {
                                if (buttonClick != null) {
                                  buttonClick();
                                } else {
                                  Navigator.pop(context);
                                }
                              },
                              shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(AwesomeAlertTheme().buttonRadius ?? buttonCornerRadius ?? 100),
                              ),
                              height: AwesomeAlertTheme().buttonHeight ?? heightButtons,
                              color: Theme.of(context).colorScheme.primary,
                              child: Text(
                                titleButton ?? "Voltar",
                                style: AwesomeAlertTheme().confirmButtonTextStyle ??
                                    const TextStyle(
                                      fontSize: 16,
                                      color: Colors.white,
                                    ),
                              ),
                            ),
                          )
                        ],
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        );
      },
    ).whenComplete(() {
      isOpened = false;
    });
  } on Exception catch (e) {
    debugPrint(e.toString());
  }
}