Viewing version 1.0.0. Open the latest package page.
nested
1.0.0A Flutter Widget which helps nest multiple widgets without needing to manually nest them.
Readme
pub package ci
A widget that simplifies the syntax for deeply nested widget trees.
Motivation
Widgets tend to get pretty nested rapidly. It's not rare to see:
MyWidget(
child: AnotherWidget(
child: Again(
child: AndAgain(
child: Leaf(),
)
)
)
)
That's not very ideal.
There's where nested propose a solution.
Using nested, it is possible to flatten the previous tree into:
Nested(
children: [
MyWidget(),
AnotherWidget(),
Again(),
AndAgain(),
],
child: Leaf(),
),
That's a lot more readable!
Usage
Nested relies on a new kind of widget: SingleChildWidget, which has two
concrete implementation:
These are SingleChildWidget variants of the original Stateless/StatefulWidget.
The difference between a widget and its single-child variant is that they have
a custom build method that takes an extra parameter.
As such, a StatelessWidget would be:
class MyWidget extends StatelessWidget {
MyWidget({Key key, this.child}): super(key: key);
final Widget child;
@override
Widget build(BuildContext context) {
return SomethingWidget(child: child);
}
}
Whereas a SingleChildStatelessWidget would be:
class MyWidget extends SingleChildStatelessWidget {
MyWidget({Key key, Widget child}): super(key: key, child: child);
@override
Widget buildWithChild(BuildContext context, Widget child) {
return SomethingWidget(child: child);
}
}
This allows our new MyWidget to be used both with:
MyWidget(
child: AnotherWidget(),
)
and to be placed inside children of [Nested] like so:
Nested(
children: [
MyWidget(),
...
],
child: AnotherWidget(),
)
Changelog
1.0.0
First stable release of Nested (with null safety)
0.0.5-nullsafety.0
- Support null-safety (Thanks to @vishna!)
0.0.4
- Handle reorder through
GlobalKeys
0.0.3
- Made the element of Stateless/Stateful variants public
0.0.2
- Added the ability to implement
SingleChildWidgetusing mixins - Added support for
InheritedWidget(only using mixins).
0.0.1
Initial release
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add 'nested:1.0.0'pubspec.yaml
name: nested
description: >-
A Flutter Widget which helps nest multiple widgets without
needing to manually nest them.
version: 1.0.0
repository: https://github.com/rrousselGit/nested
environment:
sdk: ">=2.12.0-0 <3.0.0"
dependencies:
flutter:
sdk: flutter
dev_dependencies:
flutter_test:
sdk: flutterVersion history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.1 | On demand | Download | 56e3d4a2…78b704 |
| 0.0.2 | On demand | Download | ad261a41…e52c44 |
| 0.0.3 | On demand | Download | f3e72fef…9a5b0d |
| 0.0.4 | On demand | Download | d3492747…aa6be5 |
| 0.0.5-nullsafety.1 | On demand | Download | 1ff55e0b…94b107 |
| 0.0.5 | On demand | Download | 73f5b0f9…a8b554 |
| 1.0.0 | Cached · Upstream SHA-256 matched | Download | 03bac4c5…cd2a20 |
Dependencies
flutter {
"sdk": "flutter"
}