Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions example/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: unused_element

import 'package:flutter/material.dart';
import 'package:flutter_particles/particles.dart';

Expand Down Expand Up @@ -26,7 +28,7 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({Key? key, this.title}) : super(key: key);

// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
Expand All @@ -37,7 +39,7 @@ class MyHomePage extends StatefulWidget {
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".

final String title;
final String? title;

@override
_MyHomePageStateCustom createState() => new _MyHomePageStateCustom();
Expand Down Expand Up @@ -72,4 +74,4 @@ class _MyHomePageStateCustom extends State<MyHomePage> {
),
);
}
}
}
22 changes: 11 additions & 11 deletions lib/draw_particles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_particles/particle.dart';

class DisplayPoints extends CustomPainter {
final List<Particle> particlesList;
final List<Particle>? particlesList;

final double strokeSize;
final double? strokeSize;

DisplayPoints({
this.particlesList,
Expand All @@ -15,26 +15,26 @@ class DisplayPoints extends CustomPainter {
void paint(Canvas canvas, Size size) {
Paint line = new Paint();
line.strokeCap = StrokeCap.round;
line.color = particlesList.elementAt(0).color;
line.color = particlesList!.elementAt(0).color!;

// Draw all the particles
for (var particle in particlesList) {
line.strokeWidth = particle.size;
for (var particle in particlesList!) {
line.strokeWidth = particle.size!;
Offset center = new Offset(particle.xCoor, particle.yCoor);
line.style = PaintingStyle.fill;
canvas.drawCircle(center, particle.size, line);
canvas.drawCircle(center, particle.size!, line);
}

// Draw the connect line
for (int i = 0; i < this.particlesList.length; i++) {
for (int j = i + 1; j < this.particlesList.length; j++) {
Particle particle = this.particlesList.elementAt(i);
Particle anotherParticle = this.particlesList.elementAt(j);
for (int i = 0; i < this.particlesList!.length; i++) {
for (int j = i + 1; j < this.particlesList!.length; j++) {
Particle particle = this.particlesList!.elementAt(i);
Particle anotherParticle = this.particlesList!.elementAt(j);
if (particle.isNear(anotherParticle)) {
Offset firstParticle = new Offset(particle.xCoor, particle.yCoor);
Offset secondParticle =
new Offset(anotherParticle.xCoor, anotherParticle.yCoor);
line.strokeWidth = strokeSize;
line.strokeWidth = strokeSize!;
canvas.drawLine(firstParticle, secondParticle, line);
}
}
Expand Down
26 changes: 14 additions & 12 deletions lib/particle.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
// ignore_for_file: unnecessary_statements

import 'dart:math';

import 'package:flutter/material.dart';

class Particle {
final Color color;
double xCoor;
double yCoor;
final double size;
double xDirection;
double yDirection;
static double widgetWidth;
static double widgetHeight;
final Color? color;
final double yCoor;
final double xCoor;
final double? size;
late double xDirection;
late double yDirection;
static late double widgetWidth;
static late double widgetHeight;
double connectDistance;
Random random = new Random();
double minSpeed;
double maxSpeed;

Particle({
this.color,
this.xCoor,
this.yCoor,
required this.xCoor,
required this.yCoor,
this.size,
this.connectDistance = 100.0,
this.minSpeed = 0.1,
Expand Down Expand Up @@ -54,8 +56,8 @@ class Particle {
this.yCoor + this.yDirection < 0) {
this.yDirection = this.yDirection * (-1);
}
this.xCoor += this.xDirection;
this.yCoor += this.yDirection;
this.xCoor + this.xDirection;
this.yCoor + this.yDirection;
}

double doubleInRange(double start, double end) =>
Expand Down
6 changes: 3 additions & 3 deletions lib/particles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class Particles extends StatefulWidget {

class ParticlesState extends State<Particles>
with SingleTickerProviderStateMixin {
Animation animation;
AnimationController animationController;
Animation? animation;
late AnimationController animationController;
Random random = new Random();

List<Particle> particlesList = new List();
List<Particle> particlesList = [];

void addToParticlesList() {
for (int i = 1; i <= widget.numParticle; i++) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ homepage: https://github.com/Aleadinglight/Flutter-Particles
version: 1.0.0+8

environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'

dependencies:
flutter:
Expand Down