WGShare.Mobile.Flutter/wgshare/lib/view/public_dialog.dart

176 lines
5.2 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 'dart:io';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/src/size_extension.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:install_plugin/install_plugin.dart';
import 'package:path_provider/path_provider.dart';
import 'package:wgshare/utils/color_util.dart';
import 'package:wgshare/utils/toast_utils.dart';
import 'package:wgshare/view/upgrade/util/load_file_cancel_request.dart';
publicDialog(BuildContext context,
{String title = "提示",
required String describe,
btnWidth = 116.0,
btnHeight = 42.0,
required String leftBtnStr,
required String rightBtnStr,
bool hideCancelBtn = false,
required Function leftBtnCallback,
required Function rightBtnCallback}) {
showDialog(
context: context,
barrierDismissible: hideCancelBtn,
builder: (_) => PopScope(
canPop: hideCancelBtn,
child: HintDialog(title, describe, btnWidth, btnHeight, leftBtnStr,
rightBtnStr, hideCancelBtn,leftBtnCallback,rightBtnCallback),
));
}
class HintDialog extends StatefulWidget {
final String title; //标题
final String describe; //描述
final double btnWidth; //按钮宽度
final double btnHeight; //按钮高度
final String leftBtnStr; // 左侧按钮内容
final String rightBtnStr; //右侧按钮内容
final bool hideCancelBtn; //是否隐藏取消btn实际用途为是否可以点击空白和返回键关闭
final Function leftBtnCallback;
final Function rightBtnCallback;
HintDialog(
this.title,
this.describe,
this.btnWidth,
this.btnHeight,
this.leftBtnStr,
this.rightBtnStr,
this.hideCancelBtn,
this.leftBtnCallback,
this.rightBtnCallback);
@override
State<StatefulWidget> createState() {
return HintDialogState();
}
}
class HintDialogState extends State<HintDialog> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Center(
child: Container(
height: 250.h,
margin: const EdgeInsets.only(left: 40, right: 40),
padding:
const EdgeInsets.only(top: 20, bottom: 20, left: 12, right: 12),
decoration: BoxDecoration(
color: const Color.fromRGBO(255, 255, 255, 1),
borderRadius: BorderRadius.circular(8),
),
child: _contentStyle(),
),
);
}
///内容区域样式
_contentStyle() {
return Column(
children: <Widget>[
_title(),
Expanded(
child: _hintMsg(),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
child: Container(
width: widget.btnWidth,
height: widget.btnHeight,
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(99)),
color: ColorUtil.Color_230_230_230,
),
margin: const EdgeInsets.only(top: 12, left: 12),
alignment: Alignment.center,
child: Text(
widget.leftBtnStr,
style: TextStyle(
fontSize: 14.sp, color: ColorUtil.Color_255_255_255),
),
),
onTap: () {
Get.back();
widget.leftBtnCallback();
},
),
GestureDetector(
child: Container(
width: widget.btnWidth,
height: widget.btnHeight,
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(99)),
color: ColorUtil.Color_85_117_242,
),
margin: const EdgeInsets.only(top: 12, right: 12),
alignment: Alignment.center,
child: Text(
widget.rightBtnStr,
style: TextStyle(
fontSize: 14.sp, color: ColorUtil.Color_255_255_255),
),
),
onTap: () {
Get.back();
widget.rightBtnCallback();
},
)
],
)
],
);
}
///提示标题布局
_title() {
return Container(
alignment: Alignment.center,
margin: const EdgeInsets.only(bottom: 12),
child: Text(widget.title,
style: TextStyle(
fontSize: 16.sp,
color: ColorUtil.Color_85_117_242,
fontWeight: FontWeight.w600,
decoration: TextDecoration.none)),
);
}
///提示信息布局
_hintMsg() {
return SingleChildScrollView(
child: Container(
alignment: Alignment.topLeft,
margin: const EdgeInsets.only(left: 8, right: 8),
child: Text(widget.describe,
style: const TextStyle(
fontSize: 14,
color: ColorUtil.Color_89_88_88,
decoration: TextDecoration.none,
height: 1.4)),
),
);
}
}