import 'package:fast/constants.dart'; import 'package:fast/utils/size_fit.dart'; import 'package:flutter/material.dart'; // ignore: must_be_immutable class Toast extends StatefulWidget { String title; Widget? content; bool errorIcon = false; Toast({Key? key, required this.title, required this.content, bool? showError}) : super(key: key) { if (showError == true) { errorIcon = showError!; } } @override State createState() => _ToastState(); } class _ToastState extends State with SingleTickerProviderStateMixin { late AnimationController controller; late Animation alphaAni; late Animation alpha2Ani; late Animation scaleAni; late Animation positionAni; @override void initState() { super.initState(); controller = AnimationController( vsync: this, duration: const Duration(milliseconds: 2500)); alphaAni = Tween(begin: 0.0, end: 1.0).animate( CurvedAnimation(parent: controller, curve: const Interval(0.0, 0.1))); TweenSequenceItem item0 = TweenSequenceItem(tween: Tween(begin: 0.0, end: 1.1), weight: 9); TweenSequenceItem item1 = TweenSequenceItem(tween: Tween(begin: 1.1, end: 0.9), weight: 2); TweenSequenceItem item2 = TweenSequenceItem(tween: Tween(begin: 0.9, end: 1.0), weight: 1); TweenSequence tweenSequence = TweenSequence([item0, item1, item2]); scaleAni = tweenSequence.animate( CurvedAnimation(parent: controller, curve: const Interval(0.0, 0.1))); positionAni = Tween(begin: 0.0, end: 150.px).animate( CurvedAnimation(parent: controller, curve: const Interval(0.9, 1.0))); alpha2Ani = Tween(begin: 1.0, end: 0.0).animate( CurvedAnimation(parent: controller, curve: const Interval(0.9, 1.0))); controller.addListener(() { setState(() {}); }); controller.addStatusListener((status) { if (status == AnimationStatus.completed) { Navigator.of(context).pop(); } }); controller.forward(); } @override void dispose() { controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Center( child: Opacity( opacity: alpha2Ani.value, child: Transform.scale( scale: scaleAni.value, child: Opacity( opacity: alphaAni.value, child: Container( width: 144.px, // height: 178.px, margin: EdgeInsets.only(top: positionAni.value), padding: EdgeInsets.only(top: 28.px, bottom: 24.px), // alignment: Alignment.center, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(32.px)), color: const Color(0xFF313F52), boxShadow: [ BoxShadow( offset: Offset(0.0, 12.px), blurRadius: 24.px, color: kBgColor) ]), child: Column( mainAxisSize: MainAxisSize.min, children: [ Image.asset( widget.errorIcon?'assets/images/tip_error.png':'assets/images/tip_success.png', width: 64.px, height: 64.px, ), SizedBox( height: 10.px, ), Text( widget.title, textAlign: TextAlign.center, style: TextStyle( fontSize: 16.px, color: Colors.white, fontWeight: FontWeight.w500, decoration: TextDecoration.none), ), if (widget.content != null) SizedBox( height: 10.px, ), if (widget.content != null) widget.content as Widget, ], ), ), ), ), ), ); } }