import 'package:fast/constants.dart'; import 'package:fast/utils/size_fit.dart'; import 'package:flutter/material.dart'; // ignore: must_be_immutable class AlertWidget extends StatefulWidget { String title = ''; // String message = ''; String confirm = '确定'; bool isHiddenCancel = false; VoidCallback confirmCallback; AlertWidget( {Key? key, required this.title, required this.confirm, required this.confirmCallback, bool? hideCancel}) : super(key: key) { if (hideCancel != null) { isHiddenCancel = hideCancel; } } @override State createState() => _AlertWidgetState(); } class _AlertWidgetState extends State with SingleTickerProviderStateMixin { late AnimationController controller; late Animation animation; late Animation alphaAnimation; @override void initState() { controller = AnimationController( vsync: this, duration: const Duration(milliseconds: 300)); animation = Tween(begin: 40.0, end: 0.0).animate(controller); alphaAnimation = Tween(begin: 0.0, end: 1.0).animate(controller); controller.addListener(() { setState(() {}); }); controller.forward(); super.initState(); } @override void dispose() { controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Material( color: Colors.transparent, child: Opacity( opacity: alphaAnimation.value, child: Center( child: Container( margin: EdgeInsets.only(top: animation.value), padding: EdgeInsets.fromLTRB(24.px, 32.px, 24.px, 32.px), width: 268.px, decoration: BoxDecoration( color: const Color(0xFF142133), borderRadius: BorderRadius.all(Radius.circular(32.px))), child: Column( mainAxisSize: MainAxisSize.min, children: [ Text( widget.title, style: TextStyle( color: Colors.white, fontSize: 16.px, fontWeight: FontWeight.bold, height: 1.5, ), textAlign: TextAlign.center, ), SizedBox( height: 18.px, ), Row( children: [ if (widget.isHiddenCancel == false) Expanded( child: Container( child: TextButton( onPressed: () => Navigator.of(context).pop(), child: Text( '取消', style: TextStyle( color: const Color(0xFFC4CCDA), fontSize: 14.px, fontWeight: FontWeight.bold), )), height: 42.px, decoration: BoxDecoration( color: const Color(0x33C4CCDA), borderRadius: BorderRadius.all(Radius.circular(21.px))), )), if (widget.isHiddenCancel == false) SizedBox( width: 12.px, ), Expanded( child: Container( child: TextButton( onPressed: widget.confirmCallback, child: Text( widget.confirm, style: TextStyle( color: kBgColor, fontSize: 14.px, fontWeight: FontWeight.bold), )), height: 42.px, decoration: BoxDecoration( color: kThemeColor, borderRadius: BorderRadius.all(Radius.circular(21.px))), )) ], ) ], ), )), ), ); } } /* class AlertWidget extends Dialog { String title = ''; // String message = ''; String confirm = '确定'; VoidCallback confirmCallback; AlertWidget( {Key? key, required this.title, required this.confirm, required this.confirmCallback}) : super(key: key); @override Widget build(BuildContext context) { return Material( color: Colors.transparent, child: Center( child: Container( padding: EdgeInsets.fromLTRB(24.px, 32.px, 24.px, 32.px), width: 268.px, decoration: BoxDecoration( color: const Color(0xFF142133), borderRadius: BorderRadius.all(Radius.circular(32.px))), child: Column( mainAxisSize: MainAxisSize.min, children: [ Text( title, style: TextStyle( color: Colors.white, fontSize: 16.px, fontWeight: FontWeight.bold, height: 1.5, ), textAlign: TextAlign.center, ), SizedBox( height: 18.px, ), Row( children: [ Expanded( child: Container( child: TextButton( onPressed: () => Navigator.of(context).pop(), child: Text( '取消', style: TextStyle( color: const Color(0xFFC4CCDA), fontSize: 14.px, fontWeight: FontWeight.bold), )), height: 42.px, decoration: BoxDecoration( color: const Color(0x33C4CCDA), borderRadius: BorderRadius.all(Radius.circular(21.px))), )), SizedBox( width: 12.px, ), Expanded( child: Container( child: TextButton( onPressed: confirmCallback, child: Text( confirm, style: TextStyle( color: kBgColor, fontSize: 14.px, fontWeight: FontWeight.bold), )), height: 42.px, decoration: BoxDecoration( color: kThemeColor, borderRadius: BorderRadius.all(Radius.circular(21.px))), )) ], ) ], ), )), ); } }*/