2024-03-25 14:16:00 +08:00
|
|
|
|
import 'package:flutter/cupertino.dart';
|
2024-03-19 11:09:07 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
|
import 'package:get/get.dart';
|
2024-03-26 11:35:39 +08:00
|
|
|
|
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
|
2024-03-25 14:16:00 +08:00
|
|
|
|
import 'package:sk_base_mobile/widgets/core/zt_bottomsheet_picker.dart';
|
2024-03-19 11:09:07 +08:00
|
|
|
|
|
|
|
|
|
class ModalUtil {
|
|
|
|
|
static Future<bool> showWarningDialog(
|
|
|
|
|
String title, String msg, String button, VoidCallback onConfirm) async {
|
|
|
|
|
bool confirmed = false;
|
|
|
|
|
await showDialog(
|
|
|
|
|
context: Get.overlayContext!,
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return AlertDialog(
|
|
|
|
|
title: Text(title),
|
|
|
|
|
content: Text(msg),
|
|
|
|
|
actions: [
|
|
|
|
|
TextButton(
|
|
|
|
|
child: const Text(
|
|
|
|
|
'Cancel',
|
|
|
|
|
style: TextStyle(color: Colors.black),
|
|
|
|
|
),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
confirmed = false;
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
TextButton(
|
|
|
|
|
child: Text(
|
|
|
|
|
button,
|
|
|
|
|
style: TextStyle(color: Colors.orange),
|
|
|
|
|
),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
onConfirm();
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
confirmed = true;
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
return confirmed;
|
|
|
|
|
}
|
2024-03-25 14:16:00 +08:00
|
|
|
|
|
|
|
|
|
/// 底部选择器,支持3级
|
|
|
|
|
static Future<void> showBottomSheetPicker(
|
|
|
|
|
{title = '请选择',
|
|
|
|
|
required onChanged,
|
|
|
|
|
required firstLevel,
|
|
|
|
|
secondLevel,
|
|
|
|
|
thirdLevel,
|
|
|
|
|
itemHeight,
|
|
|
|
|
popupHeight}) async =>
|
|
|
|
|
showCupertinoModalPopup(
|
|
|
|
|
context: Get.overlayContext!,
|
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
|
return ZtBottomSheetPicker(
|
|
|
|
|
title: title,
|
|
|
|
|
onChanged: onChanged,
|
|
|
|
|
firstLevel: firstLevel,
|
|
|
|
|
secondLevel: secondLevel,
|
|
|
|
|
thirdLevel: thirdLevel,
|
|
|
|
|
itemHeight: itemHeight ?? 80.0,
|
|
|
|
|
popupHeight: popupHeight ?? 400);
|
|
|
|
|
},
|
|
|
|
|
);
|
2024-03-26 11:35:39 +08:00
|
|
|
|
|
|
|
|
|
static Future<void> showGeneralDialog(
|
|
|
|
|
{required Widget content, double? width}) {
|
|
|
|
|
return Get.generalDialog(
|
|
|
|
|
barrierLabel: "productPicker",
|
|
|
|
|
barrierDismissible: true,
|
|
|
|
|
transitionDuration: const Duration(milliseconds: 400),
|
|
|
|
|
pageBuilder: (_, __, ___) {
|
|
|
|
|
return Center(
|
|
|
|
|
child: ClipRRect(
|
|
|
|
|
borderRadius: BorderRadius.circular(ScreenAdaper.sp(30)),
|
|
|
|
|
child: Material(
|
|
|
|
|
child: SizedBox(
|
|
|
|
|
height: Get.height - ScreenAdaper.height(150),
|
|
|
|
|
width: width ?? Get.width - ScreenAdaper.width(150),
|
|
|
|
|
child: content,
|
|
|
|
|
))));
|
|
|
|
|
},
|
|
|
|
|
transitionBuilder: (_, anim, __, child) {
|
|
|
|
|
Tween<Offset> tween;
|
|
|
|
|
tween = Tween(begin: const Offset(0, 1), end: Offset.zero);
|
|
|
|
|
return SlideTransition(
|
|
|
|
|
position: tween.animate(
|
|
|
|
|
CurvedAnimation(parent: anim, curve: Curves.easeInOut),
|
|
|
|
|
),
|
|
|
|
|
child: child,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-03-19 11:09:07 +08:00
|
|
|
|
}
|