import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:remixicon/remixicon.dart'; class DeleteRowItem extends StatefulWidget { final bool showDelete; final List Function(BuildContext context, Animation animation) builder; final Function() onDelete; const DeleteRowItem({ super.key, this.showDelete = false, required this.builder, required this.onDelete, }); @override State createState() => _DeleteRowItemState(); } class _DeleteRowItemState extends State with TickerProviderStateMixin { late AnimationController _controller; late Animation _animation; @override void initState() { super.initState(); _controller = AnimationController( vsync: this, duration: Duration(milliseconds: 300), ); _animation = CurvedAnimation( parent: _controller, curve: Curves.easeInOut, ); if (widget.showDelete) { _controller.forward(); } } @override void didUpdateWidget(covariant DeleteRowItem oldWidget) { super.didUpdateWidget(oldWidget); if (oldWidget.showDelete != widget.showDelete) { if (widget.showDelete) { _controller.forward(); } else { _controller.reverse(); } } } @override void dispose() { _controller.dispose(); super.dispose(); } ///点击删除 void _handleDelete() { showCupertinoDialog( context: context, builder: (_) { return CupertinoAlertDialog( title: Text("删除计划"), actions: [ CupertinoDialogAction( child: Text("取消"), onPressed: () { context.pop(); }, ), CupertinoDialogAction( isDestructiveAction: true, onPressed: () { context.pop(); widget.onDelete(); }, child: Text("确定"), ), ], ); }, ); } @override Widget build(BuildContext context) { return Row( children: [ SizeTransition( axis: Axis.horizontal, sizeFactor: _animation, axisAlignment: -1, // 从左向右展开 child: InkWell( onTap: _handleDelete, child: Container( margin: EdgeInsets.only(right: 10), child: Icon( RemixIcons.indeterminate_circle_fill, color: Colors.red, ), ), ), ), ...widget.builder(context, _animation), // ...widget.children, ], ); } }