5

I'm using flutter_sildable for chat app slide, I want only one slide to be open at the time so I have tried what they recommended on the docs but it's not working and I don't know why

class _ChatTileState extends State<ChatTile> {
  final SlidableController slidableController = SlidableController();

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {},
      child: Container(
        padding: EdgeInsets.symmetric(vertical: 10),
        child: Slidable(
          key: UniqueKey(),
          controller: slidableController,
          movementDuration: Duration(milliseconds: 100),
...

4 Answers4

8

If you are using version 1.0.0 or later you can achieve the same behaviour by wrapping the list of Slidable widgets with:

SlidableAutoCloseBehavior(closeWhenOpened: true, child: ... )

miloskarakas
  • 266
  • 5
  • 11
6

Hey there in order to open one tile at a time using the flutter_slidable package. You need to use the same Slidable controller for all tiles. From your code, it seems like you are instantiating new Slidable controllers for each tile. What you should do is to instantiate the SlidableController from the parent widget and pass it on to the tile widget.

This is the parent widget


...
  String title = 'Customers';
  final SlidableController slidableController = SlidableController();
  @override
  Widget build(BuildContext context) {
    return ScaffoldBody(
      centerTitle: true,
      title: title,

      drawer: CustomerScreen.isOrderAdding == true ? null : AppDrawer(),
      body: FutureBuilder(
        future: _refreshCustomers(context),
        builder: (ctx, snapshot) =>
            snapshot.connectionState == ConnectionState.waiting
                ? Center(
                    child: Center(
                      child: Image(
                        image: AssetImage('assets/img/LoadingCartoon.gif'),
                      ),
                    ),
                  )
                : RefreshIndicator(
                    onRefresh: () => _refreshCustomers(context),
                    child: Consumer<CustomerHttps>(
                      builder: (ctx, customerData, _) => Padding(
                        padding: EdgeInsets.all(5),
                        child: ListView.builder(
                          itemCount: customerData.items.length,
                          itemBuilder: (_, i) => CustomerTile(
                            slidableController: slidableController,
                            id: customerData.items[i].id,
                            name: customerData.items[i].name,
                          ),
                        ),
                      ),
                    ),
                  ),
      ),
    );

In my slidable Tile widget (child widget)

 final String id;
  final String name;
  final SlidableController slidableController;

  CustomerTile({
    this.id,
    this.name,
    this.slidableController,
  });

  Widget build(BuildContext context) {
    return CustomerScreen.isOrderAdding
        ? Container(
            padding: EdgeInsets.only(bottom: 9),
            child: Material(
              elevation: 5,
              borderRadius: BorderRadius.all(Radius.circular(10)),
              color: Colors.white,
              child: InkWell(
                borderRadius: BorderRadius.all(Radius.circular(10)),
                splashColor: Theme.of(context).primaryColor,
                onTap: () {
                  //clears any products and signature saved after selecting a new customer
                  var provider =
                      Provider.of<AddingProductOrder>(context, listen: false);
                  provider.clear();
                  Navigator.of(context).pushNamed(
                    EditOrderScreen.routeName,
                    arguments: [id, 'selection'],
                  );
                },
                child: Container(
                  width: double.infinity,
                  child: ListTile(
                    title: Text(name,
                        style: TextStyle(color: Colors.black),
                        overflow: TextOverflow.ellipsis,
                        maxLines: 1,
                        softWrap: false),
                    leading: Icon(
                      Icons.person,
                      color: Theme.of(context).primaryColor,
                    ),
                  ),
                ),
              ),
            ),
          )
        : Slidable(
            key: Key(id),
            actionPane: SlidableDrawerActionPane(),
            controller: slidableController,
            actionExtentRatio: 0.25,
            child: Container(...

VaughnVoyage
  • 84
  • 1
  • 5
1

First you wrap your parent wiget in "SlidableAutoCloseBehavior" and then add group tag.

SlidableAutoCloseBehavior( child: ListView( children: [ Slidable( groupTag: '0', ), Slidable( groupTag: '0', ), Slidable( groupTag: '1', ), ], ), )

0

Hopefully the accepted answer here will work for you. If not, could you show us the rest of your code so we can properly view any further reasons for there to be a problem. Swipe List Item for more options (Flutter)

James Piner
  • 199
  • 1
  • 4
  • 17