AdaptiveScaffold class

Implements the basic visual layout structure for Material Design 3 that adapts to a variety of screens.

"Example of a display made with AdaptiveScaffold"

AdaptiveScaffold provides a preset of layout, including positions and animations, by handling macro changes in navigational elements and bodies based on the current features of the screen, namely screen width and platform. For example, the navigational elements would be a BottomNavigationBar on a small mobile device or a Drawer on a small desktop device and a NavigationRail on larger devices. When the app's size changes, for example because its window is resized, the corresponding layout transition is animated. The layout and navigation changes are dictated by "breakpoints" which can be customized or overridden.

Also provides a variety of helper methods for navigational elements, animations, and more.

AdaptiveScaffold is based on AdaptiveLayout but is easier to use at the cost of being less customizable. Apps that would like more refined layout and/or animation should use AdaptiveLayout.

AdaptiveScaffold(
 destinations: const [
   NavigationDestination(icon: Icon(Icons.inbox), label: 'Inbox'),
   NavigationDestination(icon: Icon(Icons.article), label: 'Articles'),
   NavigationDestination(icon: Icon(Icons.chat), label: 'Chat'),
   NavigationDestination(icon: Icon(Icons.video_call), label: 'Video'),
 ],
 smallBody: (_) => ListView.builder(
   itemCount: children.length,
   itemBuilder: (_, idx) => children[idx]
 ),
 body: (_) => GridView.count(crossAxisCount: 2, children: children),
),

See also:

Inheritance

Constructors

AdaptiveScaffold({Key? key, required List<NavigationDestination> destinations, int? selectedIndex = 0, Widget? leadingUnextendedNavRail, Widget? leadingExtendedNavRail, Widget? trailingNavRail, WidgetBuilder? smallBody, WidgetBuilder? body, WidgetBuilder? largeBody, WidgetBuilder? smallSecondaryBody, WidgetBuilder? secondaryBody, WidgetBuilder? largeSecondaryBody, double? bodyRatio, Breakpoint smallBreakpoint = Breakpoints.small, Breakpoint mediumBreakpoint = Breakpoints.medium, Breakpoint largeBreakpoint = Breakpoints.large, Breakpoint drawerBreakpoint = Breakpoints.smallDesktop, bool internalAnimations = true, Duration transitionDuration = const Duration(seconds: 1), Axis bodyOrientation = Axis.horizontal, void onSelectedIndexChange(int)?, bool useDrawer = true, PreferredSizeWidget? appBar, double navigationRailWidth = 72, double extendedNavigationRailWidth = 192, Breakpoint? appBarBreakpoint})
Returns a const AdaptiveScaffold by passing information down to an AdaptiveLayout.
const

Properties

appBar PreferredSizeWidget?
Option to override the default AppBar when using drawer in desktop small.
final
appBarBreakpoint Breakpoint?
An optional Breakpoint which overrides the appBar breakpoint to display an AppBar without depending on the drawer visibility.
final
body WidgetBuilder?
Widget to be displayed in the body slot at the middle breakpoint.
final
bodyOrientation Axis
The orientation of the body and secondaryBody. Either horizontal (side by side) or vertical (top to bottom).
final
bodyRatio double?
Defines the fractional ratio of body to the secondaryBody.
final
destinations List<NavigationDestination>
The destinations to be used in navigation items. These are converted to NavigationRailDestinations and BottomNavigationBarItems and inserted into the appropriate places. If passing destinations, you must also pass a selected index to be used by the NavigationRail.
final
drawerBreakpoint Breakpoint
Option to override the drawerBreakpoint for the usage of Drawer over the usual BottomNavigationBar.
final
extendedNavigationRailWidth double
The width used for the internal extended NavigationRail at the large Breakpoint.
final
hashCode int
The hash code for this object.
no setterinherited
internalAnimations bool
Whether or not the developer wants the smooth entering slide transition on secondaryBody.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
largeBody WidgetBuilder?
Widget to be displayed in the body slot at the largest breakpoint.
final
largeBreakpoint Breakpoint
The breakpoint defined for the large size, associated with desktop-like features.
final
largeSecondaryBody WidgetBuilder?
Widget to be displayed in the secondaryBody slot at the largest breakpoint.
final
leadingExtendedNavRail Widget?
Option to display a leading widget at the top of the navigation rail at the largest breakpoint.
final
leadingUnextendedNavRail Widget?
Option to display a leading widget at the top of the navigation rail at the middle breakpoint.
final
mediumBreakpoint Breakpoint
The breakpoint defined for the medium size, associated with tablet-like features.
final
The width used for the internal NavigationRail at the medium Breakpoint.
final
onSelectedIndexChange → void Function(int)?
Callback function for when the index of a NavigationRail changes.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
secondaryBody WidgetBuilder?
Widget to be displayed in the secondaryBody slot at the middle breakpoint.
final
selectedIndex int?
The index to be used by the NavigationRail.
final
smallBody WidgetBuilder?
Widget to be displayed in the body slot at the smallest breakpoint.
final
smallBreakpoint Breakpoint
The breakpoint defined for the small size, associated with mobile-like features.
final
smallSecondaryBody WidgetBuilder?
Widget to be displayed in the secondaryBody slot at the smallest breakpoint.
final
trailingNavRail Widget?
Option to display a trailing widget below the destinations of the navigation rail at the largest breakpoint.
final
transitionDuration Duration
Defines the duration of transition between layouts.
final
useDrawer bool
Whether to use a Drawer over a BottomNavigationBar when not on mobile and Breakpoint is small.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<AdaptiveScaffold>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

emptyBuilder WidgetBuilder
Callback function for when the index of a NavigationRail changes.
getter/setter pair

Static Methods

bottomToTop(Widget child, Animation<double> animation) AnimatedWidget
Animation from bottom offscreen up onto the screen.
fadeIn(Widget child, Animation<double> animation) Widget
Fade in animation.
fadeOut(Widget child, Animation<double> animation) Widget
Fade out animation.
leftInOut(Widget child, Animation<double> animation) AnimatedWidget
Animation from on screen to left off screen.
leftOutIn(Widget child, Animation<double> animation) AnimatedWidget
Animation from left off the screen into the screen.
rightOutIn(Widget child, Animation<double> animation) AnimatedWidget
Animation from right off screen to on screen.
standardBottomNavigationBar({required List<NavigationDestination> destinations, int? currentIndex, double iconSize = 24, Color? backgroundColor, ValueChanged<int>? onDestinationSelected}) Builder
Public helper method to be used for creating a BottomNavigationBar from a list of NavigationDestinations.
standardNavigationRail({required List<NavigationRailDestination> destinations, double width = 72, int? selectedIndex, bool extended = false, Color? backgroundColor, EdgeInsetsGeometry padding = const EdgeInsets.all(8.0), Widget? leading, Widget? trailing, void onDestinationSelected(int)?, double? groupAlignment, IconThemeData? selectedIconTheme, IconThemeData? unselectedIconTheme, TextStyle? selectedLabelTextStyle, TextStyle? unSelectedLabelTextStyle, NavigationRailLabelType labelType = NavigationRailLabelType.none}) Builder
Creates a Material 3 Design Spec abiding NavigationRail from a list of NavigationDestinations.
stayOnScreen(Widget child, Animation<double> animation) Widget
Keep widget on screen while it is leaving
toMaterialGrid({List<Widget> thisWidgets = const <Widget>[], List<Breakpoint> breakpoints = const <Breakpoint>[Breakpoints.small, Breakpoints.medium, Breakpoints.large], double margin = 8, int itemColumns = 1, required BuildContext context}) Builder
Public helper method to be used for creating a staggered grid following m3 specs from a list of Widgets
topToBottom(Widget child, Animation<double> animation) AnimatedWidget
Animation from on the screen down off the screen.
toRailDestination(NavigationDestination destination) NavigationRailDestination
Public helper method to be used for creating a NavigationRailDestination from a NavigationDestination.