Unverified Commit 0f465e5b authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Revert "update ScrollMetricsNotification (#87421)" (#87693)

This reverts commit 52bf9dbb.
parent c38feb3b
...@@ -558,7 +558,7 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics { ...@@ -558,7 +558,7 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
// It isn't safe to trigger the ScrollMetricsNotification if we are in // It isn't safe to trigger the ScrollMetricsNotification if we are in
// the middle of rendering the frame, the developer is likely to schedule // the middle of rendering the frame, the developer is likely to schedule
// a new frame(build scheduled during frame is illegal). // a new frame(build scheduled during frame is illegal).
if (!_haveScheduledUpdateNotification) { if (_lastMetrics != null && !_haveScheduledUpdateNotification) {
scheduleMicrotask(didUpdateScrollMetrics); scheduleMicrotask(didUpdateScrollMetrics);
_haveScheduledUpdateNotification = true; _haveScheduledUpdateNotification = true;
} }
......
...@@ -1224,16 +1224,25 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv ...@@ -1224,16 +1224,25 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv
@override @override
void didChangeDependencies() { void didChangeDependencies() {
super.didChangeDependencies(); super.didChangeDependencies();
assert(_debugScheduleCheckHasValidScrollPosition()); _maybeTriggerScrollbar();
} }
bool _debugScheduleCheckHasValidScrollPosition() { // Waits one frame and cause an empty scroll event (zero delta pixels).
if (!showScrollbar) //
return true; // This allows the thumb to show immediately when isAlwaysShown is true.
// A scroll event is required in order to paint the thumb.
void _maybeTriggerScrollbar() {
WidgetsBinding.instance!.addPostFrameCallback((Duration duration) { WidgetsBinding.instance!.addPostFrameCallback((Duration duration) {
final ScrollController? scrollController = widget.controller ?? PrimaryScrollController.of(context);
if (showScrollbar) {
_fadeoutTimer?.cancel();
// Wait one frame and cause an empty scroll event. This allows the
// thumb to show immediately when isAlwaysShown is true. A scroll
// event is required in order to paint the thumb.
assert(_debugCheckHasValidScrollPosition()); assert(_debugCheckHasValidScrollPosition());
scrollController!.position.didUpdateScrollPositionBy(0);
}
}); });
return true;
} }
void _validateInteractions(AnimationStatus status) { void _validateInteractions(AnimationStatus status) {
...@@ -1356,8 +1365,7 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv ...@@ -1356,8 +1365,7 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
if (widget.isAlwaysShown != oldWidget.isAlwaysShown) { if (widget.isAlwaysShown != oldWidget.isAlwaysShown) {
if (widget.isAlwaysShown == true) { if (widget.isAlwaysShown == true) {
assert(_debugScheduleCheckHasValidScrollPosition()); _maybeTriggerScrollbar();
_fadeoutTimer?.cancel();
_fadeoutAnimationController.animateTo(1.0); _fadeoutAnimationController.animateTo(1.0);
} else { } else {
_fadeoutAnimationController.reverse(); _fadeoutAnimationController.reverse();
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -390,16 +389,9 @@ void main() { ...@@ -390,16 +389,9 @@ void main() {
); );
} }
final FlutterExceptionHandler? handler = FlutterError.onError;
FlutterErrorDetails? error;
FlutterError.onError = (FlutterErrorDetails details) {
error = details;
};
await tester.pumpWidget(viewWithScroll()); await tester.pumpWidget(viewWithScroll());
expect(error, isNotNull); final AssertionError exception = tester.takeException() as AssertionError;
expect(exception, isAssertionError);
FlutterError.onError = handler;
}, },
); );
......
...@@ -21,9 +21,8 @@ void main() { ...@@ -21,9 +21,8 @@ void main() {
); );
} }
await tester.pumpWidget(buildFrame(1200.0)); await tester.pumpWidget(buildFrame(1200.0));
expect(events.length, 1); expect(events.length, 0);
events.clear();
await tester.pumpWidget(buildFrame(1000.0)); await tester.pumpWidget(buildFrame(1000.0));
// Change the content dimensions will trigger a new event. // Change the content dimensions will trigger a new event.
expect(events.length, 1); expect(events.length, 1);
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:flutter/foundation.dart';
import 'package:flutter/src/physics/utils.dart' show nearEqual; import 'package:flutter/src/physics/utils.dart' show nearEqual;
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -1144,12 +1143,6 @@ void main() { ...@@ -1144,12 +1143,6 @@ void main() {
}); });
testWidgets('RawScrollbar.isAlwaysShown asserts that a ScrollPosition is attached', (WidgetTester tester) async { testWidgets('RawScrollbar.isAlwaysShown asserts that a ScrollPosition is attached', (WidgetTester tester) async {
final FlutterExceptionHandler? handler = FlutterError.onError;
FlutterErrorDetails? error;
FlutterError.onError = (FlutterErrorDetails details) {
error = details;
};
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
...@@ -1170,15 +1163,12 @@ void main() { ...@@ -1170,15 +1163,12 @@ void main() {
), ),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final AssertionError exception = tester.takeException() as AssertionError;
expect(error, isNotNull); expect(exception, isAssertionError);
final AssertionError exception = error!.exception as AssertionError;
expect( expect(
exception.message, exception.message,
contains("The Scrollbar's ScrollController has no ScrollPosition attached."), contains("The Scrollbar's ScrollController has no ScrollPosition attached."),
); );
FlutterError.onError = handler;
}); });
testWidgets('Interactive scrollbars should have a valid scroll controller', (WidgetTester tester) async { testWidgets('Interactive scrollbars should have a valid scroll controller', (WidgetTester tester) async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment