Skip to content

Instantly share code, notes, and snippets.

@usimsek
Created October 15, 2020 14:12
Show Gist options
  • Save usimsek/0d5a183834849c51ff61c11334a734d1 to your computer and use it in GitHub Desktop.
Save usimsek/0d5a183834849c51ff61c11334a734d1 to your computer and use it in GitHub Desktop.
Dismiss flutter list / flutter sola çekerek silme işlemi
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Ejemplo"),
),
body: Center(child: SwipeList()));
}
}
class SwipeList extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return ListItemWidget();
}
}
class ListItemWidget extends State<SwipeList> {
List items = getDummyList();
@override
Widget build(BuildContext context) {
return Container(
child: ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
return Dismissible(
key: Key(items[index]),
background: Container(
alignment: AlignmentDirectional.centerEnd,
color: Colors.red,
child: Icon(
Icons.delete,
color: Colors.white,
),
),
onDismissed: (direction) {
setState(() {
items.removeAt(index);
});
},
direction: DismissDirection.endToStart,
child: Card(
margin: EdgeInsets.only(left: 10, right: 10, top: 12),
elevation: 8,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
semanticContainer: true,
clipBehavior: Clip.antiAliasWithSaveLayer,
child: Container(
height: 135,
child: Stack(children: <Widget>[
Positioned(
top: 0,
left: 0,
right: 0,
child: Container(
color: Colors.white,
child: Column(
children: <Widget>[
Image.network(
'https://placeimg.com/640/480/any',
fit: BoxFit.fitHeight,
),
],
))),
Positioned(
top: 20,
left: 0,
right: 0,
child: Container(
child: Column(
children: <Widget>[
Text(items[index],
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 25,
color: Colors.white),
textAlign: TextAlign.center),
],
),
)),
]),
)),
);
},
));
}
static List getDummyList() {
List list = List.generate(5, (i) {
return "Item ${i + 1}";
});
print(list);
return list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment