首页 > 其他分享 >Flutter 隐式动画

Flutter 隐式动画

时间:2023-12-22 15:55:07浏览次数:243  
标签:动画 200 height width 隐式 100 Flutter

通过几行代码就可以实现隐式动画,由于隐式动画背后的实现原理和繁琐的操作细节都被隐去了,所以叫隐式动画,FLutter中提供的 [AnimatedContainer]、[AnimatedPadding]、[AnimatedPositioned.AnimatedOpacity]、[AnimatedDefaultTextStyle]、[AnimatedSwitcher]都属于隐式动画
隐式动画中可以通过 duration 配置动画时长、可以通过curve (曲线)来配置动画过程

import 'package:flutter/material.dart';

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('动画'),
      ),
      body: AnimateContent(),
    );
  }
}

class AnimateContent extends StatefulWidget {
  const AnimateContent({super.key});

  @override
  State<AnimateContent> createState() => _AnimateContentState();
}

class _AnimateContentState extends State<AnimateContent> {
  late double width;
  late double height;
  Color color = Colors.indigoAccent;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    width = 200;
    height = 200;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: AnimatedContainer(
          duration: const Duration(milliseconds: 200),
          width: width,
          height: height,
          color: color,
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            width = width == 100 ? 200 : 100;
            height = height == 100 ? 200 : 100;
            color = width == 100 ? Colors.indigoAccent : Colors.red;
          });
        },
        child: Icon(Icons.account_box_sharp),
      ),
    );
  }
}

标签:动画,200,height,width,隐式,100,Flutter
From: https://www.cnblogs.com/angelwgh/p/17921775.html

相关文章

  • Android应用开发长按拖拽-Flutter的LongPressDraggable控件回调函数onDraggableCancel
    onDraggableCanceled介绍LongPressDraggable的onDraggableCanceled回调在拖动被取消时触发。拖动可能会被取消,例如用户在拖动开始后移动了太快或在放置之前取消了拖动。onDraggableCanceled的使用以下是如何使用onDraggableCanceled的示例:LongPressDraggable<int>(//......
  • SVG动画
    一、下载SVG网站:https://undraw.co/点击“browsenow”点击“search”点击第一个点击“DownloadSVGforyourprojects”对代码进行格式化将代码拷贝到vscode中,用快捷键“Shift+Alt+F”进行格式化,格式化之后如下所示:<svgxmlns="http://www.w3.org/2000/svg"data-......
  • Flutter AnimatedList 实现动态列表
    import'dart:async';import'package:flutter/material.dart';finalGlobalKey_globalKey=GlobalKey();classMyAnimatedListextendsStatelessWidget{constMyAnimatedList({super.key});@overrideWidgetbuild(BuildContextcont......
  • Flutter 编译是pod intsall github 资源下载失败
    在fluterr编译报错然后显示github.xxxxx访问超时处理办法podinstall主要是读取profile文件platform:ios,'9.0'target'YourAppName'douse_frameworks!#这是安装依赖位置pod'SomeDependency'#添加其他依赖项...end想办法下载到github的文......
  • 纯css展示loading加载动画
    https://uiverse.io/barisdogansutcu/light-rat-32<svgviewBox="25255050"><circler="20"cy="50"cx="50"></circle></svg>svg{width:3.25em;transform-origin:center;animation:rot......
  • Flutter Key 以及通过Key获取子组件的状态和方法
    import'package:flutter/material.dart';classColorItem{GlobalKeykey;Colorcolor;//设置子组件的key,这里用的GlobalKey,用来后面获取子组件//如果不用获取子组件,也可以用ValuekeyColorItem({requiredthis.color}):key=GlobalKey();}classFlutterKe......
  • 外甥女爱看的动画片
    2012年。根据查询《精灵梦叶罗丽》动画片简介得知,该动画已经播出8个季度动画,第一部精灵梦叶罗丽是在2012年正式出品的。《精灵梦叶罗丽》是国产3D动画,该片主要讲述了叶罗丽仙境里的女王曼多拉,因为人类大肆的破坏自然环境,威胁到了仙境的存亡与仙子的安危,曼多拉决定入侵统治人类世界......
  • 想要深入学习Flutter,这篇文章让你一步到位
    前言Flutter是谷歌的移动UI框架,可以快速在iOS和Android上构建高质量的原生用户界面一份代码可以同时生成iOS和Android两个高性能、高保真的应用程序Flutter目标就是使开发人员能够交付在不同平台上都感觉自然流畅的高性能应用程序,并且兼容滚动行为、排版、图标等方面的......
  • iOS项目中加入flutter
    新建一个iOS项目Test在iOS同级目录下建一个flutter modulefluttercreate--templatemodulemy_flutterpodfile编写如下#Uncommentthenextlinetodefineaglobalplatformforyourproject#platform:ios,'9.0'target'Test'do#Commentthenextl......
  • Flutter 使用PageView 自定义无限轮播
    import'package:flutter/material.dart';int_getRealIndex(intindex,intlength){returnindex>=length?index%length:index;}classInfinitySliderextendsStatefulWidget{finalintinitialPage;finalList<Widget>items;......