flutter开发实战-旋转loading指示器

flutter开发实战-旋转loading指示器。

一、交织动画

有些时候我们可能会需要一些复杂的动画,这些动画可能由一个动画序列或重叠的动画组成。一个动画组合在不同阶段包含了多种动画,要实现这种效果,需要使用交织动画(Stagger Animation)实现会比较方法。

二、实现旋转loading指示器

实现旋转loading指示器代码

// 旋转loading指示器

class CustomLoadingIndicator extends StatefulWidget {

const CustomLoadingIndicator({Key? key}) : super(key: key);

@override

State createState() => _CustomLoadingIndicatorState();

}

class _CustomLoadingIndicatorState extends State with TickerProviderStateMixin {

late AnimationController _animationController;

late Animation _animation;

bool _disposed = false;

@override

void initState() {

// TODO: implement initState

super.initState();

_disposed = false;

复制代码
startAnimation();

}

void startAnimation() {

if (_disposed == true) {

return;

}

复制代码
_animationController =
    AnimationController(vsync: this, duration: Duration(milliseconds: 500));

_animation =
    CurvedAnimation(parent: _animationController, curve: Curves.linear);
_animation = Tween(begin: 0.0, end: 2*pi).animate(_animation);

_animationController.addListener(() {
  if (mounted) {
    setState(() {});
  }
});

_animationController.addStatusListener((status) {
  if (status == AnimationStatus.completed) {
    startAnimation();
  }
});

_animationController.forward();

}

@override

void dispose() {

// TODO: implement dispose

_disposed = true;

_animationController.dispose();

super.dispose();

}

@override

Widget build(BuildContext context) {

return Container(

width: 60,

height: 60,

color: Colors.transparent,

alignment: Alignment.center,

child: Transform.rotate(

//旋转90度

angle:_animation.value,

child: _buildLoadingWidget(context),

),

);

}

Widget _buildLoadingWidget(BuildContext context) {

return ImageHelper.wrapAssetAtImages(

"icons/ic_toast_loading.png",

width: 50.0,

height: 50.0,

);

}

}

三、小结

flutter开发实战-旋转loading指示器,使用交织动画(Stagger Animation)实现。

学习记录,每天不停进步。

相关推荐
2601_9498477517 小时前
Form-data 跨端三方库仓颉适配全流程
前端·javascript·flutter
大龄秃头程序员19 小时前
Flutter 中我为什么把 GetX 定位为高效率方案,而不是默认架构方案
flutter
传奇开心果编程1 天前
组合优先开发范式:从汉字造字原理到声明式UI组件组合思想
android·flutter·ios·swiftui·移动开发·harmonyos·android jetpack
2501_944521591 天前
Ramda 跨端三方库仓颉适配全流程
开发语言·javascript·flutter·php
大龄秃头程序员2 天前
Flutter 架构里总被混淆的 IoC、DI、Service Locator,到底是什么关系?
flutter
事圆则缓2 天前
Flutter 与原生交互的最后一层:RTC 视频帧怎么走
flutter·音视频·实时音视频
2601_949847752 天前
jose 跨端三方库仓颉适配全流程
前端·javascript·flutter
2601_949970692 天前
msgpackr 跨端三方库仓颉适配全流程
前端·javascript·flutter
2601_949970692 天前
HumanizeDuration 跨端三方库仓颉适配全流程
前端·javascript·flutter
传奇开心果编程2 天前
【Flutter踩坑排雷】第3课:const 误用坑|const 错误使用引发 UI 异常与性能损耗
flutter·移动开发·跨平台·dart·编程语言理论·编程框架·声明式ui