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

套件詳情v1.1.1

awesome_shake_widget

一個提供搖晃動畫和可選震動效果的 Flutter 小部件,非常適合用於無效表單、注意提示和使用者互動回饋。

AndroidiOS
近 30 天下載
1050
喜歡數
21
Pub 分數
160

安裝套件

flutter pub add awesome_shake_widget

套件介紹

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

一個 Flutter 小部件,可為 UI 元素添加晃動動畫和可選的震動反饋。非常適合吸引使用者注意無效表單輸入、提示使用者操作,或提供互動回饋。該小部件容易整合,並支援 Android 與 iOS 平台。透過最少的設定即可提供視覺與觸覺回應,提升使用者體驗。專為常見互動情境中的簡潔與效能所設計。

適用情境

  • 表單驗證警告
  • 使用者輸入提示
  • 互動式按鈕回饋
  • 錯誤狀態通知
  • 引導式入門

主要特色

  • 搖晃動畫效果
  • 可選的震動支援
  • 跨平台相容性
  • 簡單的 API 結合
  • 可自訂的動畫持續時間
  • 響應式設計支援

適合對象

  • 開發互動式表單的開發者
  • UX 設計師提升回饋機制
  • 需要吸引注意力提示的應用程式
  • 針對 Android 與 iOS 的行動應用程式
  • 專注於直覺式使用者互動的專案

使用建議

  • 若過度使用,可能會造成分心
  • 部分裝置需要權限才能進行震動
  • 動畫效能取決於裝置功能
  • 不適合用於對可存取性有嚴格要求的元件
  • 建議謹慎使用,以維持使用者體驗的清晰度

原始 README

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

🚀 awesome_shake_widget

A customizable Flutter widget that adds shake animations with haptic and vibration feedback. Perfect for invalid forms, error indicators, or drawing attention to UI components.

Pub Version Platform License


✨ Features

  • Shake any widget on demand
  • Built-in presets: light, medium, heavy
  • Optional vibration (custom or haptic)
  • Fully customizable offset, pattern & intensities
  • Easy to trigger using a GlobalKey

📦 Installation

dependencies:
  awesome_shake_widget: ^1.0.1

Run:

flutter pub get

🧪 Usage

1️⃣ Standard (Shake + Vibration)

By using the built-in presets — light, medium, heavy and custom — you can quickly apply different vibration intensities and patterns, perfectly paired with UI shake animations for a dynamic and responsive user experience.

final shakeKey = GlobalKey<ShakeWidgetState>();

ShakeWidget(
  key: shakeKey,
  preset: ShakePreset.medium,
  child: Text("Tap Me"),
);

// Somewhere else, e.g., on button press:
shakeKey.currentState?.shake();

2️⃣ Shake Only (No Vibration)

If you only want the visual shake effect without vibration, you can set vibrationType to VibrationType.none using the ShakeConfig. To customize the intensity of the shake, adjust the offset value — higher values will produce a stronger visual effect.

ShakeWidget(
  key: shakeKey,
  customConfig: ShakeConfig(
    offset: 20,
    vibrationType: VibrationType.none,
  ),
  child: Icon(Icons.info),
);

3️⃣ Advanced Configuration: Full Control Over Visual and Vibration Effects

You can also create custom vibration patterns by setting vibrationType to VibrationType.custom, and providing your own pattern and intensities. This gives you full control over the vibration behavior.

ShakeWidget(
key: shakeKey,
customConfig: ShakeConfig(
offset: 32,
pattern: [0, 50, 100, 50],
intensities: [255, 0, 255, 0],
vibrationType: VibrationType.custom,
),
child: Text("Custom Shake!"),
);

Trigger it via:

shakeKey.currentState?.shake();

🎥 Demo

This demo shows how you can apply shake animations to:

  • ✅ Buttons
  • 💬 Dialogs
  • 🖼️ Images
  • ✏️ Text fields
  • 📦 Any widget

🧩 API Reference

Enum: ShakePreset
Value Offset Vibration
light 8 Haptic
medium 16 Haptic
heavy 24 Patterned Vibe
custom User-defined Custom

Enum: VibrationType
  • none – no vibration
  • haptic – system haptic feedback
  • custom – vibration with pattern/intensity (Android only)

ShakeConfig
ShakeConfig({
  required double offset,
  List<int>? pattern,
  List<int>? intensities,
  VibrationType vibrationType = VibrationType.haptic,
});

💡 Example App

Clone and run the example:

cd example
flutter run

Example main.dart:

import 'package:flutter/material.dart';
import 'package:awesome_shake_widget/shake_widget.dart';

void main() => runApp(const MyApp());

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: ShakeDemo(),
    );
  }
}

class ShakeDemo extends StatelessWidget {
  final shakeKey = GlobalKey<ShakeWidgetState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Shake Demo')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ShakeWidget(
              key: shakeKey,
              preset: ShakePreset.heavy,
              child: const Icon(Icons.warning, size: 64),
            ),
            const SizedBox(height: 32),
            ElevatedButton(
              onPressed: () => shakeKey.currentState?.shake(),
              child: const Text("Shake it!"),
            ),
          ],
        ),
      ),
    );
  }
}

📄 License

MIT © Juanma Del Boca

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。