Flutter粒子效果插件particle_forked的使用
Flutter粒子效果插件particle_forked的使用
简介
这个包提供了在Flutter项目中轻松添加粒子动画的方法。
开始使用
首先,确保在你的Flutter项目中添加以下依赖:
dependencies:
particle_forked: "^0.1.1"
然后运行 flutter packages upgrade
或者在IntelliJ中更新你的包。
如何使用
下面是一个完整的示例,展示了如何使用particle_forked
插件创建一个带有粒子动画的屏幕。
import 'package:flutter/material.dart';
import 'package:particle_forked/particle_forked.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(primarySwatch: Colors.blue),
home: Scaffold(
backgroundColor: Colors.black,
body: CircularParticleScreen(),
),
);
}
}
class CircularParticleScreen extends StatelessWidget {
const CircularParticleScreen({Key? key}) : super(key: key);
[@override](/user/override)
Widget build(BuildContext context) {
double screenHeight = MediaQuery.of(context).size.height;
double screenWidth = MediaQuery.of(context).size.width;
return Center(
child: Container(
key: UniqueKey(),
child: Center(
child: CircularParticle(
// 设置粒子的参数
awayRadius: 80, // 粒子远离中心的距离
numberOfParticles: 200, // 粒子的数量
speedOfParticles: 1, // 粒子的速度
height: screenHeight, // 容器的高度
width: screenWidth, // 容器的宽度
onTapAnimation: true, // 是否启用点击动画
particleColor: Colors.white.withAlpha(150), // 粒子的颜色
awayAnimationDuration: Duration(milliseconds: 600), // 远离动画的持续时间
maxParticleSize: 8, // 粒子的最大尺寸
isRandSize: true, // 是否随机大小
isRandomColor: true, // 是否随机颜色
randColorList: [ // 随机颜色列表
Colors.red.withAlpha(210),
Colors.white.withAlpha(210),
Colors.yellow.withAlpha(210),
Colors.green.withAlpha(210)
],
awayAnimationCurve: Curves.easeInOutBack, // 动画曲线
enableHover: true, // 是否启用悬停效果
hoverColor: Colors.white, // 悬停颜色
hoverRadius: 90, // 悬停半径
connectDots: true, // 是否连接点(不推荐)
),
),
),
);
}
}
更多关于Flutter粒子效果插件particle_forked的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复