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

fix: update _floatingActionButtonVisibility only if floatingActionButon is not null #148829

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

Conversation

hello-coder-xu
Copy link
Contributor

Fixed #146736

Pre-launch Checklist

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

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels May 22, 2024
…pdate

* master: (92 commits)
  Add tests for actions.0.dart API example. (flutter#148678)
  Introduce `WidgetStateBorderSide.lerp` (flutter#148122)
  add `default-flavor` field to flutter pubspec, which will be used as the flavor in `flutter build/run` if `--flavor` is not provided (flutter#147968)
  [wiki migration] Pages under docs/postmortems/ (flutter#148798)
  Roll Flutter Engine from e5a73e520e89 to c89defa55801 (2 revisions) (flutter#148812)
  Make hover tests functional and cleanup mouse pointers in Material toggleables (flutter#148808)
  Fix two dimensional viewport unexpected null exception when no child is laid out (flutter#148256)
  Roll Flutter Engine from bc1345b6b50a to e5a73e520e89 (3 revisions) (flutter#148807)
  Add test for undo_history_controller.0.dart (flutter#148205)
  Roll Flutter Engine from a8872c8915a2 to bc1345b6b50a (6 revisions) (flutter#148802)
  Fix test that leaks images. (flutter#148494)
  Fix warnings in `dependency_version_checker.gradle.kts` (flutter#148699)
  [wiki migration] Android team pages (flutter#148585)
  Fix leaky test. (flutter#148788)
  Add DropdownButton.menuWidth (flutter#148125)
  Add test for focus example 2 (flutter#147624)
  Add a migrator to remove `FlutterMultiDexApplication.java` (flutter#148515)
  [wiki migration] Infra team pages (flutter#148718)
  Roll Flutter Engine from 8a352f01e503 to a8872c8915a2 (1 revision) (flutter#148776)
  Fix the output of the CDN test. (flutter#148730)
  ...
@Piinks Piinks self-requested a review May 22, 2024 18:30
@Piinks Piinks force-pushed the fix/_floatingActionButtonVisibilityValue-update branch from e09a2a2 to 05ce0ce Compare May 22, 2024 19:43
@JaffaKetchup
Copy link

JaffaKetchup commented May 22, 2024

This comment (#146736 (comment)) reports an issue of the exact same type at the exact same call stack - but doesn't relate to whether there is a FAB.

Although this might fix the issue with the FAB, I doubt it will fix the root issue, which seems to be in this line:

The change to the ValueNotifier causes a listener on it to fire, which fires another listener, which calls here. This appears to be the setState that causes the issue.

void _handleChange() {
if (!mounted) {
return;
}
setState(() {
// The listenable's state is our build state, and it changed already.
});
}

Interestingly, the mounted check was added in 1d7c680, which doesn't appear to be present on the current beta v3.22.0-0.3.pre. I doubt this check will make a difference, as it's not a set state after disposal issue, but I could be wrong. Can the original issue be reproduced on 'master'?

@hello-coder-xu
Copy link
Contributor Author

This comment (#146736 (comment)) reports an issue of the exact same type at the exact same call stack - but doesn't relate to whether there is a FAB.

Although this might fix the issue with the FAB, I doubt it will fix the root issue, which seems to be in this line:

The change to the ValueNotifier causes a listener on it to fire, which fires another listener, which calls here. This appears to be the setState that causes the issue.

void _handleChange() {
if (!mounted) {
return;
}
setState(() {
// The listenable's state is our build state, and it changed already.
});
}

Interestingly, the mounted check was added in 1d7c680, which doesn't appear to be present on the current beta v3.22.0-0.3.pre. I doubt this check will make a difference, as it's not a set state after disposal issue, but I could be wrong. Can the original issue be reproduced on 'master'?

I use the latest master, the problem still exists

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 3.22.0-44.0.pre.10, on macOS 12.5.1 21G83 darwin-arm64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[!] Xcode - develop for iOS and macOS (Xcode 14.2)
    ! Flutter recommends a minimum Xcode version of 15.
      Download the latest version or update via the Mac App Store.
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.3)
[✓] VS Code (version 1.89.1)
[✓] Connected device (3 available)
[✓] Network resources

! Doctor found issues in 1 category.

@hello-coder-xu
Copy link
Contributor Author

I merged and formatted the code

Copy link

@JaffaKetchup JaffaKetchup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I stated above, I'm not sure this PR fixes the underlying issue, and if it is merged, I will likely have to open another issue that's pretty much exactly the same.

Comment on lines 3244 to 3246
if (scaffold.widget.floatingActionButton != null) {
scaffold._floatingActionButtonVisibilityValue = 1.0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might just be hacking around the problem and not addressing the root cause, but I'll defer to @Piinks.

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.

I agree with @JaffaKetchup and @justinmc. This does not appear to fix the root issue since it is not dependent on the presence of the FAB.

@hello-coder-xu if you would like to continue working on this, one idea may be to create a test case where this issue reproduces without a FAB. That way if the test passes, we'll know that the primary issue here is fixed.

@JaffaKetchup
Copy link

JaffaKetchup commented May 30, 2024

I'm happy to create an MRE of my case that doesn't use a FAB, but it might take a little while to boil down from what I've got right now. Would that be helpful?
I'm not good enough with widget tests to write a proper test though!

@JaffaKetchup
Copy link

Here's an MRE. It doesn't do anything complex at all, doesn't even use anything from the DraggableScrollableController, just listens to it using an AnimatedBuilder.

The error occurs when the bottom sheet is expanded, then shrunk to/past its initial height.

void main() {
  final outerBottomSheetController = DraggableScrollableController();

  runApp(
    MaterialApp(
      home: Scaffold(
        body: AnimatedBuilder(
          animation: outerBottomSheetController,
          builder: (context, _) => const SizedBox(),
        ),
        bottomSheet: DraggableScrollableSheet(
          controller: outerBottomSheetController,
          builder: (context, innerScrollController) => ColoredBox(
            color: Colors.black,
            child: ListView.builder(
              controller: innerScrollController,
              itemBuilder: (context, index) => Text(index.toString()),
            ),
          ),
        ),
      ),
    ),
  );
}

@hello-coder-xu
Copy link
Contributor Author

Here's an MRE. It doesn't do anything complex at all, doesn't even use anything from the DraggableScrollableController, just listens to it using an AnimatedBuilder.这是一个 MRE。它根本不做任何复杂的事情,甚至不使用 , DraggableScrollableController 只是使用 AnimatedBuilder .

The error occurs when the bottom sheet is expanded, then shrunk to/past its initial height.当底板展开,然后缩小到/超过其初始高度时,就会发生错误。

void main() {
  final outerBottomSheetController = DraggableScrollableController();

  runApp(
    MaterialApp(
      home: Scaffold(
        body: AnimatedBuilder(
          animation: outerBottomSheetController,
          builder: (context, _) => const SizedBox(),
        ),
        bottomSheet: DraggableScrollableSheet(
          controller: outerBottomSheetController,
          builder: (context, innerScrollController) => ColoredBox(
            color: Colors.black,
            child: ListView.builder(
              controller: innerScrollController,
              itemBuilder: (context, index) => Text(index.toString()),
            ),
          ),
        ),
      ),
    ),
  );
}

Here's an MRE. It doesn't do anything complex at all, doesn't even use anything from the DraggableScrollableController, just listens to it using an AnimatedBuilder.这是一个 MRE。它根本不做任何复杂的事情,甚至不使用 , DraggableScrollableController 只是使用 AnimatedBuilder .

The error occurs when the bottom sheet is expanded, then shrunk to/past its initial height.当底板展开,然后缩小到/超过其初始高度时,就会发生错误。

void main() {
  final outerBottomSheetController = DraggableScrollableController();

  runApp(
    MaterialApp(
      home: Scaffold(
        body: AnimatedBuilder(
          animation: outerBottomSheetController,
          builder: (context, _) => const SizedBox(),
        ),
        bottomSheet: DraggableScrollableSheet(
          controller: outerBottomSheetController,
          builder: (context, innerScrollController) => ColoredBox(
            color: Colors.black,
            child: ListView.builder(
              controller: innerScrollController,
              itemBuilder: (context, index) => Text(index.toString()),
            ),
          ),
        ),
      ),
    ),
  );
}

Yes, I reproduced the problem, and I found another solution, I need some time to verify it

@github-actions github-actions bot added f: scrolling Viewports, list views, slivers, etc. and removed f: material design flutter/packages/flutter/material repository. labels Jun 4, 2024
@hello-coder-xu hello-coder-xu force-pushed the fix/_floatingActionButtonVisibilityValue-update branch from 4e0aaa3 to 3846fea Compare June 6, 2024 06:01
@github-actions github-actions bot added f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. and removed f: scrolling Viewports, list views, slivers, etc. f: material design flutter/packages/flutter/material repository. labels Jun 6, 2024
@hello-coder-xu
Copy link
Contributor Author

I updated it, please check it out

@@ -1746,4 +1746,49 @@ void main() {
areCreateAndDispose,
);
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add back the test you had for the floating action button? That way we know we fixed both scenarios where this bug presented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i updated

@@ -835,7 +835,14 @@ class _DraggableScrollableSheetScrollController extends ScrollController {
curve: Curves.linear,
);
}
extent.updateSize(extent.initialSize, position.context.notificationContext!);
final StatefulElement element = position.context.notificationContext! as StatefulElement;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very different from the earlier fix, can you explain a bit in the PR description what you found as the root issue, and why this fixes it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added description

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, ok, thank you for adding the comment.
This does not look like the right fix to me.

We should not need to be checking whether or not the element is dirty, and further shouldn't be using a post frame callback to initiate the update. It feels like this is working around the root cause of the issue, do you know why we end up here with a dirty element? Tracing this back further will probably reveal the real issue.

@github-actions github-actions bot added the f: material design flutter/packages/flutter/material repository. label Jun 9, 2024
…pdate

* master: (181 commits)
  Fix the scrolling layout deviation of `CupertinoActionSheet` (flutter#149439)
  Roll Flutter Engine from 60a7bb2353b6 to a6aa5d826649 (2 revisions) (flutter#149627)
  Roll Flutter Engine from ea72558be758 to 60a7bb2353b6 (2 revisions) (flutter#149623)
  Place `flutter_gpu` in the package cache. (flutter#149299)
  Switch to triage-* labels for platform package triage (flutter#149614)
  Roll pub packages (flutter#149617)
  Fixes multi line textfield hint text gets ellipsized (flutter#148423)
  Support failures-only and silent reporters in `flutter test` (flutter#148739)
  [CupertinoActionSheet] Fix overflow of the overscroll section when the user scrolls far (flutter#149542)
  Fix InputDecorator.prefixIcon color when disabled (flutter#149595)
  Added filter callback on dropdown menu (flutter#143939)
  update generated localized message files in the stocks test app (flutter#148741)
  Add a simplified SimpleCascadingMenuApp example (flutter#149147)
  Reland "Prevent LayoutBuilder from rebuilding more than once (flutter#147856)" (flutter#149303)
  Move some benchmarks from MotoG4 to Mokey (flutter#149567)
  Roll Packages from d8e8e8cee712 to 11e192a86db3 (2 revisions) (flutter#149596)
  Cleanup triage reports from docs/ (flutter#149545)
  Roll Flutter Engine from d81edf635a9f to ea72558be758 (1 revision) (flutter#149590)
  Roll Flutter Engine from b0f4d7459708 to d81edf635a9f (1 revision) (flutter#149468)
  Roll Flutter Engine from 40b868efcc46 to b0f4d7459708 (1 revision) (flutter#149467)
  ...
@hello-coder-xu hello-coder-xu force-pushed the fix/_floatingActionButtonVisibilityValue-update branch from c4d98fb to 26adfe6 Compare June 9, 2024 17:13
@github-actions github-actions bot removed the f: scrolling Viewports, list views, slivers, etc. label Jun 9, 2024
@github-actions github-actions bot added the f: scrolling Viewports, list views, slivers, etc. label Jun 9, 2024
@dkwingsmt dkwingsmt self-requested a review June 12, 2024 17:36
@@ -835,7 +835,14 @@ class _DraggableScrollableSheetScrollController extends ScrollController {
curve: Curves.linear,
);
}
extent.updateSize(extent.initialSize, position.context.notificationContext!);
final StatefulElement element = position.context.notificationContext! as StatefulElement;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, ok, thank you for adding the comment.
This does not look like the right fix to me.

We should not need to be checking whether or not the element is dirty, and further shouldn't be using a post frame callback to initiate the update. It feels like this is working around the root cause of the issue, do you know why we end up here with a dirty element? Tracing this back further will probably reveal the real issue.

@hello-coder-xu
Copy link
Contributor Author

@Piinks
You're right, I should look for why it's marked dirty, and I'm trying to do that, but I haven't found it yet...
I will continue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
4 participants