google/flutter.widgets

null safety on scrollable_positioned_list-0.3.6

Opened this issue · 3 comments

Flutter version: 3.3.1
scrollable_positioned_list-0.3.6

0.3.6 An error was reported during compilation:

/usr/local/flutter/.pub-cache/hosted/pub.dartlang.org/scrollable_positioned_list-0.3.6/lib/src/scrollable_positioned_list.dart:278:61: Error: Method 'readState' cannot be called on 'PageStorageBucket?' because it is potentially null.
 - 'PageStorageBucket' is from 'package:flutter/src/widgets/page_storage.dart' ('/usr/local/flutter/packages/flutter/lib/src/widgets/page_storage.dart').
[        ] Try calling using ?. instead.
[        ]     ItemPosition? initialPosition = PageStorage.of(context).readState(context);
[        ]                                                             ^^^^^^^^^
[   +1 ms] /usr/local/flutter/.pub-cache/hosted/pub.dartlang.org/scrollable_positioned_list-0.3.6/lib/src/scrollable_positioned_list.dart:577:31: Error: Method 'writeState' cannot be called on 'PageStorageBucket?' because it is potentially null.
[        ]  - 'PageStorageBucket' is from 'package:flutter/src/widgets/page_storage.dart' ('/usr/local/flutter/packages/flutter/lib/src/widgets/page_storage.dart').
[        ] Try calling using ?. instead.
[        ]       PageStorage.of(context).writeState(
[        ]                               ^^^^^^^^^^
[   +3 ms] Target kernel_snapshot failed: Exception

Currently fix the version to 0.3.5 normally

We are having same error while building the application, Guess this issue occurred due to new release.
Resolved it by using a fixed version like scrollable_positioned_list: 0.3.2. remove the ^ from scrollable_positioned_list: 0.3.2

we have the same error

../../flutter/.pub-cache/hosted/pub.flutter-io.cn/scrollable_positioned_list-0.3.6/lib/src/scrollable_positioned_list.dart:577:31: Error: Method 'writeState' cannot be called on 'PageStorageBucket?' because it is potentially null.

  • 'PageStorageBucket' is from 'package:flutter/src/widgets/page_storage.dart' ('../../../flutter/packages/flutter/lib/src/widgets/page_storage.dart').
    Try calling using ?. instead.
    PageStorage.of(context).writeState(
    ^^^^^^^^^^

FAILURE: Build failed with an exception.

PageStorage.of returns a nullable PageStorageBucket? in flutter 3.3.x
This has changed in flutter 3.7.x where we have the following alternative methods:

  • PageStorageBucket of(BuildContext context)
  • PageStorageBucket? maybeOf(BuildContext context)

So, scrollable_positioned_list is only compatible with Flutter 3.7.x and newer, starting from version 0.3.6
If you're still on flutter 3.3.x you should pin to the latest compatible version in your pubspec.yaml like so:

scrollable_positioned_list: 0.3.5