import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:sport/widgets/button_cancel.dart'; import 'package:sport/widgets/button_primary.dart'; import 'package:sport/widgets/misc.dart'; class CustomAlertDialog extends StatelessWidget { final String title; final Widget? child; final String textCancel; final String textOk; final Function ok; final bool addClose; final bool isLine; final ValueNotifier? onChanged; final bool cancelable; final Key? okKey; final Key? cancelKey; CustomAlertDialog({ this.title = "", this.child, this.textCancel = "取消", this.textOk = "确定", required this.ok, this.addClose = false, this.isLine = false, this.onChanged, this.cancelable = true, this.okKey, this.cancelKey, }); @override Widget build(BuildContext context) { var _width = MediaQuery.of(context).size.shortestSide * (child != null ? 0.70 : 0.66); return Material( type: MaterialType.transparency, child: Scaffold( backgroundColor: Colors.transparent, body: Center( child: Container( width: _width, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(10.0)), color: Colors.white, ), child: Column( mainAxisSize: MainAxisSize.min, children: [ if (addClose) Align( alignment: Alignment.topRight, child: IconButton( icon: Image.asset("lib/assets/img/btn_close_big.png"), onPressed: () => Navigator.pop(context, false), )), if (title.isNotEmpty == true) Stack( children: [ Padding( padding: EdgeInsets.fromLTRB( 0, child != null ? addClose ? 0 : 16.0 : 32.0, 0, isLine ? 15.0 : 20), child: Column( children: [ isLine ? Padding( child: Text( title, style: Theme.of(context).textTheme.headline3, ), padding: EdgeInsets.only(top: 5.0, bottom: 8.0, left: 16.0, right: 16.0), ) : Padding( padding: const EdgeInsets.symmetric(horizontal: 16.0), child: Text( title, style: Theme.of(context).textTheme.headline3, ), ), if (isLine) Divider( endIndent: 20.0, indent: 20.0, ) ], )) ], ), // if (child != null) ConstrainedBox( constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height - 250), child: SingleChildScrollView( child: child, )), Padding( padding: const EdgeInsets.fromLTRB(16.0, 20.0, 16.0, 20.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ if (cancelable == true) Expanded( child: CancelButton( key: cancelKey, height: 35, callback: () { Navigator.of(context).pop(false); }, content: textCancel), ), if (cancelable == true) const SizedBox( width: 20.0, ), Expanded( child: PrimaryButton( key: okKey, height: 35, callback: () { ok(); }, content: textOk)) ], ), ) ], ), ), ), ), ); } }