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)实现。

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

相关推荐
Bryce李小白2 天前
Flutter 自定义 View 权威指引
flutter
恋猫de小郭2 天前
Fluttercon EU 2025 :Let‘s go far with Flutter
android·开发语言·flutter·ios·golang
SoaringHeart3 天前
Flutter进阶:自定义一个 json 转 model 工具
前端·flutter·dart
许泽宇的技术分享3 天前
Flutter + Ollama:开启本地AI的全平台新纪元 —— 从零剖析一款现代化AI客户端的技术奥秘
人工智能·flutter
molihuan3 天前
开源 全平台 哔哩哔哩缓存视频合并 Github地址:https://github.com/molihuan/hlbmerge_flutter
android·flutter·缓存·ffmpeg·开源·github·音视频
dora4 天前
Flutter中dart和原生代码的通信之MethodChannel
android·flutter
brave7235 天前
Riverpod 3.0.0 版本中 Provider 类型选择指南
flutter
ZFJ_张福杰5 天前
【区块链】Fiat24 深度解读(含 Flutter 集成与 SDK 骨架)
flutter·web3·区块链·钱包
古希腊被code拿捏的神5 天前
【Flutter】抽象类的运用(abstract与implements的实践)
flutter
ZFJ_张福杰5 天前
【Flutter】GetX最佳实践与避坑指南
android·flutter·ios·getx