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

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

相关推荐
2603_9494621033 分钟前
Flutter for OpenHarmony社团管理App实战:消息中心实现
android·javascript·flutter
andr_gale1 小时前
08_flutter中如何优雅的提前获取child的宽高
android·flutter
yingdonglan1 小时前
Flutter 框架跨平台鸿蒙开发 ——AnimatedBuilder性能优化详解
flutter·性能优化·harmonyos
程序员清洒1 小时前
Flutter for OpenHarmony:Icon 与 IconButton — 图标系统集成
前端·学习·flutter·华为
时光慢煮1 小时前
打造跨端驾照学习助手:Flutter × OpenHarmony 实战解析
学习·flutter·华为·开源·openharmony
菜鸟小芯1 小时前
【开源鸿蒙跨平台开发先锋训练营】DAY8~DAY13 底部选项卡&首页功能实现
flutter·harmonyos
b2077212 小时前
Flutter for OpenHarmony 身体健康状况记录App实战 - 提醒设置实现
python·flutter·macos·cocoa·harmonyos
2601_949613022 小时前
flutter_for_openharmony家庭药箱管理app实战+药品详情实现
java·前端·flutter
xingfanjiuge3 小时前
Flutter框架跨平台鸿蒙开发——ListView.builder深度解析
flutter·华为·harmonyos
2601_949847753 小时前
Flutter for OpenHarmony 剧本杀组队App实战:邀请好友功能实现
开发语言·javascript·flutter