riverpod icon indicating copy to clipboard operation
riverpod copied to clipboard

Add ContainerNode and RiverpodNode to devtool

Open adsonpleal opened this issue 2 years ago • 30 comments

This PR adds support for Flutter DevTools by improving the already present file devtool.dart.

With the changes present here we can more easily get the data needed to present the provider state on Flutter DevTools.

For more information check the discussion here.

The UI that these changes enable is the following:

https://user-images.githubusercontent.com/11666470/174911002-a28792d1-ebca-4c7c-b56e-b88002afdfea.mp4

Soon I will open a PR on devtools with the addition of RiverpodScreen.

adsonpleal avatar Jun 22 '22 20:06 adsonpleal

:wave: Could you add tests for all of this? :pray:

rrousselGit avatar Jun 22 '22 21:06 rrousselGit

👋 Could you add tests for all of this? 🙏

yes! Will do!

adsonpleal avatar Jun 22 '22 22:06 adsonpleal

I haven't forgotten about this. I'll continue the work on my own during August.

rrousselGit avatar Aug 04 '22 13:08 rrousselGit

I haven't forgotten about this. I'll continue the work on my own during August.

cool, so you mean you'll continue this work? I can still work on it if you want, I was just waiting for you comments.

Let me know if you need my help.

Cheers!

adsonpleal avatar Aug 04 '22 18:08 adsonpleal

It'd be great if you could add tests on the devtool PR (not this one, the flutter/devtool repo)

rrousselGit avatar Aug 04 '22 21:08 rrousselGit

It'd be great if you could add tests on the devtool PR (not this one, the flutter/devtool repo)

For sure! I was just waiting to have this API ready to go. I'll add the tests this week.

adsonpleal avatar Aug 08 '22 12:08 adsonpleal

Don't worry about this api. I don't mind much what it looks like, since it's not public.

What matters is that everything is tested

rrousselGit avatar Aug 08 '22 13:08 rrousselGit

@rrousselGit this PR should be ready to be merged, we need to merge it first and create a release since devtools depends on this.

adsonpleal avatar Aug 12 '22 19:08 adsonpleal

Don't worry about this.

For reference, I don't plan on merging this until the devtool PR is ready to merge. These two PRs are intertined. A problem in one would require a change in the other, so they likely need to be merged at the same time.

rrousselGit avatar Aug 12 '22 20:08 rrousselGit

Makes sense!

adsonpleal avatar Aug 12 '22 20:08 adsonpleal

This is looking great!

A small note about the sidebar listing providers:

  • I believe that if the provider specifies a name, showing its type is redundant. Especially since we see its type once we select the provider (in the title of the right part)

  • I think it'd be great if providers coming from a family could list the argument

More specifically, I could see the rendering of family involve two bits.

Assuming we have:

final myProvider = Provider.family<String, int>((ref, id) => 'Hello $id');

...

ref.watch(myProvider(42));

Then I think the rendering could be:


 Containers.       |.   Exposed value
----------------------------------------
myProvider(42)     |   family arg:
                   |   42
                   |. -------- 
                   |. exposed value:
                   |. 'Hello 42'

Also, for the sake of readability, I think that if there's only one root ProviderContainer, we don't need to show it in the list. We could show the root provider directly.

This would remove one level of indentation on the sidebar

If there are multiple roots, we'd need to keep the rendering as it is. But that's fairly rare I think

rrousselGit avatar Aug 13 '22 12:08 rrousselGit

really great insights! I'll work on them! They should be easy to implement, I'll work on an UI and share with you soon.

adsonpleal avatar Aug 15 '22 12:08 adsonpleal

https://user-images.githubusercontent.com/11666470/184650168-4e08a184-e7c5-4fda-9c7c-4276ccd73cd1.mp4

I've made some modifications, WDYT?

What I've changed:

1 - Don't show the container label if there is only one container. 2 - Changed the providers list header to show Providers if there is only one container, otherwise it shows Containers. 3 - Changed how the provider name is rendered, now if the provider is a family provider it also show the argument. Another changes was to remove the type if the provider is named. 4 - Also show the selected provider family argument on the right panel, only if there is one.

adsonpleal avatar Aug 15 '22 14:08 adsonpleal

Nice! That looks great!

Quick note, what is that "StringValue"? Is it a custom class you made as an example? Or is that the object vm_service gives you?
If that's the latter, I'd expect to see the raw string directly.

Also, we'd need to make sure that there's a text wrap if the family arg toString is too long :)

rrousselGit avatar Aug 15 '22 14:08 rrousselGit

Acutally, the video showcases that. Ignore me!

That's awesome, nice work!

rrousselGit avatar Aug 15 '22 14:08 rrousselGit

Quick note: Family args shouldn't be editable. Is that the case here?

rrousselGit avatar Aug 15 '22 14:08 rrousselGit

About the family not being editable:

They are, since I'm using the same viewer as the state. I just tested here and you can just edit a value if it is not final 😞.

I was looking at the instance_viewer that you've made for provider (which is the same that I'm using) and there is no option to disable editing. I could add a flag to the InstanceViewer widget like disableEditing, which defaults to false, this way we won't touch other provider implementations.

WDYT?

adsonpleal avatar Aug 15 '22 14:08 adsonpleal

And about text wrap:

image

just added a way to wrap if there is no room for the name.

adsonpleal avatar Aug 15 '22 14:08 adsonpleal

Sorry I used the wrong word. Rather than text wrap, I think clipping it is better. As in doing myVeryLongProvid...

The sidebar can be expanded anyway, and the provider can be selected to see it in full. I think it's more important to see the full list

Especcially considering objects could override toString and end-up with a very long provider name.

rrousselGit avatar Aug 15 '22 15:08 rrousselGit

I was looking at the instance_viewer that you've made for provider (which is the same that I'm using) and there is no option to disable editing. I could add a flag to the InstanceViewer widget like disableEditing, which defaults to false, this way we won't touch other provider implementations.

WDYT?

SGTM

rrousselGit avatar Aug 15 '22 15:08 rrousselGit

image

changed

adsonpleal avatar Aug 15 '22 18:08 adsonpleal

Epic

A nit point would be to rename 'container" into providerContainer to be more specific. But otherwise LGTM

rrousselGit avatar Aug 15 '22 18:08 rrousselGit

Epic

A nit point would be to rename 'container" into providerContainer to be more specific. But otherwise LGTM

You mean written like ProviderContainer, just like the class?

adsonpleal avatar Aug 15 '22 18:08 adsonpleal

And what about the header? Should we keep Containers or change to ProviderContainers ?

adsonpleal avatar Aug 15 '22 18:08 adsonpleal

You mean written like ProviderContainer, just like the class?

Yes

And what about the header? Should we keep Containers or change to ProviderContainers ?

The header too.

rrousselGit avatar Aug 15 '22 19:08 rrousselGit

image

Done, now I just need to work on the editable flag for InstanceViewer.

adsonpleal avatar Aug 15 '22 19:08 adsonpleal

Perfect. Awesome work

rrousselGit avatar Aug 15 '22 19:08 rrousselGit

done https://github.com/flutter/devtools/pull/4210/commits/392f6b971b21061f61c9f013309bffebb279ffd1, let me know if you think anything can be improved.

adsonpleal avatar Aug 15 '22 19:08 adsonpleal

@adsonpleal do you have a social media or a name that I could share?

I'd like you publicly thank you for your work. 😊

rrousselGit avatar Aug 21 '22 21:08 rrousselGit

I'm one of those weird ones that don't use social media haha. I have a linkedin profile, though. I think you could use it hehe.

adsonpleal avatar Aug 22 '22 21:08 adsonpleal