분류, 패키지 및 저장소 검색

패키지 상세v1.2.2

nester

위젯 목록을 중첩된 위젯 그룹으로 자동으로 변환하는 Flutter 라이브러리입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
39
좋아요
5
Pub 점수
150

패키지 설치

flutter pub add nester

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Nester는 평면적인 위젯 목록을 계층적 그룹으로 자동으로 정리함으로써 중첩된 위젯 구조를 만드는 것을 간소화하는 Flutter 라이브러리입니다. 접을 수 있는 목록이나 다단계 컨테이너와 같은 중첩 레이아웃을 사용하여 복잡한 UI를 만들 때 가독성과 유지보수성을 향상시킵니다. 이 패키지는 Android, iOS, Web, macOS, Windows, Linux 등 모든 주요 플랫폼을 지원하며 크로스플랫폼 개발에 유용합니다. `flutter pub add nester`를 통해 최소한의 설정만으로도 개발자는 위젯 조합 워크플로우를 효율적으로 관리할 수 있습니다.

사용 사례

  • 접을 수 있거나 펼칠 수 있는 중첩 목록 만들기
  • 트리 뷰와 같은 계층적 UI 컴포넌트 만들기
  • 복잡한 위젯 중첩 로직 간소화
  • 동적 UI에서 레이아웃 그룹화 자동화
  • 중첩된 컨테이너 구조에서 반복 코드 줄이기

주요 기능

  • 평탄한 목록에서 위젯을 자동으로 중첩
  • 크로스 플랫폼 배포 지원
  • 필수 최소 구성
  • 계층 구조용 직관적인 API
  • 기존 Flutter 코드와의 원활한 통합

적합한 대상

  • 복잡한 UI 계층 구조를 개발하는 개발자
  • 위젯 중첩 복잡성을 줄이려는 팀
  • 크로스 플랫폼 Flutter 애플리케이션
  • 동적 중첩 레이아웃을 필요로 하는 프로젝트

고려 사항

  • 깊이 중첩된 구조를 위해 신중한 계획이 필요할 수 있습니다
  • 예측 가능한 중첩 패턴에 가장 적합
  • 매우 동적인 또는 런타임에서 변경되는 계층 구조에 적합하지 않음
  • 수동 중첩과 비교하여 사용자 지정이 제한적입니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

nester

Flutter library to convert a list of widgets in a nested group of widgets.
A beautifier plugin to easing your code syntax.

Features

  • Ease the code syntax
  • Can manage like a generic list
  • Can manage like a queue

Installation

  • Add the dependency
dependencies:
  nester: ^1.2.1
  • Import the package
import 'package:nester/nester.dart';

Example Usage

NESTER LIST

Will treated the as simple list. You are allowed to have just one "next" reference for each item in the list. This is the most simple way to use Nester. Recommended when you mostly have "one child" Widget inside your list.

Original code
   return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text("Example"),
        ),
        body: Padding(
          padding: const EdgeInsets.all(20),
          child: Container(
            color: Colors.black12,
            child: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: const <Widget>[Text("Just a description")],
              ),
            ),
          ),
        ),
      );
Using Nester
   return Nester.list([
        (next) => MaterialApp(
              title: 'Flutter Demo',
              theme: ThemeData(primarySwatch: Colors.blue),
              home: next,
            ),
        (next) => Scaffold(
              appBar: AppBar(title: const Text("Example")),
              body: next,
            ),
        (next) => Padding(
              padding: const EdgeInsets.all(20),
              child: next,
            ),
        (next) => Container(
              color: Colors.black12,
              child: next,
            ),
        (next) => Center(child: next),
        (_) => Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: const <Widget>[Text("Just a text")],
            ),
  ]);

NOTE: The last next item in list will be always an empty Container object. So is useless to pass it.


NESTER QUEUE

The Widget list will be treated like a queue. Every "next" calling will consume the next item in the list. This is useful when you using "multi-child" Widgets inside your list.

Original code
   return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: Scaffold(
        appBar: AppBar(
          title: const Text("Example"),
        ),
        body: Padding(
          padding: const EdgeInsets.all(50),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: const [
              Text("Left", textAlign: TextAlign.left),
              Text("Center", textAlign: TextAlign.center),
              Text("Right", textAlign: TextAlign.right),
            ],
          ),
        ),
      ),
    );
Using Nester
    return Nester.queue([
      (next) => MaterialApp(
            title: 'Flutter Demo',
            theme: ThemeData(primarySwatch: Colors.blue),
            home: next(),
          ),
      (next) => Scaffold(
            appBar: next() as PreferredSizeWidget,
            body: next(),
          ),
      (_) => AppBar(title: const Text("Example")),
      (next) => Padding(
            padding: const EdgeInsets.all(50),
            child: next(),
          ),
      (next) => Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: next(take: 3), // or [ next(), next(), next() ],
          ),
      (_) => const Text("Left", textAlign: TextAlign.left),
      (_) => const Text("Center", textAlign: TextAlign.center),
      (_) => const Text("Right", textAlign: TextAlign.right),
    ]);

Skip and Take

The next({int skip, int take}) function accept two parameters.

  • Param skip will skip n calls on the queue list. Note that the function wil NOT check for nested calling, just skip the next n items inside the list. skip will be always applied before take.
  • Param take will consuming n items on the same level. If a item have a nested calling will not count as consumed. The result will be an array of Widgets.

Constraints

  • if skip and take are less than 0 will be considered 0
  • if skip is not null or 0 and take is null an empty Container will be returned.

Throw Range Exception

The queue constructor accept throwRangeException (default: false) to avoid the RangeError check. If true every calling of next then exceed the list boundaries will throw a RangeError exception.

When use take param the resulting array will not exceed the number of remaining items in list. When NOT use take and the next calling exceed the list bounds an empty Container will be returned.


Deep in queue mode

Using of skip and take parameters could create confusion so write some examples to explain better them behavior.

Suppose the have a variable trigger boolean to use to skip some items inside a Column widget.

    return Nester.queue([
      ...,
     (next) => Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              next(skip: trigger ? 0: 2),
              next(),
              next(),
            ]),
      (next) => Padding(..., child: next()),
      (_) => const Text("If trigger true"),
      (_) => const Text("Always show"),
      (_) => const Text("Always show"),
    ]);

OR

    return Nester.queue([
      ...,
     (next) => Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: []
              ..addAll(next(skip: trigger ? 0: 2, take: trigger ? 1: 0))
              ..addAll(next(take: 2)),
            ),
      (next) => Padding(..., child: next()),
      (_) => const Text("If trigger true"),
      (_) => const Text("Always show"),
      (_) => const Text("Always show"),
    ]);

If trigger is true skip 0 and take 1.
If trigger is false skip 2 and take 0.

Why skip = 2?
Because skip will not go inside the tree to check the nested items. Just skip the items on the raw list. So need to skip the next Padding and Text (two items).
Instead take will consume all the item inside the tree. Take 1 it mean consuming the next Padding then will consume the next Text (two items).

Why addAll?
Because when you use take parameter the result will be always an Array of Widgets, also if taking is 0 or 1.


NESTER EXTENDED

A extension of Queue.
Will be treated exactly like queue but extended it adding an extra param in the next function than will allow to pass a dynamic value to the next calling.

    return Nester.extended([
      (next, _) => MaterialApp(
            title: 'Flutter Demo',
            theme: ThemeData(primarySwatch: Colors.blue),
            home: next(),
          ),
      (next, _) => Scaffold(
            appBar: next(param: "Example") as PreferredSizeWidget,
            body: next(),
          ),
      (_, title) => AppBar(title: Text(title)),
      (next, _) => Padding(
            padding: const EdgeInsets.all(50),
            child: next(),
          ),
      (next, _) => Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: next(take: 3, param: ["Left", "Center", "Right"]),
          ),
      (_, param) => Text(param[0], textAlign: TextAlign.left),
      (_, param) => Text(param[1], textAlign: TextAlign.center),
      (_, param) => Text(param[2], textAlign: TextAlign.right),
    ]);

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.