实现flutter 漂亮加载动画的例子
时间: 2023-07-29 09:05:53 浏览: 163
创建一个漂亮的flutter app
以下是一个漂亮的 Flutter 加载动画的示例,包含了多种不同类型的加载动画,你可以参考实现自己的加载动画。
```dart
import 'package:flutter/material.dart';
class BeautifulLoadingAnimation extends StatefulWidget {
@override
_BeautifulLoadingAnimationState createState() => _BeautifulLoadingAnimationState();
}
class _BeautifulLoadingAnimationState extends State<BeautifulLoadingAnimation>
with SingleTickerProviderStateMixin {
AnimationController _controller;
Animation<Color> _colorTween;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(milliseconds: 2000),
vsync: this,
)..repeat();
_colorTween = _controller.drive(ColorTween(
begin: Colors.red,
end: Colors.blue,
));
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Beautiful Loading Animation'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(
valueColor: _colorTween,
),
SizedBox(height: 20),
LinearProgressIndicator(
valueColor: _colorTween,
),
SizedBox(height: 20),
Stack(
alignment: Alignment.center,
children: [
CircularProgressIndicator(
valueColor: _colorTween,
),
Text(
'Loading',
style: TextStyle(
color: Colors.black,
fontSize: 20,
),
),
],
),
SizedBox(height: 20),
Container(
width: 100,
height: 100,
child: CircularProgressIndicator(
strokeWidth: 10,
valueColor: _colorTween,
),
),
SizedBox(height: 20),
CupertinoActivityIndicator(
radius: 20,
),
],
),
),
);
}
}
```
运行该示例可以看到多种不同类型的加载动画效果。
阅读全文