Flutter Physics UI

A Flutter package that provides physics-based UI elements using flutter_physics_animation for realistic interactions.

pub package License: MIT

Features

  • Touch Responsive: Elements respond to touch inputs (taps, drags) with physics-based feedback.
  • Gravity Physics: Built-in gravity simulation for realistic weighted interactions.
  • Multi-Platform: Pure Dart implementation that works on iOS, Android, Web, Windows, macOS, and Linux.
  • High Performance: Leverages efficient 2D physics simulation.
  • Customizable: Configure gravity, friction, mass, and restitution (bounciness) via PhysicsProperties.

Platform Support

Platform Support Note
Android
iOS
Web WASM Ready
macOS
Windows
Linux

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  flutter_physics_ui: ^0.1.0

Basic Usage

PhysicsContainer

The core widget for applying physics to any specific UI element.

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

class PhysicsExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: PhysicsContainer(
          physics: const PhysicsProperties(
            gravity: 9.8,
            friction: 0.5,
            mass: 1.0,
          ),
          child: Container(
            width: 100, 
            height: 100, 
            color: Colors.red,
            child: const Center(child: Text('Touch me!')),
          ),
        ),
      ),
    );
  }
}

Pre-built Widgets

  • PhysicsButton: A button that reacts to taps with physics-based feedback (e.g. bounce).
  • PhysicsCard: A card that can be dragged and thrown with inertia.
PhysicsButton(
  onPressed: () => print('Tap!'),
  physics: const PhysicsProperties(restitution: 0.9), // Bouncy
  child: Text('Click Me'),
)

API Reference

PhysicsProperties

Property Default Description
gravity 9.8 Downward acceleration applied to the object.
friction 0.5 Resistance to motion (drag).
mass 1.0 Mass of the object, affecting momentum.
restitution 0.8 Bounciness factor (0.0 = no bounce, 1.0 = full bounce).

License

MIT

Libraries

flutter_physics_ui
A Flutter package providing physics-based UI elements that respond to touch and gravity.