app-starlock/lib/tools/showTipView.dart

220 lines
6.4 KiB
Dart
Raw Permalink Normal View History

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:star_lock/app_settings/app_colors.dart';
2025-02-18 14:20:10 +08:00
import 'package:star_lock/main/lockDetail/lockDetail/device_network_info.dart';
import 'package:star_lock/talk/starChart/star_chart_manage.dart';
import 'package:star_lock/tools/showTFView.dart';
import 'showDeleteAdministratorIsHaveAllDataWidget.dart';
typedef BlockIsHaveAllDataCallback = void Function(bool isAllData);
class ShowTipView {
// 只有一个确定按钮
void showSureAlertDialog(String contentStr,
{String? tipTitle, String? sureStr}) {
showCupertinoDialog(
context: Get.context!,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Text(tipTitle ?? ''),
content: Text(contentStr),
actions: <Widget>[
CupertinoDialogAction(
2024-07-26 09:21:22 +08:00
child: Text(sureStr ?? '确定'.tr,
style: TextStyle(color: AppColors.mainColor)),
onPressed: Get.back,
),
],
);
},
);
}
// 授权管理员调用是否删除数据
void showDeleteAdministratorIsHaveAllDataDialog(String contentStr,
BlockIsHaveAllDataCallback blockIsHaveAllDataCallback) {
bool selet = false;
showDialog(
context: Get.context!,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Text('提示'.tr),
content: SizedBox(
// height: 100.h,
child: ShowDeleteAdministratorIsHaveAllDataWidget(
2024-04-02 17:30:44 +08:00
contentStr: contentStr,
blockIsHaveAllDataCallback: (bool a) {
selet = a;
},
),
),
actions: <Widget>[
CupertinoDialogAction(
2024-07-26 09:57:44 +08:00
child: Text('取消'.tr),
onPressed: Get.back,
),
CupertinoDialogAction(
2024-07-26 09:21:22 +08:00
child: Text('确定'.tr),
onPressed: () {
Get.back();
2024-04-02 17:30:44 +08:00
blockIsHaveAllDataCallback(selet);
},
),
],
);
},
);
}
// 有取消和确定按钮
void showIosTipWithContentDialog(String contentStr, Function sureClick) {
showCupertinoDialog(
context: Get.context!,
builder: (BuildContext context) {
return CupertinoAlertDialog(
2024-11-05 09:55:04 +08:00
content: Text(contentStr.tr),
actions: <Widget>[
CupertinoDialogAction(
2024-11-05 09:55:04 +08:00
child:
Text('取消'.tr, style: TextStyle(color: AppColors.mainColor)),
onPressed: Get.back,
),
CupertinoDialogAction(
2024-11-05 09:55:04 +08:00
child:
Text('确定'.tr, style: TextStyle(color: AppColors.mainColor)),
onPressed: () {
Get.back();
sureClick();
},
),
],
);
},
);
}
2024-07-27 14:36:35 +08:00
TextEditingController getController = TextEditingController();
2025-02-18 14:20:10 +08:00
void showTFViewAlertDialog(TextEditingController controller, String title,
String tipTitle, Function sureClick,
{List<TextInputFormatter>? inputFormatters, bool? isShowSuffixIcon}) {
// 点击删除 开始扫描
2024-07-27 14:36:35 +08:00
getController = controller;
showDialog(
context: Get.context!,
builder: (BuildContext context) {
return ShowTFView(
title: title,
tipTitle: tipTitle,
inputFormatters: inputFormatters,
controller: controller,
isShowSuffixIcon: isShowSuffixIcon ?? false,
sureClick: () {
if (controller.text.isEmpty) {
EasyLoading.showToast(tipTitle, duration: 2000.milliseconds);
return;
}
sureClick();
2025-02-18 14:20:10 +08:00
StartChartManage().lockNetworkInfo = DeviceNetworkInfo();
},
cancelClick: () {
// 取消的时候停止扫描
Get.back();
},
);
},
);
}
2024-11-05 09:55:04 +08:00
void resetGetController() {
2024-07-27 14:36:35 +08:00
getController.text = '';
}
// 只有一个确定按钮
void showSureBtnTipsAlert(
{required String tipsText, required String sureText}) {
showCupertinoDialog(
context: Get.context!,
builder: (BuildContext context) {
return CupertinoAlertDialog(
content: Text(tipsText),
actions: <Widget>[
CupertinoDialogAction(
child:
Text('确定'.tr, style: TextStyle(color: AppColors.mainColor)),
onPressed: Get.back,
),
],
);
},
);
}
//输入框的弹窗
void showTipWithInputDialog({
required String title,
required String sureText,
required String contentText,
required Function(String) sureClick,
String cancelText = '取消',
VoidCallback? onCancel,
}) {
final TextEditingController controller = TextEditingController();
controller.text = contentText;
showDialog(
context: Get.context!,
barrierDismissible: true,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Text(
title,
style: TextStyle(color: AppColors.blackColor),
),
content: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const SizedBox(height: 16),
CupertinoTextField(
controller: controller,
placeholder: '请输入',
style: TextStyle(color: AppColors.blackColor),
),
const SizedBox(height: 16),
],
),
actions: <Widget>[
CupertinoDialogAction(
child: Text(
cancelText,
style: TextStyle(color: AppColors.blackColor),
),
onPressed: () {
if (onCancel != null) {
onCancel();
}
Get.back();
},
),
CupertinoDialogAction(
child: Text(
sureText,
style: const TextStyle(color: AppColors.blueTextTipsColor),
),
onPressed: () {
sureClick(controller.text);
// Get.back(); // 关闭弹窗
},
),
],
);
},
);
}
}