Skip to content
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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

SohanRaidev
Copy link

@SohanRaidev SohanRaidev commented Aug 24, 2024

Fixes #153860
Fixes #146612

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Copy link

google-cla bot commented Aug 24, 2024

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.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: scrolling Viewports, list views, slivers, etc. labels Aug 24, 2024
@goderbauer goderbauer requested a review from Piinks August 28, 2024 22:14
Copy link
Contributor

@Piinks Piinks left a 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!

@SohanRaidev SohanRaidev marked this pull request as draft September 4, 2024 08:45
@flutter-dashboard
Copy link

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 package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@github-actions github-actions bot added engine flutter/engine repository. See also e: labels. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos labels Sep 4, 2024
@SohanRaidev SohanRaidev closed this Sep 4, 2024
@SohanRaidev SohanRaidev reopened this Sep 4, 2024
@github-actions github-actions bot removed the engine flutter/engine repository. See also e: labels. label Sep 4, 2024
@SohanRaidev SohanRaidev marked this pull request as ready for review September 4, 2024 19:08
@SohanRaidev
Copy link
Author

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!

@goderbauer
Copy link
Member

(triage): Looks like this is failing some checks. Can you please take a look and address those issues? Thank you!

Copy link
Contributor

@Piinks Piinks left a 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?

@chunhtai
Copy link
Contributor

chunhtai commented Oct 8, 2024

(triage) Hi @SohanRaidev , are you still plan to come back to this pr?

@Piinks
Copy link
Contributor

Piinks commented Oct 22, 2024

@SohanRaidev it looks like there are some failing tests here, can you take a look? Thanks!

Copy link
Member

@nate-thegrate nate-thegrate left a 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!

Comment on lines +68 to +85
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'),
),
],
),
);
Copy link
Member

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.

Comment on lines +38 to +40
// 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.
Copy link
Member

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?

Copy link
Member

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().

Copy link
Member

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 ← ⋯

SohanRaidev and others added 3 commits November 3, 2024 00:22
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
5 participants