Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phuongtailtranminh/a8517e3fb11da81e5d9aeeb0c2ff19ba to your computer and use it in GitHub Desktop.
Save phuongtailtranminh/a8517e3fb11da81e5d9aeeb0c2ff19ba to your computer and use it in GitHub Desktop.
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

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