Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/navgation body builder #77

Merged
merged 6 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
38 changes: 33 additions & 5 deletions lib/src/controls/navigation/navigation_view/body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,45 @@ 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),
// ignore: prefer_initializing_formals
NicolaVerbeeck marked this conversation as resolved.
Show resolved Hide resolved
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)),
// ignore: prefer_initializing_formals
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 +149,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