0 purchases
dart types
Dart Types #
A utility to construct and present the type graph of dart type(s).
The tool is useful to visualize and understand the type hierarchy of a certain library or package.
Currently, the library only supports generating Mermaid graphs.
Features: #
Generate the type graph of given dart type(s) or for given library/libraries
Generate Mermaid code (as code, as url for view, edit or image)
List all types within a path.
Note: generics are ignored at the moment
Installation #
To install the package as a CLI, run the following:
dart pub global activate dart_types
copied to clipboard
Available commands in dart_types:
Global options:
-h, --help Print this usage information.
-v, --[no-]verbose Verbose output
Available commands:
list List the available types in the given `path`
mermaid Generate Mermaid Graph (code, editor url, viewer url, or image url)
Run "dart_types help <command>" for more information about a command
copied to clipboard
Usage for dart_types mermaid
Generate Mermaid Graph (code, editor url, viewer url, or image url)
Usage: dart_types mermaid [arguments]
-h, --help Print this usage information.
-p, --path Specify the path of the file/project where the type(s) are (can be multiple)
-f, --filter filter types using a pattern (can be multiple)
-x, --[no-]ignore-privates Ignore all private types
-t, --type scope the type hierarchy to specific type(s) (can be multiple)
-c, --code print the mermaid graph code
-u, --url generate a url to mermaid.live graph viewer
-e, --url-edit generate a url to mermaid.live graph editor
-i, --url-image generate a url to mermaid.ink graph image
-g, --graph-type Specify the graph type: Top Bottom, Bottom Up, Right Left, Left Right
[TB, BT, RL, LR (default)]
copied to clipboard
Notes: See the example folder for how to use this as a package
Example #
Running the following:
dart_types mermaid --path /path/to/flutter/sdk/packages/flutter/lib --code -ignore-privates --type StatelessWidget
copied to clipboard
Produces the code to the following mermaid graph:
%% To view the graph, copy the code below to:
%% https://mermaid.live/
graph LR
931422573("Object") --> 639058955("Widget")
639058955 --> 464006715("StatelessWidget")
639058955 --> 416054233("PreferredSizeWidget")
464006715 --> 1056914755("Builder")
464006715 --> 262732828("CallbackShortcuts")
464006715 --> 337536055("CheckedModeBanner")
464006715 --> 610219950("Container")
464006715 --> 936772830("DefaultTextEditingShortcuts")
464006715 --> 162789820("DisplayFeatureSubScreen")
464006715 --> 609146547("ExcludeFocus")
464006715 --> 49112299("ExcludeFocusTraversal")
464006715 --> 747420043("GestureDetector")
464006715 --> 146799707("GridPaper")
464006715 --> 902421044("HeroMode")
464006715 --> 742478379("HtmlElementView")
464006715 --> 821894802("Icon")
464006715 --> 679314("ImageIcon")
464006715 --> 599778847("IndexedStack")
464006715 --> 386259944("KeyboardListener")
464006715 --> 756704846("KeyedSubtree")
464006715 --> 341174972("ModalBarrier")
464006715 --> 339198387("NavigationToolbar")
464006715 --> 409547886("OrientationBuilder")
464006715 --> 48107699("PageStorage")
464006715 --> 743848276("Placeholder")
464006715 --> 456230168("PlatformSelectableRegionContextMenu")
464006715 --> 42097335("PositionedDirectional")
464006715 --> 961235098("PreferredSize")
464006715 --> 1065842558("RawMagnifier")
464006715 --> 472365102("ReorderableDragStartListener")
464006715 --> 427683055("SafeArea")
464006715 --> 286068455("ScrollView")
464006715 --> 445477711("SingleChildScrollView")
464006715 --> 126306520("SliverConstrainedCrossAxis")
464006715 --> 592348889("SliverFillRemaining")
464006715 --> 83650908("SliverFillViewport")
464006715 --> 827955045("SliverPersistentHeader")
464006715 --> 378627107("SliverSafeArea")
464006715 --> 716412635("SliverVisibility")
464006715 --> 460084456("Spacer")
464006715 --> 900189511("Text")
464006715 --> 535960679("Title")
464006715 --> 638939478("TwoDimensionalScrollView")
464006715 --> 661441418("UnconstrainedBox")
464006715 --> 521488773("View")
464006715 --> 956347801("ViewAnchor")
464006715 --> 740469611("Visibility")
760877175("BoxScrollView") --> 733462125("GridView")
760877175 --> 167943787("ListView")
416054233 --> 961235098
472365102 --> 721803713("ReorderableDelayedDragStartListener")
286068455 --> 760877175
286068455 --> 257018606("CustomScrollView")
style 464006715 color:#7FFF7F
copied to clipboard
Note: to view the output, paste the graph at: https://mermaid.live
Or alternatively, you can generate a URL directly using the following command:
dart_types mermaid --path /path/to/flutter/sdk/packages/flutter/lib --url -ignore-privates --type StatelessWidget
copied to clipboard
Known Limitation: #
Generics are ignored in generated graphs (in terms of type hierarchy)
Types from external libraries may not appear in the graph as super types in certain cases.
I assume that the analyzer will take advantage of cached analysis to provide super types from external libraries. If those external libraries are not available in the cache, they are ignored (this is unverified observation).
Note: mermaid.live website has a limit of 500 edges.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.