Coder Social home page Coder Social logo

rickypid / widget_tree_depth_counter Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 1.0 98 KB

Widget to count the amount of nested widget tree, useful in the dynamic construction of the interface when it is important to know the depth of widget.

Home Page: https://pub.dev/packages/widget_tree_depth_counter

License: BSD 3-Clause "New" or "Revised" License

Dart 100.00%
flutter flutter-package widget pubdev package dart flutter-packages widget-tree nested nested-widgets

widget_tree_depth_counter's Introduction

widget_tree_depth_counter

Widget Tree Depth Counter

Pub Package Pub Points Pub Likes

Package Issue Package License

WidgetTreeDepthCounter is a simple widget to count the amount of nested widget tree, useful in the dynamic construction of the interface when it is important to know the depth of widget.

Image
WidgetTreeDepthCounter

Features

  • count of the depth of the widget with respect to the tree (all uses of WidgetTreeDepthCounter in the current tree are counted, the other types of widgets are not counted)

This widget can be used conveniently in such cases:

  • Dynamically manage the colors of widgets based on their position in the tree

  • in an app that manages chapter numbers it is very easy to renumber them in case a chapter is removed.

  • ...

    Many other cases where it is very difficult to manage a widget through fixed parameters to be managed based on the construction of the tree.

 

Usage

Make sure to check out the examples on GitHub.

Image
Example of operation in a widget tree

Installation

From pubspec.yaml

Add the following line to pubspec.yaml:

dependencies:
  widget_tree_depth_counter: <last-release>

and

flutter pub get

From cli

run following command:

flutter pub add widget_tree_depth_counter

Basic setup

Complete example available here.

ParentWidget(
  child: WidgetTreeDepthCounter(
    builder: (context, counter) => //counter=0
      Container(
        color: Theme.of(context)
          .primaryColor
          .withOpacity(counter * 0.05 + 0.05),
          child: WidgetTreeDepthCounter(
            builder: (context, counter) =>//counter=1
                Container(
                    color: Theme.of(context)
                    .primaryColor
                        .withOpacity(counter * 0.05 + 0.05),
                ),
          ),
      ),
  ),
),

WidgetTreeDepthCounter Properties

  • builder: Function called at layout time to construct the widget tree, return Widget.
  • count: With this parameter it's possible define or overwrite the current depth count value.

 

Use current counter value during build WidgetTreeDepthCounter

WidgetTreeDepthCounter uses Provider library to count the depth, but if it is necessary to access the current value to perform a sum (for example), it is possible to retrieve the count value through the `Provider 'functions:

WidgetTreeDepthCounter(
			count: context.read<DepthCounter>().value + 2,
            builder: (context, counter) =>
                Text(counter.toString()),
          )

Obviously to access the value via context.read<DepthCounter>() it is necessary that at least one WidgetTreeDepthCounter is present in the tree and provider package is required.

 

📚 My open source projects

Flutter

Package Verison Score Likes Test Coverage
Pub Package Pub Points Pub Likes
Pub Package Pub Points Pub Likes
Pub Package Pub Points Pub Likes
Pub Package Pub Points Pub Likes

Dart

Package Verison Score Likes Test Coverage
Pub Package Pub Points Pub Likes Test CI codecov
Pub Package Pub Points Pub Likes Test CI codecov

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.