搜索插件、代码仓与 APP 分类

add_to_cart_animation 封面
插件详情v2.0.4

add_to_cart_animation

一个提供添加到购物车动画的 Flutter 插件。我专门为购物应用准备了它,但您也可以在其他应用中使用。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
2730
喜欢数
324
Pub 分数
150

安装插件

flutter pub add add_to_cart_animation

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 插件,提供流畅的添加到购物车动画,非常适合购物应用程序。它使用户能够通过动态且引人入胜的运动效果直观地看到物品被添加到购物车中。该动画可自定义,并可集成到各种 UI 组件中。虽然专为电子商务应用设计,但其灵活性也适用于需要直观购物车交互的其他场景。该包支持所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。

适合场景

  • 电子商务应用程序产品添加
  • 互动式购物车体验
  • 项目选择的视觉反馈
  • 提升零售应用中的用户参与度
  • 移动和网页应用中的自定义动画

主要特点

  • 平滑添加到购物车动画
  • 跨平台兼容性
  • 与现有 UI 的轻松集成
  • 可自定义的动画行为
  • 支持多个目标目的地

适合对象

  • 购物和零售应用
  • 需要视觉购物车反馈的应用
  • 寻求简单动画解决方案的开发者
  • Flutter 项目针对多个平台
  • 专注于UI/UX增强的开发者

使用建议

  • 需要正确放置购物车图标或目标
  • 在低端设备上可能需要性能调优
  • 仅限基本购物车动画模式
  • 不适合复杂的交互流程
  • 依赖正确的控件层级以获得最佳效果

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Add To Cart Animaiton

A flutter plugin which provide you add to cart animation. I have prepared it to special to shopping apps however you can use it on the others apps too, becasue it accept every widget to drag as in the gif. So It can be useful at shopping, game, news and other category apps.

Icon Preview Gif | Image Preview Gif | Text Preview Gif

Features
  • Product container accepts every widget.
  • The cart and cart's badge can be invisible.
  • The product animation is fully controlled(duration, curve)
  • The first jump animation is fully controlled(active, duration, curve)

If you need it, you can add it to your project easily. It is easy to use

Add the dependency to your pubspec.yaml:

add_to_cart_animation: ^2.0.4

And check the example code to solve how it works.

import 'package:add_to_cart_animation/add_to_cart_animation.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Add To Cart Animation Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Add To Cart Animation Example'),
      debugShowCheckedModeBanner: false,
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

  @override
  MyHomePageState createState() => MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> {
  // We can detect the location of the cart by this  GlobalKey<CartIconKey>
  GlobalKey<CartIconKey> cartKey = GlobalKey<CartIconKey>();
  late Function(GlobalKey) runAddToCartAnimation;
  var _cartQuantityItems = 0;

  @override
  Widget build(BuildContext context) {
    return AddToCartAnimation(
      // To send the library the location of the Cart icon
      cartKey: cartKey,
      height: 30,
      width: 30,
      opacity: 0.85,
      dragAnimation: const DragToCartAnimationOptions(
        rotation: true,
      ),
      jumpAnimation: const JumpAnimationOptions(),
      createAddToCartAnimation: (runAddToCartAnimation) {
        // You can run the animation by addToCartAnimationMethod, just pass trough the the global key of  the image as parameter
        this.runAddToCartAnimation = runAddToCartAnimation;
      },
      child: Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
          centerTitle: false,
          actions: [
            //  Adding 'clear-cart-button'
            IconButton(
              icon: const Icon(Icons.cleaning_services),
              onPressed: () {
                _cartQuantityItems = 0;
                cartKey.currentState!.runClearCartAnimation();
              },
            ),
            const SizedBox(width: 16),
            AddToCartIcon(
              key: cartKey,
              icon: const Icon(Icons.shopping_cart),
              badgeOptions: const BadgeOptions(
                active: true,
                backgroundColor: Colors.red,
              ),
            ),
            const SizedBox(
              width: 16,
            )
          ],
        ),
        body: ListView(
          children: List.generate(
            15,
            (index) => AppListItem(
              onClick: listClick,
              index: index,
            ),
          ),
        ),
      ),
    );
  }

  void listClick(GlobalKey widgetKey) async {
    await runAddToCartAnimation(widgetKey);
    await cartKey.currentState!
        .runCartAnimation((++_cartQuantityItems).toString());
  }
}

class AppListItem extends StatelessWidget {
  final GlobalKey widgetKey = GlobalKey();
  final int index;
  final void Function(GlobalKey) onClick;

  AppListItem({super.key, required this.onClick, required this.index});
  @override
  Widget build(BuildContext context) {
    //  Container is mandatory. It can hold images or whatever you want
    Container mandatoryContainer = Container(
      key: widgetKey,
      width: 60,
      height: 60,
      color: Colors.transparent,
      child: Image.network(
        "https://cdn.jsdelivr.net/gh/omerbyrk/add_to_cart_animation/example/assets/apple.png",
        width: 60,
        height: 60,
      ),
    );

    return ListTile(
      onTap: () => onClick(widgetKey),
      leading: mandatoryContainer,
      title: Text(
        "Animated Apple Product Image $index",
      ),
    );
  }
}

By the way, you can run the example project in the plugin to check it deeply.

Have a good days.

Thanks for contributing:

codegtd

Support

Did you find this plugin useful? Please consider to buy me a coffe!

所属分类

源码仓库

使用此插件的项目

暂无相关数据。