ParticleNetwork class
A Flutter widget that renders an interactive particle network visualization.
This widget creates a dynamic system of particles that:
- Move continuously within the widget bounds using basic physics
- Connect visually when within a specified distance (Euclidean distance)
- Respond to touch interactions when enabled (distance-based highlighting)
- Can be customized through various parameters
Mathematical Concepts Used:
- 2D vector math for particle movement (position + velocity)
- Euclidean distance calculation for connection detection
- Random number generation for initial placement and movement
- Basic collision detection with boundaries
Performance Features:
- Spatial partitioning for efficient neighbor detection (O(n) → O(n log n))
- Cached distance calculations to minimize recomputation
- Batched painting operations to reduce GPU calls
- Configurable repaint strategies based on complexity
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- ParticleNetwork
Constructors
- ParticleNetwork({Key? key, int particleCount = 60, double maxSpeed = 0.5, double maxSize = 1.5, double lineWidth = 0.5, double lineDistance = 100, Color particleColor = Colors.white, Color lineColor = const Color.fromARGB(255, 100, 255, 180), Color touchColor = Colors.amber, bool touchActivation = true, bool isComplex = false, bool fill = true, bool drawNetwork = true, GravityType gravityType = GravityType.none, double gravityStrength = 0.1, Offset gravityDirection = const Offset(0, 1), Offset? gravityCenter})
-
Creates a ParticleNetwork widget with customizable visualization parameters.
const
Properties
- drawNetwork → bool
-
Whether to draw connecting lines between particles
default: true.final - fill → bool
-
Whether to fill particles (true) or stroke them (false)
default: true.final - gravityCenter → Offset?
-
The center point for point-based gravity effects.
Defaults to the widget's center if null.
final
- gravityDirection → Offset
-
The direction vector for global gravity
default: Offset(0, 1) - downwards.final - gravityStrength → double
-
The strength of the applied gravity force
default: 0.1.final - gravityType → GravityType
-
The type of gravity effect to apply
default: GravityType.none.final - hashCode → int
-
The hash code for this object.
no setterinherited
- isComplex → bool
-
Whether the painting logic is complex (affects repaint strategy)
default: false. If true, Flutter may optimize repainting differently.final - key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- lineColor → Color
-
Color of connection lines between particles
default: Color.fromARGB(255, 100, 255, 180). Lines are drawn with opacity based on distance (inverse linear interpolation).final - lineDistance → double
-
Maximum connection distance between particles in pixels
default: 100. Threshold for drawing connecting lines (Euclidean distance).final - lineWidth → double
-
Stroke width of connection lines in pixels
default: 0.5.final - maxSize → double
-
Maximum radius of particles in pixels
default: 1.5. Used for rendering particle size.final - maxSpeed → double
-
Maximum speed of particles in pixels per frame
default: 0.5. Determines how fast particles move (velocity magnitude).final - particleColor → Color
-
Base color of all particles
default: Colors.white.final - particleCount → int
-
Total number of particles in the visualization
default: 60. Affects performance: O(n) for updates, O(n²) for connection checks.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- touchActivation → bool
-
Whether touch interactions are enabled
default: true. Adds gesture detection and touch response logic.final - touchColor → Color
-
Highlight color for touch interactions
default: Colors.amber. Particles near touch point get this color (distance-based).final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< ParticleNetwork> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited