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

animated_widgets 封面
插件详情v1.1.0

animated_widgets

使用 AnimatedWidgets 轻松为您的屏幕添加动画。始终将您的动画小部件添加到组件树中,然后在需要时激活它们以启动动画。

近 30 天下载
1万
喜欢数
171
Pub 分数
70

安装插件

flutter pub add animated_widgets

插件介绍

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

AnimatedWidgets 是一个 Flutter 包,可简化向 UI 组件添加动画的过程。它允许开发者将动画小部件直接嵌入到小部件树中,并按需触发动画。通过最少的设置,它通过启用流畅的过渡和动态效果来增强用户界面,而无需复杂的代码。非常适合创建需要视觉反馈或运动效果的应用程序中的引人入胜、交互式体验。该包轻量且可无缝集成到现有的 Flutter 项目中。

适合场景

  • 为UI元素添加微妙的进入动画
  • 创建交互式按钮反馈
  • 滚动时动画列表或卡片
  • 通过动态效果增强启动画面
  • 使用视觉提示构建响应式表单输入

主要特点

  • 简单集成到组件树中
  • 按需触发动画
  • 轻量且高效
  • 支持常见的动画模式
  • 轻松自定义时间和行为

适合对象

  • 初学者到中级 Flutter 开发者
  • 需要视觉美化功能的应用
  • 交互式 UI 组件
  • 快速原型动画
  • 专注于用户参与度的项目

使用建议

  • 仅限基本动画类型
  • 无内置的复杂编排支持
  • 需要手动管理动画状态
  • 未针对高频更新进行优化
  • 依赖于 Flutter 动画引擎的性能

原始 README

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

animated_widgets

Easily add animations on your screen with AnimatedWidgets.

Optimized for MVVM using Bloc, updating the enabled value of the widget will forward or reverse the animation.

Available widgets : TranslationAnimatedWidget, OpacityAnimatedWidget, RotationAnimatedWidget, ScaleAnimatedWidget, SizeAnimatedWidget

For example : add a TranslationAnimatedWidget on a button, then activate it to display it !

TranslationAnimatedWidget(
    enabled: this.displayMyWidget, //update this boolean to forward/reverse the animation
    values: [
        Offset(0, 200), // disabled value value
        Offset(0, 250), //intermediate value
        Offset(0, 0) //enabled value
    ],
    child: /* your widget */
),

screen

or using a tween constructor

RotationAnimatedWidget.tween(
    enabled: this.displayMyWidget, //update this boolean to forward/reverse the animation
    rotationDisabled: Rotation.degrees(z: 0),
    rotationEnabled: Rotation.degrees(z: 90),
    child: /* your widget */
),

screen

Compose

Don't hesitate to compose them

TranslationAnimatedWidget.tween(
    enabled: this.displayMyWidget,
    translationDisabled: Offset(0, 200),
    translationEnabled: Offset(0, 0),
    child:
        OpacityAnimatedWidget.tween(
        enabled: this.displayMyWidget,
        opacityDisabled: 0,
        opacityEnabled: 1,
        child: /* your widget */
    ),
),

screen

Opacity

screen

Example using a Stateful Widget

class _StatefulScreenState extends State<StatefulScreen> {

  // will determine if the opacity animation is launched
  bool _display = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.max,
        children: [

          //wrap your widget with OpacityAnimatedWidget
          OpacityAnimatedWidget.tween(
            opacityEnabled: 1, //define start value
            opacityDisabled: 0, //and end value
            enabled: _display, //bind with the boolean
            child: Container(
               height: 200,
               width: 200,
               child: FlutterLogo(
                 style: FlutterLogoStyle.stacked,
               ),
            ),
          ),

          RaisedButton(
            color: Colors.blue,
            child: Text(
              _display ? "hide logo" : "display logo",
              style: TextStyle(color: Colors.white),
            ),
            onPressed: () {
              setState(() {

                //will fire the animation
                _display = !_display;

              });
            },
          )
        ],
      ),
    );
  }
}

Translation

screen

Example using bloc pattern

class FirstScreenBloc extends Bloc {
  final _viewState = BehaviorSubject<FirstScreenViewState>.seeded(FirstScreenViewState());
  Observable<FirstScreenViewState> get viewState => _viewState;

  void onClicked() {
    _viewState.add(FirstScreenViewState(buttonVisible: true));
  }

  void onDismissClicked() {
    _viewState.add(FirstScreenViewState(buttonVisible: false));
  }

  @override
  void dispose() {
    _viewState.close();
  }
}

class FirstScreenViewState {
  final bool buttonVisible;

  const FirstScreenViewState({
    this.buttonVisible = false,
  });
}
class FirstScreenView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final bloc = BlocProvider.of<FirstScreenBloc>(context);

    return StreamBuilder<FirstScreenViewState>(
            stream: bloc.viewState,
            builder: (context, snapshot) {

                final viewState = snapshot.data;

                return Stack(
                  fit: StackFit.expand,
                  children: [
                    _buildInputButton(onClicked: () {
                      bloc.onClicked();
                    }),
                    Positioned(
                      bottom: 20,
                      left: 20,
                      right: 20,

                      child: TranslationAnimatedWidget(
                        enabled: viewState.buttonVisible, //will forward/reverse the animation
                        curve: Curves.easeIn,
                        duration: Duration(seconds: 1),
                        values: [
                          Offset(0, 200),
                          Offset(0, -50),
                          Offset(0, 0),
                        ],
                        child: RaisedButton(
                          onPressed: () {
                            bloc.onDismissClicked();
                          },
                          child: Text("Dismiss"),
                        ),

                      ),
                    ),
                  ],
               );
            }
        );
  }
}

Rotation

screen

RotationAnimatedWidget.tween(
    enabled: enabled,
    rotationDisabled: Rotation.deg(),
    rotationEnabled: Rotation.deg(z: 90, x: 80),
    child: /* your widget */
),

RotationAnimatedWidget.tween(
    enabled: enabled,
    rotation: Rotation.deg(),
    rotationEnabled: Rotation.deg(z: 90, x: 80),
    child: /* your widget */
),

Scale

ScaleAnimatedWidget.tween(
      enabled: this._enabled,
      duration: Duration(milliseconds: 600),
      scaleDisabled: 0.5,
      scaleEnabled: 1,

      //your widget
      child: Container(
        height: 200,
        width: 200,
        child: FlutterLogo(
          style: FlutterLogoStyle.stacked,
        ),
      ),
    ),

screen

Size

SizeAnimatedWidget(
      enabled: this._enabled,
      duration: Duration(milliseconds: 1500),
      values: [Size(100, 100),  Size(100, 150), Size(200, 150), Size(200, 200)],
      curve: Curves.linear,

      //your widget
      child: Container(
        decoration: BoxDecoration(
          border: Border.all(color: Colors.blue)
        ),
        child: FlutterLogo(
          style: FlutterLogoStyle.stacked,
        ),
      ),
    ),

screen

Shake

ShakeAnimatedWidget(
      enabled: this._enabled,
      duration: Duration(milliseconds: 1500),
      shakeAngle: Rotation.deg(z: 40),
      curve: Curves.linear,
      child: FlutterLogo(
        style: FlutterLogoStyle.stacked,
      ),
    ),

screen

Custom Animated

CustomAnimatedWidget(
      enabled: this._enabled,
      duration: Duration(seconds: 3),
      curve: Curves.easeOut,
      builder: (context, percent) { //for custom animation, use builders
        final int displayedDate = (2018 * percent).floor();
        return Text(
              "current year : $displayedDate",
              style: TextStyle(color: Colors.blue),
        );
      },
),

screen

Flutter Package

Animated widget is available at https://pub.dev/packages/animated_widgets

dependencies:
  animated_widgets:

Getting Started with Flutter

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

License

Copyright 2019 florent37, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目