Breakpoint.fromConstraints constructor
Breakpoint.fromConstraints(
- BoxConstraints constraints, {
- BreakType type = BreakType.material,
- int? columnInterval,
- double? minColumnSize,
Create breakpoint data from the current box constraints that are passed in.
The default type BreakType.material follows the Material Design Guide
https://material.io/design/layout/responsive-layout-grid.html#grid-behavior
The optional layout BreakType.large has smaller gutters
and more columns (24) and more column distribution. It also includes
watch and large desktop classes suitable for 4 screen.
Use a layout builder to get BoxConstraints
Implementation
factory Breakpoint.fromConstraints(
BoxConstraints constraints, {
BreakType type = BreakType.material,
int? columnInterval,
double? minColumnSize,
}) {
/// The predefined amount of columns for the BreakType for a given width
/// will be returned if columnsInterval is null or minColumnSize is null.
assert(
columnInterval == null || (columnInterval >= 1 && columnInterval <= 24),
'columnInterval must be null or from 1 to 24');
assert(
minColumnSize == null ||
(minColumnSize >= 137 / 2 && minColumnSize <= 8192),
'MinColumnSize must be null or from 137/2 (=two columns on a small watch) '
' to 8192 (=1 column on a 8k screen)');
double width = 359;
Orientation orientation = Orientation.portrait;
if (constraints.debugAssertIsValid()) {
width = constraints.normalize().maxWidth;
orientation = constraints.maxHeight > constraints.maxWidth
? Orientation.portrait
: Orientation.landscape;
}
return type == BreakType.material
? Breakpoint._calcBreakpoint(
orientation: orientation,
width: width,
columnInterval: columnInterval,
minColumnSize: minColumnSize,
)
: Breakpoint._calcBreakpointLarge(
orientation: orientation,
width: width,
columnInterval: columnInterval,
minColumnSize: minColumnSize,
);
}