flutterscrollable

No Scrollable widget ancestor could be found


I'm trying implementing of slidable list item by using Slidable widget.

I get error that Scrollable.of() was called with a context that does not contain a Scrollable widget.

Error Message

I expect to get something like this:

desire work

my code looks like:

import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';

void main(List<String> args) {
  runApp(
    const MaterialApp(
      home: MyWidget(),
    ),
  );
}

class MyWidget extends StatefulWidget {
  const MyWidget({super.key});

  @override
  State<MyWidget> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Slidable(
          startActionPane: ActionPane(
            motion: const StretchMotion(),
            children: [
              SlidableAction(onPressed: ((context) {}), icon: Icons.waves),
            ],
          ),
          child: Container(
            color: Colors.grey,
            child: const ListTile(
              leading: Icon(Icons.newspaper),
              title: Text("New List Tile"),
            ),
          ),
        ),
      ),
    );
  }
}

Solution

  • You can set closeOnScroll: false if the parent widget doesn't contains any scrollable widget.

    Slidable(
      closeOnScroll: false, //this
      startActionPane: ActionPane(
    

    Or you can use any scrollable widget on body:

      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: ListView(
            children: [
              Center(
                child: Slidable(
    

    or

    return Scaffold(
      body: SingleChildScrollView(
        child: Center(
          child: Slidable(
    

    Just needed to be on top of Slidable. Doesn't have to be on body specifically.

    flutter_slidable/issues/402