• Stars
    star
    116
  • Rank 294,374 (Top 6 %)
  • Language
    Dart
  • License
    MIT License
  • Created almost 5 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A new kind of widgets that helps building nested widget tree using a linear syntax

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(),
)

More Repositories

1

riverpod

A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
Dart
5,641
star
2

provider

InheritedWidgets, but simple
Dart
5,028
star
3

flutter_hooks

React hooks for Flutter. Hooks are a new kind of object that manages a Widget life-cycles. They are used to increase code sharing between widgets and as a complete replacement for StatefulWidget.
Dart
2,967
star
4

freezed

Code generation for immutable classes that has a simple syntax/API without compromising on the features.
Dart
1,547
star
5

functional_widget

A code generator to write widgets as function without loosing the benefits of classes.
Dart
555
star
6

state_notifier

ValueNotifier, but outside Flutter and with some extra perks
Dart
295
star
7

boundary

Error Boundaries for Flutter
Dart
95
star
8

union

Union types for dart
Dart
84
star
9

todos

Dart
37
star
10

expect_error

A Dart testing utility for asserting that some code emits a compilation error.
Dart
36
star
11

semantic_changelog

Dart
29
star
12

provider-example

Dart
26
star
13

analyzer_plugins

Dart
19
star
14

lazy-broadcast

Dart
17
star
15

sync_stream_controller

Dart
11
star
16

demo_21-01-2019

Dart
9
star
17

ci

A placeholder project to work on a CI for all of my different projects at once
Shell
5
star
18

scroll-behaviors

A set of scroll behaviors for peoples to use.
Dart
2
star
19

meetup-18-10-18

Slides/examples for the 18/10/18 meetup
Dart
2
star
20

hot-restart-expando-reproduction

HTML
2
star
21

vikings

Dart
1
star
22

coverage_regression_example

Dart
1
star
23

coverage_issue_reproduction

Dart
1
star
24

build_runner_bug

Dart
1
star