搜尋套件、儲存庫與 APP 分類

vitality 封面
套件詳情v3.0.0

vitality

使用 Vitality 輕鬆為您的 Flutter 應用程式添加引人入勝的即時動畫!

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
46
喜歡數
70
Pub 分數
130

安裝套件

flutter pub add vitality

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Vitality 是一個 Flutter 套件,讓開發者能輕鬆為應用程式加入令人著迷的即時動畫。支援動態背景效果、漸層與著色器,透過跨多個平台的流暢、吸引人的視覺效果提升使用者介面。此套件可透過簡單指令輕鬆整合至 Flutter 專案中,對初學者與資深開發者皆易於使用。其輕量設計確保順暢效能,同時不影響應用程式的速度。Vitality 透過可自訂的即時動畫為靜態設計注入生命,這些動畫可回應使用者互動或時間觸發。

適用情境

  • 增強應用啟動畫面
  • 建立動態啟動畫面
  • 為儀表板添加動畫背景
  • 透過視覺反饋提升使用者參與度
  • 在遊戲或互動式應用中動畫化使用者介面元素

主要特色

  • 即時直播動畫
  • 對漸變和著色器的支援
  • 跨平台相容性
  • 透過 pub add 的簡單整合
  • 可自定義的動畫參數
  • 輕量且高效

適合對象

  • 尋求動態視覺效果的UI設計師
  • 開發互動式應用的開發者
  • 專注於使用者體驗的團隊
  • 需要動畫背景的專案
  • Flutter 初學者探索進階效果

使用建議

  • 可能影響低階裝置的效能
  • 需要理解動畫原理
  • 除了基本範例之外,文件內容有限
  • 最適合非關鍵的UI元件
  • 不適合高度複雜的動畫序列

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

vitality

  • Welcome to Vitality, a dynamic Flutter package designed to effortlessly infuse your app with captivating live animations in the background. With just 10 lines of code, you can breathe life into your UI by adding randomly moving icons, circles, rectangles, images, and more. Let's explore how you can enhance your app's visual appeal with ease.

Examples:

Check out these examples showcasing the versatility of the Vitality library:

  • example 1 example 6

  • example 3 example 4

  • example 5 example 2

Usage:

  • The Vitality package is designed with simplicity in mind, making integration a breeze. Take a look at the example below to quickly grasp how to use it:
Vitality.randomly(
  background: Colors.black,
  maxOpacity: 0.8,
  minOpacity: 0.3,
  itemsCount: 80,
  enableXMovements: false,
  whenOutOfScreenMode: WhenOutOfScreenMode.Teleport,
  maxSpeed: 1.5,
  maxSize: 30,
  minSpeed: 0.5,
  randomItemsColors: [Colors.yellowAccent, Colors.white],
  randomItemsBehaviours: [
    ItemBehaviour(shape: ShapeType.Icon, icon: Icons.star),
    ItemBehaviour(shape: ShapeType.Icon, icon: Icons.star_border),
    ItemBehaviour(shape: ShapeType.StrokeCircle),
  ],
)

Parameters:

  • whenOutOfScreenMode Determines how a shape behaves at the screen edge, values are:

    • none: It does nothing and continues its movements out the screen.
    • Reflect: It bounces and returns in the oppisite direction.
    • Teleport: It continues its movements to the other side of the screen.
  • randomItemsBehaviours Defines the shapes that the library can generate. Choose from the ShapeType enum (FilledCircle, StrokeCicle, FilledSquare, Icon, Image, etc.) :

    • For Icon type, pass an IconData object:

       ItemBehaviour(shape: ShapeType.Icon, icon: Icons.star)
      
    • For Image type, pass a dart:ui Image object:

       ItemBehaviour(shape: ShapeType.Image, image: /*ui.Image() here*/)
      

      Sample code to load an image from assets:

      • Convert the path into dart:ui Image object
      import 'dart:ui' as ui;
      import 'package:flutter/services.dart';
      
      Future<ui.Image> loadImage(String assetPath) async {
        ByteData data = await rootBundle.load(assetPath);
        List<int> bytes = data.buffer.asUint8List();
        ui.Codec codec = await ui.instantiateImageCodec(Uint8List.fromList(bytes));
        ui.FrameInfo fi = await codec.getNextFrame();
        return fi.image;
      }
      
      • Integrate this function into your code :
      FutureBuilder<ui.Image>(
        future: loadImage('assets/images/your_image.png'),
        builder: (context, snapshot) {
          if (snapshot.connectionState == ConnectionState.done) {
            return Vitality.randomly(
              whenOutOfScreenMode: WhenOutOfScreenMode.Reflect,
              randomItemsColors: const [Colors.yellow],
              randomItemsBehaviours: [
                ItemBehaviour(
                  shape: ShapeType.Image,
                  image: snapshot.data!,
                )
              ],
            );
          }
          return const CircularProgressIndicator();
        },
      ),
      

Full Customization:

  • If you desire even more customization in your animations, Vitality provides a custom mode that is straightforward to use. In this mode, you can specify the exact shapes, icons, or images you want to animate using the shapes parameter. Additionally, you can control the background with the background parameter.
Customizing Individual Shapes:
  • To customize individual shapes, you can pass a list of Shape objects as the shapes parameter. Each Shape object includes the following properties:
    • pos: Initial position of the shape [Offset].
    • dx: Speed on the X-axis [double].
    • dy: Speed on the Y-axis [double].
    • size: Size of the shape [double].
    • color: Color of the shape [Color].
    • whenOutOfScreenMode: Behavior of the shape at the screen edge [WhenOutOfScreenMode].
    • behaviour: Structure of the shape [ItemBehaviour].
Vitality.custom(shapes: [
  Shape(
    pos: const Offset(30, 30),
    dx: 0.3,
    dy: 0,
    size: 160,
    color: Colors.yellow,
    whenOutOfScreenMode: WhenOutOfScreenMode.Reflect,
    behaviour: ItemBehaviour(shape: ShapeType.Icon, icon: Icons.sunny),
  ),
]),
Customizing Groups of Shapes:
  • For more dynamic combinations, you can use the ShapesGenerator class. This class allows you to generate shapes with specific properties, resulting in an easier way to seamlessly combine multiple shapes, allowing you to effortlessly craft a beautiful background. The parameters include:

    • minWidth, minHeight: Minimum width and height for random generation [double].
    • maxWidth, maxHeigh: Maximum width and height for random generation [double].
    • enableXMovements, enableYMovements: Whether or not the shapes will move on the X and Y axes [bool].
    • minSize, maxSize: Minimum and maximum size values for shapes [double].
    • minOpacity, maxOpacity: Minimum and maximum opacity values for shapes (values between 0 and 1) [double].
    • minSpeed, maxSpeed: Minimum and maximum speed values for shapes [double].
    • behaviours: List of ItemBehaviour for random selection.
    • colors: List of Color for random selection.
    • whenOutOfScreenMode: What will happen when shapes reach the screen edge [WhenOutOfScreenMode].
List<Shape> getClouds(Size size) {
  return ShapesGenerator.randomly(
    maxWidth: size.width,
    maxHeight: size.height / 3,
    enableYMovements: false,
    maxSize: 60,
    minSize: 50,
    maxOpacity: 0.9,
    minOpacity: 0.5,
    whenOutOfScreenMode: WhenOutOfScreenMode.Reflect,
    behaviours: [ItemBehaviour(shape: ShapeType.Icon, icon: Icons.cloud)],
    colors: const [Colors.white],
  ).getShapes(10);
}

Now, let's mix different shapes to make something truly magical.

List<Shape> getClouds(Size size) {
  return ShapesGenerator.randomly(
    maxWidth: size.width,
    maxHeight: size.height / 3,
    enableYMovements: false,
    maxSize: 60,
    minSize: 50,
    maxOpacity: 0.9,
    minOpacity: 0.5,
    whenOutOfScreenMode: WhenOutOfScreenMode.Reflect,
    behaviours: [ItemBehaviour(shape: ShapeType.Icon, icon: Icons.cloud)],
    colors: const [Colors.white],
  ).getShapes(10);
}

List<Shape> getGroundShapes(Size size) {
  return ShapesGenerator.randomly(
    minHeight: size.height - 130,
    maxWidth: size.width,
    maxHeight: size.height,
    enableYMovements: false,
    maxSize: 190,
    minSize: 90,
    maxOpacity: 1,
    minOpacity: 0.5,
    whenOutOfScreenMode: WhenOutOfScreenMode.none,
    behaviours: [
      ItemBehaviour(shape: ShapeType.Icon, icon: Icons.circle)
    ],
    colors: const [Colors.green],
    maxSpeed: 0,
    minSpeed: 0
  ).getShapes(40);
}



@override
Widget build(BuildContext context) {
  Size size = MediaQuery.of(context).size;
  return Vitality.custom(background: Colors.blue, shapes: [
    Shape(
      pos: const Offset(30, 30),
      dx: 0.3,
      dy: 0,
      size: 160,
      color: Colors.yellow,
      whenOutOfScreenMode: WhenOutOfScreenMode.Reflect,
      behaviour: ItemBehaviour(shape: ShapeType.Icon, icon: Icons.sunny),
    ),
    ...getClouds(size),
    ...getGroundShapes(size),
  ]);
}

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。