particular 0.0.5 copy "particular: ^0.0.5" to clipboard
particular: ^0.0.5 copied to clipboard

The Particular is a high performance particle effects flutter widget.

example/lib/main.dart

import 'dart:convert';
import 'dart:ui' as ui;

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image/image.dart' as image;
import 'package:particular/particular.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  // Add controller to change particle
  final _particleController = ParticularController();

  @override
  void initState() {
    _loadParticleAssets();
    super.initState();
  }

  // Load configs and texture of particle
  Future<void> _loadParticleAssets() async {
    // Load json config
    var json = await rootBundle.loadString("assets/meteor.json");
    var configsMap = jsonDecode(json);

    // Load particle texture
    final ByteData assetImageByteData =
        await rootBundle.load("assets/${configsMap["textureFileName"]}");
    image.Image? baseSizeImage =
        image.decodeImage(assetImageByteData.buffer.asUint8List());
    image.Image resizeImage = image.copyResize(baseSizeImage!,
        height: baseSizeImage.width, width: baseSizeImage.height);
    ui.Codec codec =
        await ui.instantiateImageCodec(image.encodePng(resizeImage));
    ui.FrameInfo frameInfo = await codec.getNextFrame();

    _particleController.initialize(
      texture: frameInfo.image,
      configs: configsMap,
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.black,
        body: Column(
          children: [
            GestureDetector(
              onPanUpdate: (details) {
                _particleController.update(
                    emitterX: details.localPosition.dx,
                    emitterY: details.localPosition.dy);
              },
              onTapDown: (details) {
                _particleController.update(
                    emitterX: details.localPosition.dx,
                    emitterY: details.localPosition.dy);
              },
              child: SizedBox(
                width: 600,
                height: 600,
                child: Particular(
                  controller: _particleController,
                ),
              ),
            ),
            TextButton(
              onPressed: () {
                _particleController.update(
                    maxParticles:
                        _particleController.maxParticles > 500 ? 300 : 13000);
              },
              child: ListenableBuilder(
                listenable: _particleController,
                builder: (c, w) =>
                    Text("${_particleController.maxParticles} particles."),
              ),
            )
          ],
        ),
      ),
    );
  }
}
28
likes
0
pub points
58%
popularity

Publisher

unverified uploader

The Particular is a high performance particle effects flutter widget.

Repository (GitHub)
View/report issues

Topics

#particle #particles #visualization #game #effects

Documentation

Documentation

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on particular