Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrollable.of() was called with a context that does not contain a Scrollable widget #444

Closed
jesussmile opened this issue Dec 22, 2022 · 15 comments

Comments

@jesussmile
Copy link

currently using typeAhead widget to query some parameters, after the recent flutter 3 update i keep getting this error

Scrollable.of() was called with a context that does not contain a Scrollable widget.
This is the widget where the error is pointing

 Row(
    children: [
        Image.asset("images/images/desticon.png",
            height: 16.0, width: 16.0),
        SizedBox(width: 18.0),
        Expanded(
            child: Container(
                decoration: BoxDecoration(
                    color: Colors.grey[400],
                    borderRadius: BorderRadius.circular(5.0),
                ),
                child: Padding(
                    padding: EdgeInsets.all(3.0),
                    child: TypeAheadField(
                        textFieldConfiguration: TextFieldConfiguration(
                            autofocus: false,
                            maxLines: 1,
                            controller: dropOffTextEditingController,
                            decoration: InputDecoration(
                                contentPadding: EdgeInsets.all(3),
                                hintText: "Drop off Location",
                                labelStyle: TextStyle(color: Colors.black),
                                focusedBorder: OutlineInputBorder(
                                    borderSide: BorderSide(
                                        width: 1.3, color: Colors.black),
                                ),
                                border: OutlineInputBorder(
                                    borderSide: BorderSide(width: 0.8),
                                ),
                            ),
                        ),
                        suggestionsCallback: (pattern) async {
                            //if (pattern.isNotEmpty)
                            return await addressSuggestion(pattern);
                            // return Future.value();
                        },
                        suggestionsBoxController:
                        SuggestionsBoxController(),
                        itemBuilder: (context, dynamic suggestion) {
                            return ListTile(
                                leading: Icon(Icons.location_on),
                                title: Text((suggestion as SearchInfo)
                                    .address!
                                    .name!),
                                subtitle:
                                Text((suggestion).address!.country!),
                            );
                        },
                        onSuggestionSelected: (dynamic suggestion) {
                            print("xxx $suggestion");

                            dropOffTextEditingController.text =
                                (suggestion as SearchInfo).address!.name!;
                            Provider.of < AppData > (context, listen: false)
                                .updateDropOffLocationAddress(
                                    dropOffTextEditingController.text);
                            //get the coordinates here
                            GeoPoint ? dropOffPoint = suggestion.point;
                            print("Coordinates :$dropOffPoint");
                            Provider.of < AppData > (context, listen: false)
                                .updateDropOffGeoPoint(dropOffPoint);

                            // Navigator.pop(
                            //     context, widget.showMapFunction(false));
                        },
                    ),
                ),
            ),
        ),
    ],
),

and this is the full error stack

════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building Container(bg: BoxDecoration(color: Color(0xffbdbdbd), borderRadius: BorderRadius.circular(5.0))):
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:
  TypeAheadField<SearchInfo>(dirty, state: _TypeAheadFieldState<SearchInfo>#d5046(lifecycle state: initialized))
The relevant error-causing widget was
Container
lib/AllScreens/searchScreen.dart:140
When the exception was thrown, this was the stack
#0      Scrollable.of.<anonymous closure>
package:flutter/…/widgets/scrollable.dart:336
#1      Scrollable.of
package:flutter/…/widgets/scrollable.dart:348
#2      _TypeAheadFieldState.didChangeDependencies (package:flutter_typeahead/src/flutter_typeahead.dart:871:51)

How can I fix it ?

@DemonKING073
Copy link

still not fixed?

@jesussmile
Copy link
Author

I just used a workaround to this. No replies. Nepali ho ?

@monolidth
Copy link

You can wrap the typeahead field in the SingleChildScrollView. @DemonKING073 @jesussmile

SingleChildScrollView(
  scrollDirection: Axis.vertical,
  child: widget
);

@jobypthomas
Copy link

@monolidth when wrapped with SingleChildScrollView, the callback "onSuggestionSelected" is not working.

@monolidth
Copy link

Let me check, will try to fix it since we are using it as well

@felipecastrosales
Copy link
Contributor

news about this?

@monolidth
Copy link

Well apparently is this not the only problem, I have fixed the scrolling issue but faced a couple of new issues.

@felipecastrosales
Copy link
Contributor

Thanks for the answer, @monolidth.
What for example? I'm having this problem on a crucial component.

@monolidth
Copy link

Update @felipecastrosales @jobypthomas. I first implement a custom scroll logic but as I said, had couple of issues.
Check out my fork, after removing the didChangeDependencies(), it works again :)

https://github.com/Bavest/flutter_typeahead

@felipecastrosales
Copy link
Contributor

Update @felipecastrosales @jobypthomas. I first implement a custom scroll logic but as I said, had couple of issues. Check out my fork, after removing the didChangeDependencies(), it works again :)

https://github.com/Bavest/flutter_typeahead

@monolidth wow, it actually worked. Very good. 🚀

But tell me, why did you remove didChangeDependencies? 🤔

It was not very clear to me the objective, "besides just solving the problem".


I used it this way.

  flutter_typeahead:
    git:
      url: https://github.com/Bavest/flutter_typeahead.git
      ref: ffe2ee391888fa4b0a51bd2027e91e21ec85ec6d

It is good practice to use ref.

@grahamsmith
Copy link

grahamsmith commented Jan 27, 2023

For scroll problem I managed to fix it in a single simple change...

Line 871:

ScrollableState? scrollableState = Scrollable.of(context);

to

ScrollableState? scrollableState = Scrollable.maybeOf(context);

Seems like Scrollable.of throws if a Scrollable is not found, where maybeOf allows null to be returned;

Edit: I am behind the times, two other people have PRs open that fix this already. Neither have been merged.

@jesussmile
Copy link
Author

jesussmile commented Jan 27, 2023

heres how i done it, no problem everything works fine

  Expanded(
    child: SingleChildScrollView(
        child: Container(
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(5.0),
                border: Border.all(color: Colors.red),
            ),
            child: Padding(
                padding: EdgeInsets.all(3.0),
                child: TypeAheadField(
                    textFieldConfiguration:
                    TextFieldConfiguration(
                        autofocus: false,
                        maxLines: 1,
                        controller: dropOffTextEditingController,
                        decoration: InputDecoration(
                            contentPadding: EdgeInsets.all(3),
                            hintText: "Drop off Location",
                            labelStyle:
                            TextStyle(color: Colors.black),
                            label: Text(
                                "Your DropOff Location",
                                style: TextStyle(color: Colors.blue),
                            ),

                        ),
                    ),
                    suggestionsCallback: (pattern) async {
                        //if (pattern.isNotEmpty)
                        return await addressSuggestion(pattern);
                        // return Future.value();
                    },
                    suggestionsBoxController:
                    SuggestionsBoxController(),
                    itemBuilder: (context, dynamic suggestion) {
                        return ListTile(
                            leading: Icon(
                                Icons.location_on,
                                color: Colors.red,
                            ),
                            title: Text((suggestion as SearchInfo)
                                .address!
                                .name!),
                            subtitle:
                            Text((suggestion).address!.country!),
                        );
                    },
                    onSuggestionSelected: (dynamic suggestion) {
                        print("xxx $suggestion");

                        dropOffTextEditingController.text =
                            (suggestion as SearchInfo)
                            .address!
                            .name!;
                        Provider.of < AppData > (context, listen: false)
                            .updateDropOffLocationAddress(
                                dropOffTextEditingController.text);
                        //get the coordinates here
                        GeoPoint ? dropOffPoint = suggestion.point;
                        print("Coordinates :$dropOffPoint");
                        Provider.of < AppData > (context, listen: false)
                            .updateDropOffGeoPoint(dropOffPoint);

                        // Navigator.pop(
                        //     context, widget.showMapFunction(false));
                    },
                ),
            ),
        ),
    ),
),

@sjmcdowall
Copy link
Collaborator

The .maybeOf() logic has been merged in to the code for Flutter 3.7.0. Not sure abotu the rest of the issues.

@sjmcdowall
Copy link
Collaborator

Can someone try this with 4.3.3 and see if the primary issue has been fixed?

@monolidth
Copy link

Yes, has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants