bouncing_ball 0.0.1 copy "bouncing_ball: ^0.0.1" to clipboard
bouncing_ball: ^0.0.1 copied to clipboard

A simple physics engine for ball movement with gravity, friction, and elasticity.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:bouncing_ball/bouncing_ball.dart';

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

class MyApp extends StatelessWidget {
  final double ballHeightAndWidth = 80;

  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,

      home: Scaffold(
        body: Center(
          child: BouncingBall(
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height,
            gravity: 0.2,
            dt: 1,
            isCircle: true,
            // friction: 0.9,
            ballSize: ballHeightAndWidth * 0.9,
            ball: Container(
              decoration: BoxDecoration(
                color: Colors.greenAccent,
                shape: BoxShape.circle,
              ),
              height: ballHeightAndWidth,
              width: ballHeightAndWidth,
            ),
            blockers: [
              PositionedBlocker(
                x: 100,
                y: 600,
                width: 100,
                height: 100,
                child: Container(
                  width: 100,
                  height: 100,
                  decoration: BoxDecoration(
                    color: Colors.red,
                    shape: BoxShape.circle,
                  ),
                ),
              ),
              PositionedBlocker(
                x: 100,
                y: 250,
                width: 200,
                height: 10,
                child: Container(width: 200, height: 10, color: Colors.green),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
3
likes
160
points
38
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A simple physics engine for ball movement with gravity, friction, and elasticity.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, vector_math

More

Packages that depend on bouncing_ball