diff --git a/CHANGELOG.md b/CHANGELOG.md index d88d98463..634b77e28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ Date format: DD/MM/YYYY +## [3.x.x] - Flutter 2.5.0 - [DD/MM/YYYY] + +- Added builder variant to `NavigationBody`. + ## [3.2.0] - Flutter 2.5.0 - [15/09/2021] - Added missing parameters in `_FluentTextSelectionControls` methods ([#67](https://github.com/bdlukaa/fluent_ui/issues/67)) diff --git a/README.md b/README.md index 4781d0e43..ae1c88fb3 100644 --- a/README.md +++ b/README.md @@ -493,10 +493,12 @@ pane: NavigationPane( ### Navigation body -A navigation body is used to implement page transitions into a navigation view. It knows what is the current diplay mode of the parent `NavigationView`, if any, and define the page transitions accordingly. +A navigation body is used to implement page transitions into a navigation view. It knows what is the current display mode of the parent `NavigationView`, if any, and define the page transitions accordingly. For top mode, the horizontal page transition is used. For the others, drill in page transition is used. +You can also supply a builder function to create the pages instead of a list of widgets. For this use the `NavigationBody.builder` constructor. + ```dart int _currentIndex = 0; @@ -985,12 +987,12 @@ String? comboBoxValue; SizedBox( width: 200, - child: ComboBox( + child: Combobox( header: 'Colors', placeholder: 'Selected list item', isExpanded: true, items: values - .map((e) => ComboboxMenuItem( + .map((e) => ComboboxItem( value: e, child: Text(e), )) @@ -1457,7 +1459,7 @@ The list of equivalents between this library and `flutter/material.dart` | - | ToggleButton | | Switch | ToggleSwitch | | TextField | TextBox | -| DropdownButton | ComboBox | +| DropdownButton | Combobox | | - | AutoSuggestBox | | AlertDialog | ContentDialog | | MaterialBanner | InfoBar | diff --git a/lib/src/controls/navigation/navigation_view/body.dart b/lib/src/controls/navigation/navigation_view/body.dart index 264b4f1b2..33242613d 100644 --- a/lib/src/controls/navigation/navigation_view/body.dart +++ b/lib/src/controls/navigation/navigation_view/body.dart @@ -1,3 +1,4 @@ +// ignore_for_file: prefer_initializing_formals part of 'view.dart'; /// A helper widget that implements fluent page transitions into @@ -13,18 +14,43 @@ class NavigationBody extends StatefulWidget { const NavigationBody({ Key? key, required this.index, - required this.children, + required List children, this.transitionBuilder, this.animationCurve, this.animationDuration, }) : assert(index >= 0 && index <= children.length), + children = children, + itemBuilder = null, + itemCount = null, super(key: key); - /// The pages this body can have. - final List children; + /// Creates a navigation body that uses a builder to supply child pages + /// + /// [index] must be greater than 0 and less than [itemCount] if it is provided + const NavigationBody.builder({ + Key? key, + required this.index, + required IndexedWidgetBuilder itemBuilder, + this.itemCount, + this.transitionBuilder, + this.animationCurve, + this.animationDuration, + }) : assert(index >= 0 && (itemCount == null || index <= itemCount)), + itemBuilder = itemBuilder, + children = null, + super(key: key); + + /// The pages this body can have + final List? children; + + /// The builder that will be used to build the pages + final IndexedWidgetBuilder? itemBuilder; + + /// Optional number of items to assume builder can create. + final int? itemCount; /// The current page index. It must be greater than 0 and less - /// than [children.length]. + /// than [children.length] or [itemCount]. final int index; /// The transition builder. @@ -122,7 +148,8 @@ class _NavigationBodyState extends State { }, child: SizedBox( key: ValueKey(widget.index), - child: widget.children[widget.index], + child: widget.itemBuilder?.call(context, widget.index) ?? + widget.children![widget.index], ), ), );