import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; class Dialog extends StatelessWidget { String title; String type; String? message; Widget? content; VoidCallback? onConfirm; VoidCallback? onCancel; Dialog({Key? key, this.type = 'alert', required this.title, this.message, this.content, this.onConfirm, this.onCancel, }): super(key: key); Widget _confirmBtn() { return ElevatedButton( child: const Text("确定"), style: ElevatedButton.styleFrom( primary: const Color(0xFFFF703B), textStyle: TextStyle(color: Colors.white, fontSize: 20.sp, letterSpacing: 5.sp), elevation: 0, minimumSize: Size(90.w, 49.w), shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(24.5.w)), ) ), onPressed: onConfirm, ); } Widget _cancelBtn() { return ElevatedButton( child: const Text("取消"), style: ElevatedButton.styleFrom( primary: Colors.transparent, textStyle: TextStyle(color: const Color(0xFFFF703B), fontSize: 20.sp, letterSpacing: 5.sp), elevation: 0, minimumSize: Size(90.w, 49.w), shape: RoundedRectangleBorder( side: const BorderSide(color: Color(0xFFFF703B), width: 2.0), borderRadius: BorderRadius.all(Radius.circular(24.5.w)), ) ), onPressed: onCancel, ); } Widget _alert() { return SimpleDialog( title: Text(title), children: [ if (null != message) Text(message!), if (null != content) content!, Center( child: _confirmBtn(), ) ] ); } Widget _dialog() { return SimpleDialog( title: Text(title), children: [ if (null != message) Text(message!), if (null != content) content!, Row( children: [ Center( child: _confirmBtn(), ), Center( child: _cancelBtn(), ) ], ) ] ); } @override Widget build(BuildContext context) { return type == 'alert' ? _alert() : _dialog(); } }