Repository navigation
Closed
Labels
a: error messageError messages from the Flutter frameworkError messages from the Flutter frameworka: null-safetySupport for Dart's null safety featureSupport for Dart's null safety featurefound in release: 2.3Found to occur in 2.3Found to occur in 2.3frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Description
Facing this for few days now on the latest stable. Haven't found any existing issue so...
Steps to Reproduce
- Run the code below.
Expected results: No crash
Actual results: Null check operator used on a null value
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(home: Page()));
class Page extends StatefulWidget {
@override
_BankAppState createState() => _BankAppState();
}
class _BankAppState extends State<Page> {
late PageController _pageController = PageController();
@override
Widget build(BuildContext context) {
return Scaffold(
body: PageView.builder(
itemCount: 4,
controller: _pageController,
itemBuilder: (context, index) {
// Calling this cause the issue.
debugPrint(_pageController.page.toString());
return Container(color: Colors.primaries[index]);
},
),
);
}
}Logs
Performing hot restart...
Syncing files to device iPhone 12 Pro Max...
Restarted application in 306ms.
======== Exception caught by widgets library =======================================================
The following _CastError was thrown building:
Null check operator used on a null value
When the exception was thrown, this was the stack:
#0 ScrollPosition.minScrollExtent (package:flutter/src/widgets/scroll_position.dart:136:49)
#1 _PagePosition.page (package:flutter/src/widgets/page_view.dart:388:22)
#2 PageController.page (package:flutter/src/widgets/page_view.dart:181:21)
#3 _BankAppState.build.<anonymous closure> (package:flutter_challenges/banking_app.dart:69:38)
#4 SliverChildBuilderDelegate.build (package:flutter/src/widgets/sliver.dart:455:22)
...
====================================================================================================
flutter: 0.0
[✓] Flutter (Channel stable, 2.2.3, on macOS 11.4 20F71 darwin-arm, locale en-AO)
• Flutter version 2.2.3 at /Users/pedromassango/dev/sdk/flutter_stable
• Framework revision f4abaa0735 (3 days ago), 2021-07-01 12:46:11 -0700
• Engine revision 241c87ad80
• Dart version 2.13.4
Reacted by David Richboy Echomgbe, Pedro Massango, r-i-c-o and DieGlueckswurst
Metadata
Metadata
Assignees
Labels
a: error messageError messages from the Flutter frameworkError messages from the Flutter frameworka: null-safetySupport for Dart's null safety featureSupport for Dart's null safety featurefound in release: 2.3Found to occur in 2.3Found to occur in 2.3frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Activity
darshankawar commentedon Jul 5, 2021
@pedromassango Hi,
Any reason you are using
debugPrint(_pageController.page.toString());instead ofdebugPrint(_pageController.toString());?Using the latter, it works and prints properly as below:
pedromassango commentedon Jul 5, 2021
No really. However, the point it that this code throws an exception.
You can replace that with:
_pageController.page!.toDouble()which is what I was trying to do.On a side note: this code still crashes even if you define the
initialPagein the controller.darshankawar commentedon Jul 6, 2021
Thanks for the details.
flutter doctor -v
ominibyte commentedon Jul 10, 2021
This error is not just particular to PageView. I'm using
ListWheelScrollView.useDelegatewithFixedExtentScrollPhysicsandFixedExtentScrollControllerand I have the same issue.Seems like a few null checks needs to be added to
package:flutter/src/widgets/scroll_position.dart.Levi-Lesches commentedon Aug 13, 2021
Related to #60578 (not quite a duplicate since that was initially about something else, but now they're the same).
DieGlueckswurst commentedon Aug 13, 2021
really annyoing issue. Wish Flutter would update this! Is there ay workaround for this at the moment? @Levi-Lesches
Levi-Lesches commentedon Aug 13, 2021
DieGlueckswurst commentedon Aug 14, 2021
Levi-Lesches commentedon Aug 15, 2021
pedromassango commentedon Sep 6, 2021
Finally found a workaround for this bug: Make sure you check for the content dimensions before trying to access a content-related property.
markusaksli-nc commentedon Nov 25, 2021
This now throws an assertion that explains this so closing this as fixed.
github-actions commentedon Dec 9, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.