| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- import 'package:flutter/material.dart';
- // void showSuccess(text) {
- // }
- void showCustomDialog(context, text, {String title, bool isCancel = false, String submitText = '确认', OnTapHomeMenu onsubmit, OnTapHomeMenu oncancel}) {
- Navigator.of(context).push(
- PageRouteBuilder(
- opaque: false,
- transitionDuration: Duration(milliseconds: 300),
- transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
- return FadeTransition(
- opacity: CurvedAnimation(parent: animation, curve: Curves.linear),
- child: child,
- );
- },
- pageBuilder: (BuildContext context, _, __) {
- return LoadingDialog(title: title, text: text, submitText: submitText, cancel: isCancel, onsubmit: onsubmit, oncancel: oncancel);
- },
- ),
- );
- }
- typedef OnTapHomeMenu = void Function();
- // ignore: must_be_immutable
- class LoadingDialog extends Dialog {
- String title;
- String text;
- String submitText;
- bool cancel = false;
- OnTapHomeMenu onsubmit = () {};
- OnTapHomeMenu oncancel = () {};
- LoadingDialog({Key key, @required this.text, this.cancel, this.onsubmit, this.oncancel, this.title, this.submitText}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- return WillPopScope(
- child: Scaffold(
- backgroundColor: Color(0xb3000000),
- body: Container(
- child: SizedBox.expand(
- child: UnconstrainedBox(
- child: Container(
- width: 270,
- // padding: EdgeInsets.symmetric(horizontal: 20, vertical: 25),
- decoration: BoxDecoration(color: Color(0xE6293559), border: Border.all(width: 1, color: Color(0xFF1990F8))),
- child: Stack(
- children: <Widget>[
- Padding(
- padding: EdgeInsets.symmetric(horizontal: 20, vertical: 25),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Text(title ?? '提示', style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold)),
- Container(
- height: 20,
- ),
- Text(text, style: TextStyle(color: Colors.white, fontSize: 14), textAlign: TextAlign.center),
- Container(
- height: 30,
- ),
- cancel
- ? Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Container(
- width: 100,
- child: RaisedButton(
- color: Color(0xFF3A3D5C),
- highlightColor: Color(0xFF3A3D5C).withOpacity(0.8),
- textColor: Colors.white,
- child: Text('取消'),
- onPressed: () {
- Navigator.of(context).pop();
- oncancel();
- },
- ),
- ),
- Container(
- width: 100,
- child: RaisedButton(
- textColor: Colors.white,
- child: Text(submitText),
- onPressed: () {
- Navigator.of(context).pop();
- onsubmit();
- },
- ),
- )
- ],
- )
- : Container(
- width: double.infinity,
- child: RaisedButton(
- textColor: Colors.white,
- child: Text(submitText),
- onPressed: () {
- Navigator.of(context).pop();
- onsubmit();
- },
- ),
- ),
- Container(
- height: 5,
- )
- ],
- ),
- ),
- ],
- ),
- ),
- ),
- ),
- ),
- ),
- onWillPop: () {
- return Future.value(false);
- },
- );
- }
- }
|