51

Is there a way to see how libraries in my Flutter package depend on each other? Under libraries, I mean internal libraries, dart files under 'lib'. Also, it would be great to check for circular dependencies between the libraries.

polina-c
  • 6,245
  • 5
  • 25
  • 36

3 Answers3

117

You can use below command to see your flutter app's dependency graph.

flutter pub deps

The dependency information is printed as a tree, a list, or a compact list.

enter image description here

ibhavikmakwana
  • 8,948
  • 4
  • 20
  • 39
18

I was also looking for a tool to show internal dependencies but couldn't find one. So I wrote a tool called Lakos to visualize Dart/Flutter library dependencies in Graphviz. Lakos will visualize dependencies inside your project, not external package dependencies. Lakos will also warn about dependency cycles with an exit code.

https://pub.dev/packages/lakos

Example usage:

lakos --metrics . | dot -Tpng -Gdpi=200 -o lakos_example.png

The output will look similar to this:

Lakos dependency graph example

Oleg Alexander
  • 909
  • 1
  • 7
  • 11
  • Beautiful! This worked great for me to understand the screens hierarchy of a new project. – Brandon Mar 30 '22 at 22:00
  • This is really great @Oleg Alexander, exactly what I was looking for! However, the graphs tend to get very hairy for larger projects. Is there a way to produce a graph only at the coarser level of subdirectories (I believe you call them "subgraphs" in lakos)? – user18184 May 14 '22 at 12:34
  • 1
    @user18184 Thanks for the kind words. Unfortunately, there's no way to treat the subdirectories as nodes themselves. But you could try rendering the nodes as points, like this: lakos . | dot -Tpng -Gdpi=200 -Nshape=point -o example.png – Oleg Alexander May 14 '22 at 16:35
3

dependency diagram example

LayerLens can continuously auto-generate dependency diagrams for your project.

polina-c
  • 6,245
  • 5
  • 25
  • 36