alertList method
void
alertList(})
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());
}
}