-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tab for inspecting the state of package:provider #2851
Conversation
import 'dart:async'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how much functionality are you using from riverpod? Unless it is extensive it could make sense to avoid the dependency for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used extensively
With it, the implementation of the instance viewer is fully declarative, and it takes care of the process of canceling pending evaluations whenever possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Can you point to the pattern that ensures evaluations are cancelled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the "autoDispose" functionality on providers (which package:provider
sadly cannot support)
https://riverpod.dev/docs/concepts/modifiers/auto_dispose
It keeps track of the number of listeners on the associated provider (be it widgets or other providers (such as when chaining providers)). And when all listeners are removed, the provider state will automatically be destroyed.
Then providers can add a dispose method to cancel pending requests. That's the "Disposable" object which all providers use:
AutoDisposeProvider((ref) {
final isAlive = Disposable();
// tell Riverpod to dispose the "Disposable" object when the provider is disposed
ref.onDispose(isAlive.dispose);
// when the provider is destroyed, `isAlive` will be disposed, canceling the pending requests.
await eval.eval('...', isAlive: isAlive);
})
This combines nicely with the collapse functionality too.
All object properties are associated with a unique provider. So when collapsing a property, its listener is removed, its state destroyed and pending requests canceled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This architecture also automatically deals with loading and error handling.
It relies on the fact that using await
throws when the awaited future fails, purposefully letting the exception bubble. Then the provider will catch the exception, and use a union-type to force the UI to deal with loading/errors (or the application otherwise will not compile)
That's the when(loading: ..., error: ..., data: ...)
you can see inside widgets.
); | ||
} | ||
|
||
class _SplitBorder extends StatelessWidget { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you attach an updated screenshot to the CL?
I'm interested in seeing how this widget looks as part of the UI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand out a list and a map in the screenshot and show a screenshot where the hashcodes are fixed or omitted if they are -1.
Hashcodes should also be truncated 5 char hex to match what Flutter does in its debug print.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the split border in the screenshot. I would have expected to see a border that was the focus color.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The split border is the thin grey border
But maybe focusColor
is not the correct variable to use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I skip goldens? Since they generate 0.01% diff, probably due to environment differences. |
Hum interesting that this time they passed |
coming in kind of late here but I thought we agreed to not use |
After discussing with @jacob314 , we agreed to remove the dependency and commit the generated file Those |
Will the .freezed files ever need to be regenerated? Perhaps we could include a comment at the top of the .freezed files that describes how to regenerate these files if necessary |
There is one here: devtools/packages/devtools_app/lib/src/provider/instance_viewer/instance_details.dart Line 16 in 5e81d82
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
color: backgroundColor, | ||
padding: _tilePadding, | ||
child: state.when( | ||
loading: () => const CenteredCircularProgressIndicator(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be good now
Looking good! a few UI requests and then LGTM |
requiresLibrary: 'package:provider/', | ||
title: 'Provider', | ||
requiresDebugBuild: true, | ||
icon: Icons.palette, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel free to change the icon - not sure if this once was listed in the conditional screens example by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, switched to attach_file
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be good to go now |
No description provided.