| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- 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<AlertWidget> createState() => _AlertWidgetState();
- }
- class _AlertWidgetState extends State<AlertWidget>
- 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))),
- ))
- ],
- )
- ],
- ),
- )),
- );
- }
- }*/
|