Breaker
A responsive and adaptive design library built for Flutter.
Features
- Window Breakpoints
- Mobile/Desktop
- Platforms (Android, iOS, Web, Windows, Linux, Mac, etc.)
- Screen Orientation
- Navigation Types (Bottom Bar, Sidebar, etc.)
- Panes Count
- Layout Breakpoints
- Height Breakpoint Ranges (min/max)
- Width Breakpoint Ranges (min/max)
- Body Size Constraint
- Axes Count (Number of columns/rows)
- Margins (Static and Scaling support)
- Axis Spacing
- Material Breakpoints
- Window Class based
- Material 2 responsive layout breakpoints
- Layout builder
- Inherited Models (Window and Layout)
- Vertical Layout Widget
- Grid Layout Widget
- Debug Overlay Widget
Getting started
Import the Breaker package (package:breaker/breaker.dart). For the Material Design implementation, import the material package (package:breaker/material.dart).
For a Window breakpoint system, use the BreakerWindow widget towards the root of the widget tree. Descending widgets can
then depend on the WindowModel by referencing the Breaker static methods:
Widget build(BuildContext context) {
Breaker.device(context); // The device type (mobile, web, desktop).
Breaker.platform(context); // The platform (android, ios, web, linux, macos, windows).
Breaker.orientation(context); // The window orientation.
Breaker.navigation(context); // The breakpoint's navigation type.
Breaker.panes(context); // Number of panes supported by the breakpoint.
}
For the Layout breakpoint system, use the BreakerLayout widget after the BreakerWindow. All descending widgets gain access
to the Layout Breakpoint values. Use the Breaker static methods to access each value.
Widget build(BuildContext context) {
Breaker.body(context); // Fixed body width, or null if the body scales.
Breaker.axes(context); // Number of axes (columns).
Breaker.axisSize(context); // Size of a single axis, excluding spacing.
Breaker.margin(context); // Margin on each side of the body.
Breaker.spacing(context); // Spacing between axes.
}
To build custom layouts with support for the LayoutBreakpoints, use the ResponsiveLayoutBuilder. There are readily
available widgets built with the ResponsiveLayoutBuilder (e.g. ResponsiveVerticalLayout, ResponsiveGridLayout,
and ResponsiveLayoutOverlay).
Both BreakerWindow and every LayoutBreakpoint-based widget above accept an optional fallback breakpoint, used
whenever none of the entries in breakpoints match the current window size or layout constraints. If fallback isn't
supplied, the first breakpoint in the list is used instead — so a gap in your breakpoints never crashes the app, it
just falls back to your smallest/simplest layout.
Widget build(BuildContext context) {
return ResponsiveLayoutBuilder(
breakpoints: materialLayoutBreakpoints,
builder: (context, constraints) {
final body = constraints.body;
final axes = constraints.axes;
final axisSize = constraints.axisSize;
final margin = constraints.margin;
final spacing = constraints.spacing;
return MyResponsiveWidget(...);
},
);
}
Usage
Creating a simple two Breakpoint window breakpoint system with a responsive vertical layout. This will use the readily available
widget ResponsiveVerticalLayout.
import 'package:flutter/material.dart';
import 'package:breaker/breaker.dart';
class MyWindow extends StatelessWidget {
const MyWindow({super.key});
@override
Widget build(BuildContext context) {
return BreakerWindow(
breakpoints: const [
WindowBreakpoint( // Small Screen or Mobile Window
maxWidth: 600,
navigation: NavigationType.bottomBar,
panes: 1
),
WindowBreakpoint( // Anything larger than a Mobile screen
minWidth: 600,
navigation: NavigationType.sideBar,
panes: 2
),
],
child: const MyLayout()
);
}
}
class MyLayout extends StatelessWidget {
const MyLayout({super.key});
@override
Widget build(BuildContext context) {
final panes = Breaker.panes(context);
return ResponsiveVerticalLayout(
debugOverlay: true, // false to remove overlay
breakpoints: const [
LayoutBreakpoint(
maxWidth: 905,
minMargin: 16,
axes: 4,
spacing: 4,
),
LayoutBreakpoint(
minWidth: 905,
body: 840,
minMargin: 32,
axes: 12,
spacing: 12,
),
],
cells: [
if (panes == 1)
Cell(
span: (constraints) => constraints.axes.toInt(),
child: Column(
children: [
Flexible(child: Placeholder(color: Colors.blue, strokeWidth: 4)),
SizedBox(height: 4),
Flexible(child: Placeholder(color: Colors.red, strokeWidth: 4)),
],
),
),
if (panes == 2)
Cell(
span: (constraints) => (constraints.axes / 2).toInt(),
child: Placeholder(color: Colors.blue, strokeWidth: 4),
),
if (panes == 2)
Cell(
span: (constraints) => (constraints.axes / 2).toInt(),
child: Placeholder(color: Colors.red, strokeWidth: 4),
),
],
);
}
}
Breakpoints are evaluated in list order and the first match wins; ranges are inclusive, so adjacent
breakpoints can share a boundary value (e.g. maxWidth: 600 and minWidth: 600).
Neither breakpoint list above needs to cover every possible width/height: pass a fallback: breakpoint to
BreakerWindow or ResponsiveVerticalLayout to control what's used when nothing matches, or omit it to fall back to
the first breakpoint in the list.
Material
The Material Design breakpoint systems are also available in the breaker/material.dart package. Change from the standard
breaker/breaker.dart package and reference the available materialWindowBreakpoints and materialLayoutBreakpoints.
The window breakpoints follow the Material window size classes and the layout breakpoints follow the Material
responsive layout grid.
import 'package:flutter/material.dart';
import 'package:breaker/material.dart';
class MyWindow extends StatelessWidget {
const MyWindow({super.key});
@override
Widget build(BuildContext context) {
return BreakerWindow(
breakpoints: materialWindowBreakpoints,
child: const MyLayout()
);
}
}
class MyLayout extends StatelessWidget {
const MyLayout({super.key});
@override
Widget build(BuildContext context) {
final panes = Breaker.panes(context);
return ResponsiveVerticalLayout(
debugOverlay: true, // false to remove overlay
breakpoints: materialLayoutBreakpoints,
cells: [
if (panes == 1)
Cell(
span: (constraints) => constraints.axes.toInt(),
child: Column(
children: [
Flexible(child: Placeholder(color: Colors.blue, strokeWidth: 4)),
SizedBox(height: 4),
Flexible(child: Placeholder(color: Colors.red, strokeWidth: 4)),
SizedBox(height: 4),
Flexible(child: Placeholder(color: Colors.green, strokeWidth: 4)),
],
),
),
if (panes == 2)
Cell(
span: (constraints) => (constraints.axes / 2).toInt(),
child: Column(
children: [
Flexible(child: Placeholder(color: Colors.blue, strokeWidth: 4)),
SizedBox(height: 4),
Flexible(child: Placeholder(color: Colors.red, strokeWidth: 4)),
],
),
),
if (panes == 2)
Cell(
span: (constraints) => (constraints.axes / 2).toInt(),
child: Placeholder(color: Colors.green, strokeWidth: 4),
),
if (panes == 3)
Cell(
span: (constraints) => (constraints.axes / 3).toInt(),
child: Placeholder(color: Colors.blue, strokeWidth: 4),
),
if (panes == 3)
Cell(
span: (constraints) => (constraints.axes / 3).toInt(),
child: Placeholder(color: Colors.red, strokeWidth: 4),
),
if (panes == 3)
Cell(
span: (constraints) => (constraints.axes / 3).toInt(),
child: Placeholder(color: Colors.green, strokeWidth: 4),
),
],
);
}
}