Skip to content

Commit

Permalink
Feature/navgation body builder (bdlukaa#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa authored Oct 5, 2021
2 parents e8abc2b + 230cf8e commit 446aba6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -985,12 +987,12 @@ String? comboBoxValue;
SizedBox(
width: 200,
child: ComboBox<String>(
child: Combobox<String>(
header: 'Colors',
placeholder: 'Selected list item',
isExpanded: true,
items: values
.map((e) => ComboboxMenuItem<String>(
.map((e) => ComboboxItem<String>(
value: e,
child: Text(e),
))
Expand Down Expand Up @@ -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 |
Expand Down
37 changes: 32 additions & 5 deletions lib/src/controls/navigation/navigation_view/body.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: prefer_initializing_formals
part of 'view.dart';

/// A helper widget that implements fluent page transitions into
Expand All @@ -13,18 +14,43 @@ class NavigationBody extends StatefulWidget {
const NavigationBody({
Key? key,
required this.index,
required this.children,
required List<Widget> 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<Widget> 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<Widget>? 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.
Expand Down Expand Up @@ -122,7 +148,8 @@ class _NavigationBodyState extends State<NavigationBody> {
},
child: SizedBox(
key: ValueKey<int>(widget.index),
child: widget.children[widget.index],
child: widget.itemBuilder?.call(context, widget.index) ??
widget.children![widget.index],
),
),
);
Expand Down

0 comments on commit 446aba6

Please sign in to comment.