Created
April 23, 2018 09:37
-
-
Save phuongtailtranminh/a8517e3fb11da81e5d9aeeb0c2ff19ba to your computer and use it in GitHub Desktop.
Flutter Dismissible with Delete text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the code snippet...
You no need to add
Align
widget, usealignment
property ofContainer
Widget to align center-right instead.