87 lines
2.4 KiB
Dart
87 lines
2.4 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import '../../app/app.dart';
|
|
|
|
void showMyAlertDialog({
|
|
required BuildContext context,
|
|
required Function(bool) callback,
|
|
required String title,
|
|
required String content,
|
|
String? continueBtnTxt,
|
|
String? cancelBtnTxt,
|
|
}) {
|
|
bool isIOS = Platform.isIOS;
|
|
// set up the buttons
|
|
Widget cancelButton = cancelBtnTxt != null
|
|
? TextButton(
|
|
style: ButtonStyle(
|
|
overlayColor: MaterialStateColor.resolveWith(
|
|
(states) => isIOS ? Colors.transparent : ThemeColor.mainColor.withOpacity(0.1),
|
|
),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Text(
|
|
cancelBtnTxt,
|
|
style: TextStyle(
|
|
color: ThemeColor.mainColor,
|
|
fontSize: 12.sp,
|
|
),
|
|
),
|
|
),
|
|
onPressed: () => callback(false),
|
|
)
|
|
: Container();
|
|
Widget continueButton = continueBtnTxt != null
|
|
? TextButton(
|
|
style: ButtonStyle(
|
|
overlayColor: MaterialStateColor.resolveWith(
|
|
(states) => isIOS ? Colors.transparent : ThemeColor.mainColor.withOpacity(0.1),
|
|
),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Text(
|
|
continueBtnTxt,
|
|
style: TextStyle(
|
|
color: ThemeColor.mainColor,
|
|
fontSize: 12.sp,
|
|
),
|
|
),
|
|
),
|
|
onPressed: () => callback(true),
|
|
)
|
|
: Container();
|
|
|
|
// set up the AlertDialog
|
|
AlertDialog alertDialogAndroid = AlertDialog(
|
|
title: Text(title, style: TextStyle(fontSize: 16.sp)),
|
|
content: Text(content, style: TextStyle(fontSize: 14.sp)),
|
|
actions: [
|
|
cancelButton,
|
|
continueButton,
|
|
],
|
|
);
|
|
|
|
final alertDialogIOS = CupertinoAlertDialog(
|
|
title: Text(title, style: TextStyle(fontSize: 16.sp)),
|
|
content: Text(content, style: TextStyle(fontSize: 14.sp)),
|
|
actions: <Widget>[cancelButton, continueButton],
|
|
);
|
|
|
|
// show the dialog
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
if (isIOS) {
|
|
return alertDialogIOS;
|
|
} else
|
|
return alertDialogAndroid;
|
|
},
|
|
);
|
|
}
|