mobile_skt/lib/util/modal.util.dart

156 lines
5.3 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sk_base_mobile/app_theme.dart';
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
import 'package:sk_base_mobile/widgets/core/sk_bottomsheet_picker.dart';
class ModalUtil {
static Future<bool> confirm(
{String? title, String? button, VoidCallback? onConfirm}) async {
bool confirmed = false;
await showDialog(
context: Get.overlayContext!,
builder: (context) {
return AlertDialog(
clipBehavior: Clip.hardEdge,
backgroundColor: AppTheme.nearlyWhite,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(ScreenAdaper.sp(20)),
),
actionsPadding: EdgeInsets.zero,
titlePadding: EdgeInsets.zero,
title: title != null
? Container(
padding: EdgeInsets.symmetric(
vertical: ScreenAdaper.height(30),
horizontal: ScreenAdaper.width(30)),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: AppTheme.dividerColor,
width: ScreenAdaper.height(2)))),
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.error_outline,
color: AppTheme.dangerColor,
),
SizedBox(
width: ScreenAdaper.width(10),
),
Text(
title,
style: TextStyle(
fontSize: ScreenAdaper.sp(40),
fontWeight: FontWeight.w500),
)
]),
)
: null,
actions: [
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(
color: Colors.black, fontSize: ScreenAdaper.sp(40)),
)),
)),
const VerticalDivider(),
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(
color: Colors.black, fontSize: ScreenAdaper.sp(40)),
),
),
)),
],
)
],
);
},
);
return confirmed;
}
/// 底部选择器支持3级
static Future<void> showBottomSheetPicker(
{title = '请选择',
required onChanged,
required firstLevel,
secondLevel,
thirdLevel,
itemHeight,
popupHeight}) async =>
showCupertinoModalPopup(
context: Get.overlayContext!,
builder: (BuildContext context) {
return SkBottomSheetPicker(
title: title,
onChanged: onChanged,
firstLevel: firstLevel,
secondLevel: secondLevel,
thirdLevel: thirdLevel,
itemHeight: itemHeight ?? 80.0,
popupHeight: popupHeight ?? 400);
},
);
static Future<void> showGeneralDialog(
{required Widget content,
double? width,
double? height,
Offset? offset}) {
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: height ?? Get.height - ScreenAdaper.height(150),
width: width ?? Get.width - ScreenAdaper.width(150),
child: content,
))));
},
transitionBuilder: (_, anim, __, child) {
Tween<Offset> tween;
tween = Tween(begin: offset ?? const Offset(0, 1), end: Offset.zero);
return SlideTransition(
position: tween.animate(
CurvedAnimation(parent: anim, curve: Curves.easeInOut),
),
child: child,
);
},
);
}
}