How to wrap buttons to dismissible buttons in Flutter

Viewed 125

I have following code to get list of recognized text in my app. I would like to change them to dismissable buttons, so I can remove quickly some item from the list:

class OcrTextWidget extends StatelessWidget{
  final OcrText ocrText;
  OcrTextWidget(this.ocrText);

  @override
  Widget build(BuildContext context) {
    return ListTile(
      leading: const Icon(Icons.title),
      title: Text(ocrText.value),
    );
  }
}

This how it look from app:

screenshot

1 Answers

Change the build method to this:

A Dismissible widget requires a child, background, and key properties.

  @override
  Widget build(BuildContext context) {
    return Dismissible(
      child: ListTile(
        leading: const Icon(Icons.title),
        title: Text(ocrText.value),
      ),
      background: Container(),
      key: ValueKey(ocrText.value),
    );
  }
Related