Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Flutter Dismissible with Delete text
import 'package:flutter/material.dart';
void main() => runApp(new MaterialApp(
home: new HomePage('Dismissible Example'),
class HomePage extends StatelessWidget {
String title;
final items = new List<String>.generate(10000, (i) => "Item $i");
Widget build(BuildContext context) {
var listView = new ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
var item = items[index];
return new Dismissible(
direction: DismissDirection.endToStart,
key: new Key(item),
onDismissed: (direction) {
background: new Container(
padding: EdgeInsets.only(right: 20.0),
child: new Align(
alignment: Alignment.centerRight,
child: new Text('Delete',
textAlign: TextAlign.right,
style: new TextStyle(color: Colors.white)),
child: new ListTile(
title: new Text('$item'),
var scafford = new Scaffold(
appBar: new AppBar(title: new Text(title)),
body: listView,
return scafford;
Copy link

vinothvino42 commented Apr 17, 2020

Thanks for the code snippet...
You no need to add Align widget, use alignment property of Container Widget to align center-right instead.

 background: Container(
   padding: EdgeInsets.only(right: 20.0),
   alignment: Alignment.centerRight,
   child: Text(
      textAlign: TextAlign.right,
      style: TextStyle(color: Colors.white),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment