Skip to content

Instantly share code, notes, and snippets.

Embed
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");
HomePage(this.title);
@override
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) {
items.removeAt(index);
},
background: new Container(
padding: EdgeInsets.only(right: 20.0),
color: Colors.red,
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;
}
}
@vinothvino42
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,
   color: Colors.red,
   child: Text(
     'Delete',
      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