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:get/get.dart';
|
2024-04-01 11:38:10 +08:00
|
|
|
|
import 'package:sk_base_mobile/app_theme.dart';
|
2024-03-26 11:35:39 +08:00
|
|
|
|
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
|
2024-04-01 08:41:52 +08:00
|
|
|
|
import 'package:sk_base_mobile/widgets/core/sk_bottomsheet_picker.dart';
|
2024-03-19 11:09:07 +08:00
|
|
|
|
|
|
|
|
|
class ModalUtil {
|
2024-04-01 11:38:10 +08:00
|
|
|
|
static Future<bool> confirm(
|
|
|
|
|
{String? title, String? button, VoidCallback? onConfirm}) async {
|
2024-03-19 11:09:07 +08:00
|
|
|
|
bool confirmed = false;
|
|
|
|
|
await showDialog(
|
|
|
|
|
context: Get.overlayContext!,
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return AlertDialog(
|
2024-04-01 11:38:10 +08:00
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
|
backgroundColor: AppTheme.nearlyWhite,
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(ScreenAdaper.sp(20)),
|
|
|
|
|
),
|
2024-04-01 14:27:44 +08:00
|
|
|
|
actionsPadding: EdgeInsets.zero,
|
|
|
|
|
titlePadding: EdgeInsets.zero,
|
2024-04-01 11:38:10 +08:00
|
|
|
|
title: title != null
|
|
|
|
|
? Container(
|
2024-04-01 14:27:44 +08:00
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
|
vertical: ScreenAdaper.height(30),
|
|
|
|
|
horizontal: ScreenAdaper.width(30)),
|
2024-04-01 11:38:10 +08:00
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
border: Border(
|
|
|
|
|
bottom: BorderSide(
|
|
|
|
|
color: AppTheme.dividerColor,
|
|
|
|
|
width: ScreenAdaper.height(2)))),
|
|
|
|
|
alignment: Alignment.center,
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
2024-04-01 14:27:44 +08:00
|
|
|
|
const Icon(
|
2024-04-01 11:38:10 +08:00
|
|
|
|
Icons.error_outline,
|
|
|
|
|
color: AppTheme.dangerColor,
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: ScreenAdaper.width(10),
|
|
|
|
|
),
|
|
|
|
|
Text(
|
|
|
|
|
title,
|
|
|
|
|
style: TextStyle(
|
2024-04-01 17:35:34 +08:00
|
|
|
|
fontSize: ScreenAdaper.height(30),
|
2024-04-01 11:38:10 +08:00
|
|
|
|
fontWeight: FontWeight.w500),
|
|
|
|
|
)
|
|
|
|
|
]),
|
|
|
|
|
)
|
|
|
|
|
: null,
|
2024-03-19 11:09:07 +08:00
|
|
|
|
actions: [
|
2024-04-01 11:38:10 +08:00
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: InkWell(
|
|
|
|
|
onTap: () {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
confirmed = false;
|
|
|
|
|
},
|
|
|
|
|
child: Container(
|
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
|
vertical: ScreenAdaper.height(15)),
|
|
|
|
|
alignment: Alignment.center,
|
|
|
|
|
child: Text(
|
|
|
|
|
'取消',
|
|
|
|
|
style: TextStyle(
|
2024-04-01 17:35:34 +08:00
|
|
|
|
color: Colors.black,
|
|
|
|
|
fontSize: ScreenAdaper.height(30)),
|
2024-04-01 11:38:10 +08:00
|
|
|
|
)),
|
|
|
|
|
)),
|
2024-04-01 14:27:44 +08:00
|
|
|
|
const VerticalDivider(),
|
2024-04-01 11:38:10 +08:00
|
|
|
|
Expanded(
|
|
|
|
|
child: InkWell(
|
|
|
|
|
onTap: () {
|
|
|
|
|
if (onConfirm != null) onConfirm();
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
confirmed = true;
|
|
|
|
|
},
|
|
|
|
|
child: Container(
|
|
|
|
|
padding:
|
|
|
|
|
EdgeInsets.symmetric(vertical: ScreenAdaper.height(15)),
|
|
|
|
|
alignment: Alignment.center,
|
|
|
|
|
child: Text(
|
|
|
|
|
'确定',
|
|
|
|
|
style: TextStyle(
|
2024-04-01 17:35:34 +08:00
|
|
|
|
color: Colors.black,
|
|
|
|
|
fontSize: ScreenAdaper.height(30)),
|
2024-04-01 11:38:10 +08:00
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)),
|
|
|
|
|
],
|
|
|
|
|
)
|
2024-03-19 11:09:07 +08:00
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
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) {
|
2024-04-01 08:41:52 +08:00
|
|
|
|
return SkBottomSheetPicker(
|
2024-03-25 14:16:00 +08:00
|
|
|
|
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(
|
2024-03-27 11:06:01 +08:00
|
|
|
|
{required Widget content,
|
|
|
|
|
double? width,
|
|
|
|
|
double? height,
|
|
|
|
|
Offset? offset}) {
|
2024-03-26 11:35:39 +08:00
|
|
|
|
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(
|
2024-03-26 15:30:43 +08:00
|
|
|
|
height: height ?? Get.height - ScreenAdaper.height(150),
|
2024-03-26 11:35:39 +08:00
|
|
|
|
width: width ?? Get.width - ScreenAdaper.width(150),
|
|
|
|
|
child: content,
|
|
|
|
|
))));
|
|
|
|
|
},
|
|
|
|
|
transitionBuilder: (_, anim, __, child) {
|
|
|
|
|
Tween<Offset> tween;
|
2024-03-27 11:06:01 +08:00
|
|
|
|
tween = Tween(begin: offset ?? const Offset(0, 1), end: Offset.zero);
|
2024-03-26 11:35:39 +08:00
|
|
|
|
return SlideTransition(
|
|
|
|
|
position: tween.animate(
|
|
|
|
|
CurvedAnimation(parent: anim, curve: Curves.easeInOut),
|
|
|
|
|
),
|
|
|
|
|
child: child,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-03-19 11:09:07 +08:00
|
|
|
|
}
|