-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f472d7d
Showing
21 changed files
with
976 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
**/doc/api/ | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
build/ | ||
|
||
# Android related | ||
**/android/**/gradle-wrapper.jar | ||
**/android/.gradle | ||
**/android/captures/ | ||
**/android/gradlew | ||
**/android/gradlew.bat | ||
**/android/local.properties | ||
**/android/**/GeneratedPluginRegistrant.java | ||
|
||
# iOS/XCode related | ||
**/ios/**/*.mode1v3 | ||
**/ios/**/*.mode2v3 | ||
**/ios/**/*.moved-aside | ||
**/ios/**/*.pbxuser | ||
**/ios/**/*.perspectivev3 | ||
**/ios/**/*sync/ | ||
**/ios/**/.sconsign.dblite | ||
**/ios/**/.tags* | ||
**/ios/**/.vagrant/ | ||
**/ios/**/DerivedData/ | ||
**/ios/**/Icon? | ||
**/ios/**/Pods/ | ||
**/ios/**/.symlinks/ | ||
**/ios/**/profile | ||
**/ios/**/xcuserdata | ||
**/ios/.generated/ | ||
**/ios/Flutter/App.framework | ||
**/ios/Flutter/Flutter.framework | ||
**/ios/Flutter/Flutter.podspec | ||
**/ios/Flutter/Generated.xcconfig | ||
**/ios/Flutter/ephemeral | ||
**/ios/Flutter/app.flx | ||
**/ios/Flutter/app.zip | ||
**/ios/Flutter/flutter_assets/ | ||
**/ios/Flutter/flutter_export_environment.sh | ||
**/ios/ServiceDefinitions.json | ||
**/ios/Runner/GeneratedPluginRegistrant.* | ||
|
||
# Exceptions to above rules. | ||
!**/ios/**/default.mode1v3 | ||
!**/ios/**/default.mode2v3 | ||
!**/ios/**/default.pbxuser | ||
!**/ios/**/default.perspectivev3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: 18116933e77adc82f80866c928266a5b4f1ed645 | ||
channel: stable | ||
|
||
project_type: package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Widget Tree Depth Counter | ||
|
||
## [0.0.1-alpha] | ||
#### [@rickypid](https://github.com/rickypid) | ||
- Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Copyright © 2021 Riccardo Cucia (https://www.rcprogrammer.net/) All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, this | ||
list of conditions and the following disclaimer in the documentation and/or | ||
other materials provided with the distribution. | ||
* Neither the name of Riccardo Cucia nor the names of its contributors may be used to | ||
endorse or promote products derived from this software without specific prior | ||
written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#### widget_tree_depth_counter | ||
# Widget Tree Depth Counter | ||
[![Pub Package](https://img.shields.io/pub/v/widget_tree_depth_counter.svg?style=flat-square)](https://pub.dartlang.org/packages/widget_tree_depth_counter) | ||
[![likes](https://badges.bar/widget_tree_depth_counter/likes)](https://pub.dev/packages/widget_tree_depth_counter/score) | ||
[![popularity](https://badges.bar/widget_tree_depth_counter/popularity)](https://pub.dev/packages/widget_tree_depth_counter/score) | ||
[![pub points](https://badges.bar/widget_tree_depth_counter/pub%20points)](https://pub.dev/packages/widget_tree_depth_counter/score) | ||
|
||
[![Package Issue](https://img.shields.io/github/issues/rickypid/widget_tree_depth_counter)](https://github.com/rickypid/widget_tree_depth_counter/issues) | ||
![Package License](https://img.shields.io/github/license/rickypid/widget_tree_depth_counter) | ||
|
||
`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](https://github.com/rickypid/widget_tree_depth_counter/blob/master/doc/.media/example.jpg?raw=true) | | ||
| :------------: | | ||
| **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](https://github.com/rickypid/widget_tree_depth_counter/tree/master/example). | ||
|
||
| ![Image](https://github.com/rickypid/widget_tree_depth_counter/blob/master/doc/.media/widget_tree_example.jpg?raw=true) | | ||
| :------------: | | ||
| **Example of operation in a widget tree** | | ||
|
||
### Installation | ||
|
||
#### From `pubspec.yaml` | ||
|
||
Add the following line to `pubspec.yaml`: | ||
|
||
```yaml | ||
dependencies: | ||
widget_tree_depth_counter: <last-release> | ||
``` | ||
and | ||
```bash | ||
flutter pub get | ||
``` | ||
|
||
#### From cli | ||
|
||
run following command: | ||
|
||
```bash | ||
flutter pub add provider | ||
``` | ||
|
||
### Basic setup | ||
|
||
*Complete example [available here](https://github.com/rickypid/widget_tree_depth_counter/blob/master/example/lib/main.dart).* | ||
|
||
```dart | ||
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](https://pub.dev/packages/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: | ||
|
||
```dart | ||
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.** | ||
|
||
| ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include: package:flutter_lints/flutter.yaml | ||
|
||
# Additional information about this file can be found at | ||
# https://dart.dev/guides/language/analysis-options |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
**/doc/api/ | ||
**/ios/Flutter/.last_build_id | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
|
||
# Web related | ||
lib/generated_plugin_registrant.dart | ||
|
||
# Symbolication related | ||
app.*.symbols | ||
|
||
# Obfuscation related | ||
app.*.map.json | ||
|
||
# Android Studio will place build artifacts here | ||
/android/app/debug | ||
/android/app/profile | ||
/android/app/release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: b2e05062b6d1d73024bbd42bf974509f9ddfb383 | ||
channel: master | ||
|
||
project_type: app |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class ColoredContainer extends StatelessWidget { | ||
final Color color; | ||
final Widget? child; | ||
final int counter; | ||
|
||
const ColoredContainer( | ||
{Key? key, required this.color, this.child, required this.counter}) | ||
: super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Stack( | ||
children: [ | ||
Container( | ||
color: color, | ||
margin: EdgeInsets.all(20), | ||
child: child, | ||
), | ||
Align( | ||
alignment: Alignment.topLeft, | ||
child: Padding( | ||
padding: const EdgeInsets.only(top: 24, left: 24), | ||
child: Text(counter.toString()), | ||
)), | ||
], | ||
); | ||
} | ||
} |
Oops, something went wrong.