123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- import 'package:fis_common/helpers/color.dart';
- import 'package:flutter/material.dart';
- import 'package:flyinsonolite/infrastructure/scale.dart';
- import 'package:flyinsonolite/infrastructure/storage.dart';
- class SwipeCard extends StatefulWidget {
- final Widget child;
- final int? index;
- final Function onTap;
- final bool isActive;
- final EdgeInsets forbiddenAnimationMargin;
- final EdgeInsets forbiddenAnimationPadding;
- /// 是否禁用动画
- final bool? isForbiddenAnimation;
- const SwipeCard({
- Key? key,
- this.index,
- required this.child,
- required this.onTap,
- required this.isActive,
- this.forbiddenAnimationMargin = const EdgeInsets.only(
- right: 22,
- left: 22,
- ),
- this.forbiddenAnimationPadding = const EdgeInsets.only(
- top: 20,
- bottom: 10,
- left: 15,
- right: 0,
- ),
- this.isForbiddenAnimation = false,
- }) : super(key: key);
- @override
- State<SwipeCard> createState() => _SwipeCardState();
- }
- class _SwipeCardState extends State<SwipeCard> {
- bool hovering = false;
- Widget _buildChild() {
- EdgeInsets margin = EdgeInsets.only(
- right: 22.s,
- left: 22.s,
- );
- Color color = Colors.white;
- BoxShadow boxShadow = BoxShadow(
- color: FColorHelper.mixColor(
- Colors.black12,
- Colors.black38,
- 70,
- ),
- offset: Offset(3.s, 3.s), //阴影y轴偏移量
- blurRadius: 6.s, //阴影模糊程度
- spreadRadius: 0, //阴影扩散程度
- );
- EdgeInsets padding =
- EdgeInsets.only(top: 20.s, bottom: 10.s, left: 15.s, right: 0);
- if (hovering && !widget.isActive) {
- margin = EdgeInsets.only(
- right: 15.s,
- left: 15.s,
- );
- color = Storage.currentTheme.themeData.indicatorColor;
- boxShadow = BoxShadow(
- color: color,
- offset: Offset(3.s, 3.s), //阴影y轴偏移量
- blurRadius: 6.s, //阴影模糊程度
- spreadRadius: 0, //阴影扩散程度
- );
- padding = EdgeInsets.only(
- top: 20.s,
- bottom: 10.s,
- left: 22.s,
- right: 0,
- );
- } else if (widget.isActive) {
- //color = FTheme.ins.colorScheme.primary;
- boxShadow = BoxShadow(
- color: FColorHelper.mixColor(
- color,
- Colors.black,
- 70,
- ),
- offset: Offset(3.s, 3.s), //阴影y轴偏移量
- blurRadius: 6.s, //阴影模糊程度
- spreadRadius: 0, //阴影扩散程度
- );
- }
- return AnimatedContainer(
- duration: const Duration(milliseconds: 200),
- decoration: BoxDecoration(
- color: color,
- borderRadius: BorderRadius.all(
- Radius.circular(8.s),
- ),
- boxShadow: [
- boxShadow,
- ],
- ),
- margin: widget.isForbiddenAnimation!
- ? widget.forbiddenAnimationMargin
- : margin,
- padding: widget.isForbiddenAnimation!
- ? widget.forbiddenAnimationPadding
- : padding,
- child: widget.child,
- );
- }
- @override
- Widget build(BuildContext context) {
- return MouseRegion(
- cursor: SystemMouseCursors.click,
- onEnter: (e) {
- setState(() {
- hovering = true;
- });
- },
- onExit: (e) {
- setState(() {
- hovering = false;
- });
- },
- child: GestureDetector(
- onTap: () {
- setState(() {
- widget.onTap();
- });
- },
- child: Column(
- children: [
- _buildChild(),
- SizedBox(height: 15.s),
- ],
- ),
- ),
- );
- }
- }
|