hydra 1.1.1
hydra: ^1.1.1 copied to clipboard
Flutter widget which helps building responsive widgets.
Hydra #
Build responsive Flutter widgets with ease. Define up to four layout variants and let Hydra pick the right one based on screen size.
Installation #
flutter pub add hydra
Quick Start #
import 'package:hydra/hydra.dart';
HydraWidget(
mini: const Text('Phone'),
medium: const Text('Tablet'),
large: const Text('Desktop'),
)
Hydra selects the best match for the current screen width. If no exact match exists, it falls back to the nearest available alternative.
Breakpoints #
Default breakpoints: 600 (small), 900 (medium), 1200 (large). Everything below 600 is considered mini.
// Use defaults
HydraWidget(
behaviour: const HydraBehaviour(),
mini: mobileLayout(),
large: desktopLayout(),
)
// Custom breakpoints
HydraWidget(
behaviour: const HydraBehaviour(
breakpointSmall: 480,
breakpointMedium: 768,
breakpointLarge: 1024,
),
small: mobileLayout(),
medium: tabletLayout(),
large: desktopLayout(),
)
// Material Design breakpoints (600 / 840 / 1200)
HydraWidget(
behaviour: const HydraBehaviour.material(),
mini: compactLayout(),
small: mediumLayout(),
large: expandedLayout(),
)
Behaviour Options #
| Constructor | Description |
|---|---|
HydraBehaviour() |
Default: orientation-aware, prefers larger fallback |
HydraBehaviour.preferSmaller() |
Falls back to smaller alternative instead of larger |
HydraBehaviour.noOrientation() |
Uses shortest side regardless of orientation |
HydraBehaviour.material() |
Material Design breakpoints (600/840/1200) |
Orientation Awareness #
By default, Hydra uses MediaQuery.of(context).size.width which changes when the device rotates. Set isOrientationAware: false (or use HydraBehaviour.noOrientation()) to use the shortest side instead — the layout stays consistent regardless of rotation.
How It Works #
- Breakpoint detection — determines the current breakpoint from screen width
- Exact match — looks for a widget registered at that breakpoint
- Nearest fallback — if no exact match, picks the closest available alternative (prefers larger by default, configurable via
isSmallerScreenPreferred)
License #
MIT