THATMobile/alice/lib/helper/alice_alert_helper.dart
2026-02-26 10:39:42 +07:00

57 lines
1.4 KiB
Dart

import 'package:flutter/material.dart';
class AliceAlertHelper {
///Helper method used to open alarm with given title and description.
static void showAlert(
BuildContext context,
String title,
String description, {
String firstButtonTitle = "Accept",
String? secondButtonTitle,
Function? firstButtonAction,
Function? secondButtonAction,
Brightness? brightness,
}) {
final List<Widget> actions = [];
actions.add(
TextButton(
onPressed: () {
if (firstButtonAction != null) {
firstButtonAction();
}
Navigator.of(context).pop();
},
child: Text(firstButtonTitle),
),
);
if (secondButtonTitle != null) {
actions.add(
TextButton(
onPressed: () {
if (secondButtonAction != null) {
secondButtonAction();
}
Navigator.of(context).pop();
},
child: Text(secondButtonTitle),
),
);
}
showDialog<void>(
context: context,
builder: (BuildContext buildContext) {
return Theme(
data: ThemeData(
brightness: brightness ?? Brightness.light,
),
child: AlertDialog(
title: Text(title),
content: Text(description),
actions: actions,
),
);
},
);
}
}