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

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

相关推荐
落魄的Android开发4 小时前
FLutter 如何在跨平台下实现国际化多语言开发
flutter
libo_20255 小时前
HarmonyOS5原生开发 vs. Flutter:谁更适合你的项目?
flutter
libo_20255 小时前
ArkTS还是Flutter?HarmonyOS5开发框架选型指南
flutter
libo_20255 小时前
Flutter开发者在HarmonyOS5生态中的优势与局限
flutter
libo_20255 小时前
HarmonyOS5 + Flutter:电商应用全栈开发实战
flutter
叽哥5 小时前
flutter学习第 6 节:按钮与交互组件
android·flutter·ios
libo_20255 小时前
从Flutter到HarmonyOS5:无缝迁移的技术路径
flutter
tangweiguo030519877 小时前
Dart语言“跨界”指南:从JavaScript到Kotlin,如何用多语言思维快速上手
flutter
叽哥8 小时前
flutter学习第 5 节:文本与样式
android·flutter·ios
RaidenLiu9 小时前
Flutter 状态管理:Provider 入门与实战
前端·flutter