Search packages, repositories and app categories

Package detailsv1.0.0

nested

A Flutter Widget which helps nest multiple widgets without needing to manually nest them.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
5.3M
Likes
350
Pub points
150

Install package

flutter pub add nested

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The nested package is a Flutter utility that simplifies the nesting of multiple widgets by providing a clean, declarative way to compose them without manually writing nested widget structures. It enhances readability and maintainability in complex UI layouts by allowing developers to chain widgets in a more intuitive manner. Ideal for reducing boilerplate in UI code, it supports all major Flutter platforms including Android, iOS, Web, macOS, Windows, and Linux.

Use cases

  • Simplifying complex widget hierarchies
  • Reducing nested widget boilerplate
  • Improving UI code readability
  • Streamlining layout composition
  • Creating reusable widget chains
  • Enhancing maintainability of large UIs

Key features

  • Declarative widget nesting
  • Minimal boilerplate
  • Chainable widget composition
  • Cross-platform support
  • Clean, readable syntax
  • No additional dependencies

Suitable for

  • Developers seeking cleaner UI code
  • Projects with deeply nested widgets
  • Teams prioritizing code maintainability
  • UI-heavy applications
  • Flutter beginners learning composition
  • Experienced developers optimizing layout patterns

Considerations

  • Limited to widget composition only
  • Not a replacement for advanced layout widgets
  • May increase learning curve for new users
  • Best used in conjunction with other layout strategies
  • Does not replace state management
  • Requires understanding of Flutter's widget tree

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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

Categories

Source repository

Projects using this package