-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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 sample code for AutomaticKeepAliveClientMixin. #154049
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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.
Hi @SohanRaidev welcome! Thanks for contributing!
We put sample code in examples/api/lib and then embed them in the docs. Look for {@tool dartpad}
for an example.
Thanks!
This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
e2f15fb
to
e36c795
Compare
e36c795
to
056c40f
Compare
Hi @Piinks , Thank you for the warm welcome and the guidance! I’ve added the necessary example code to the examples/api/lib directory and embedded it in the documentation. I followed the pattern with {@tool dartpad} for embedding the examples. If there’s anything else needed or if you have further feedback, please let me know! Thanks again! |
(triage): Looks like this is failing some checks. Can you please take a look and address those issues? Thank you! |
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.
Hey @SohanRaidev thanks for the updates, as well as your patience while I was out of town.
I don't know that we need this many samples. We could also reference some of the existing samples like list_view.1.dart or page_view.1.dart.
All new samples should have tests to verify they work as expected.
Can you also take a look at the failing checks here?
examples/api/lib/widgets/automatic_keep_alive/automatic_keep_alive.0.dart
Outdated
Show resolved
Hide resolved
examples/api/lib/widgets/automatic_keep_alive/automatic_keep_alive.0.dart
Outdated
Show resolved
Hide resolved
examples/api/lib/widgets/automatic_keep_alive/automatic_keep_alive.0.dart
Outdated
Show resolved
Hide resolved
examples/api/lib/widgets/automatic_keep_alive/automatic_keep_alive.0.dart
Outdated
Show resolved
Hide resolved
examples/api/lib/widgets/automatic_keep_alive/automatic_keep_alive_client_mixin.0.dart
Outdated
Show resolved
Hide resolved
examples/api/lib/widgets/automatic_keep_alive/automatic_keep_alive_client_mixin.0.dart
Outdated
Show resolved
Hide resolved
...ib/widgets/automatic_keep_alive/sliver_child_builder_delegate_add_automatic_keep_alives.dart
Outdated
Show resolved
Hide resolved
...i/lib/widgets/automatic_keep_alive/sliver_child_list_delegate_add_automatic_keep_alives.dart
Outdated
Show resolved
Hide resolved
(triage) Hi @SohanRaidev , are you still plan to come back to this pr? |
@SohanRaidev it looks like there are some failing tests here, can you take a look? Thanks! |
e15a07e
to
70a02a2
Compare
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.
Hi @SohanRaidev, thanks so much for contributing!
I've been wanting to look into the KeepAlive APIs a bit more, so I feel lucky to have found this :)
At this point, it looks like the number of test files does not match the number of example files. I also saw that Linux Analyze is reporting a few problems:
info • Sort directive sections alphabetically • examples/api/test/widgets/automatic_keep_alive/automatic_keep_alive.0_test.dart:6:1 • directives_ordering
info • Unnecessary use of parentheses • examples/api/test/widgets/automatic_keep_alive/automatic_keep_alive.0_test.dart:50:33 • unnecessary_parenthesis
info • Unnecessary use of parentheses • examples/api/test/widgets/automatic_keep_alive/automatic_keep_alive.0_test.dart:69:33 • unnecessary_parenthesis
info • Missing a newline at the end of the file • examples/api/test/widgets/automatic_keep_alive/automatic_keep_alive.0_test.dart:103:2 • eol_at_end_of_file
Overall, I think we'd probably have a smoother review process we start with a pull request that just introduces 1 example. But if you don't mind putting a whole bunch of work in here, then that's fine with me!
examples/api/lib/widgets/automatic_keep_alive/automatic_keep_alive.0.dart
Outdated
Show resolved
Hide resolved
examples/api/lib/widgets/automatic_keep_alive/automatic_keep_alive_client_mixin.0.dart
Outdated
Show resolved
Hide resolved
return ListTile( | ||
title: Text('Item ${widget.index}'), | ||
subtitle: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
Text('Keep me alive: $_keepAlive'), | ||
ElevatedButton( | ||
onPressed: () { | ||
setState(() { | ||
_keepAlive = !_keepAlive; | ||
updateKeepAlive(); // Important to call to update the keep-alive status | ||
}); | ||
}, | ||
child: const Text('Toggle Keep Alive'), | ||
), | ||
], | ||
), | ||
); |
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 have a little bit of an issue here: when wantKeepAlive
is switched to false, it doesn't look any different from when the widget is first created, so there's no way to visually tell whether it's behaving correctly.
examples/api/lib/widgets/automatic_keep_alive/automatic_keep_alive_client_mixin.0.dart
Outdated
Show resolved
Hide resolved
// The default value of addAutomaticKeepAlives is true, so we can remove it | ||
// Set to false to observe the loss of state in each item when scrolled | ||
// out of view. Selected items will revert to their default state if false. |
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 a way to select an item. Maybe an onTap
callback could be added to the list tile?
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 think it'd be nice if there were some meaningful differences between this file and the one above, aside from whether it uses List<Widget>.generate()
.
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 tried running this sample and got the following error:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.
The ParentDataWidget KeepAlive(keepAlive: true) wants to apply ParentData of type
KeepAliveParentDataMixin to a RenderObject, which has been set up to accept ParentData of
incompatible type ParentData.
Usually, this means that the KeepAlive widget has the wrong ancestor RenderObjectWidget. Typically,
KeepAlive widgets are placed directly inside SliverWithKeepAliveWidget or TwoDimensionalViewport
widgets.
The offending KeepAlive is currently placed inside a RepaintBoundary widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
Semantics ← _FocusInheritedScope ← Focus ← _ActionsScope ← Actions ← _ParentInkResponseProvider ←
_InkResponseStateWidget ← InkWell ← ListTile ← ListItem ← ⋯
…live.0.dart Co-authored-by: Nate Wilson <nathan.wilson1232@gmail.com>
…live_client_mixin.0.dart Co-authored-by: Nate Wilson <nathan.wilson1232@gmail.com>
…live_client_mixin.0.dart Co-authored-by: Nate Wilson <nathan.wilson1232@gmail.com>
Fixes #153860
Fixes #146612
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.