Fix null check for content dimensions in page getter (#87824)

This commit is contained in:
Alexandre Daigle 2021-08-17 18:57:06 -04:00 committed by GitHub
parent 42a6b7913c
commit ddfaec19ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -385,10 +385,12 @@ class _PagePosition extends ScrollPositionWithSingleContext implements PageMetri
@override @override
double? get page { double? get page {
assert( assert(
!hasPixels || (minScrollExtent != null && maxScrollExtent != null), !hasPixels || hasContentDimensions,
'Page value is only available after content dimensions are established.', 'Page value is only available after content dimensions are established.',
); );
return !hasPixels ? null : getPageFromPixels(pixels.clamp(minScrollExtent, maxScrollExtent), viewportDimension); return !hasPixels || !hasContentDimensions
? null
: getPageFromPixels(pixels.clamp(minScrollExtent, maxScrollExtent), viewportDimension);
} }
@override @override

View File

@ -14,6 +14,12 @@ import 'states.dart';
const Duration _frameDuration = Duration(milliseconds: 100); const Duration _frameDuration = Duration(milliseconds: 100);
void main() { void main() {
testWidgets('PageController cannot return page while unattached',
(WidgetTester tester) async {
final PageController controller = PageController();
expect(() => controller.page, throwsAssertionError);
});
testWidgets('PageView control test', (WidgetTester tester) async { testWidgets('PageView control test', (WidgetTester tester) async {
final List<String> log = <String>[]; final List<String> log = <String>[];