letsar / gap

Flutter widgets for easily adding gaps inside Flex widgets such as Columns and Rows or scrolling views
MIT License
211 stars 20 forks source link

`flutter:master` FlutterError (Scrollable.of() was called with a context that does not contain a Scrollable widget. #12

Closed ghost closed 2 years ago

ghost commented 2 years ago

The upcoming Flutter change from of to maybeOf might break gap: ^2.0.0, because of its usage of Scrollable.of.

Issue description

When using Gap(...) outside of a Scrollable container the issue will show up as:

Exception has occurred.
FlutterError (Scrollable.of() was called with a context that does not contain a Scrollable widget.
No Scrollable widget ancestor could be found starting from the context that was passed to Scrollable.of(). This can happen because you are using a widget that looks for a Scrollable ancestor, but no such ancestor exists.
The context used was:
  Gap(dirty))

A flutter version without the change will run without error.

What will/has change(d)

PR Add maybeOf for all the cases where of returns nullable has been merged to flutter:master and will most probably land in a beta and then stable release.

A description of the Flutter changes and a migration guide is available at: Migrate of to non-nullable return values, and add maybeOf

Current Status 11/16/2022

gap: ^2.0.0 on current flutter:stable channel [Not reproduceable]

% flutter channel stable
% flutter upgrade 
% flutter --version
Flutter 3.3.8 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 52b3dc25f6 (7 days ago) • 2022-11-09 12:09:26 +0800
Engine • revision 857bd6b74c
Tools • Dart 2.18.4 • DevTools 2.15.0

gap: ^2.0.0 on flutter:beta channel [Not reproduceable]

% flutter channel beta
% flutter upgrade 
% flutter --version
Flutter 3.4.0-34.1.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision 71520442d4 (6 weeks ago) • 2022-10-05 16:38:28 -0500
Engine • revision db0cbb2145
Tools • Dart 2.19.0 (build 2.19.0-255.2.beta) • DevTools 2.18.0

gap: ^2.0.0 on flutter:master channel [Reproduceable]

% flutter channel master
% flutter upgrade 
% flutter --version
Flutter 3.6.0-3.0.pre.55 • channel master • https://github.com/flutter/flutter.git
Framework • revision 484e09ef79 (35 minutes ago) • 2022-11-16 05:18:10 -0500
Engine • revision 0241f18cbe
Tools • Dart 2.19.0 (build 2.19.0-406.0.dev) • DevTools 2.19.0

Quick fix for Flutter master / upcoming beta? channel users

I have made a change in my fork at fix_scrollable_of_issue_with_flutter_master

To use this fix, make the following change in your pubspec.yaml

  # gap: ^2.0.0
  gap: 
    git: 
      url: https://github.com/incima/gap.git
      ref: 307be282e99e6f27c2899cd5c81d724b267f18f4   

@letsar Thank you for this convenient package. This is just meant as a heads up.

letsar commented 2 years ago

Thanks for the heads up, I changed the code to work on stable and master branches.

davidmigloz commented 1 year ago

Scrollable.maybeOf() already landed on stable (Flutter 3.7)

migalv commented 1 year ago

I got this error when I started using Flutter version 3.7.11 on the stable channel with gap: ^2.0.1

Screenshot 2023-04-14 at 11 15 15

letsar commented 1 year ago

I've just released a fix with Scrollable.maybeOf