Skip to content

Instantly share code, notes, and snippets.

@shihaohong
Created June 12, 2019 17:00
Show Gist options
  • Save shihaohong/6ad7c4feee9251ba6273d3b4ad54ced2 to your computer and use it in GitHub Desktop.
Save shihaohong/6ad7c4feee9251ba6273d3b4ad54ced2 to your computer and use it in GitHub Desktop.
When swiping away ListTiles, it overlaps on top of surrounding content
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'ListTile test'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final leftItems = List<String>.generate(3, (i) => "Item ${i + 1}");
final rightItems = List<String>.generate(3, (i) => "Item ${i + 1}");
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(widget.title)),
body: Container(
child: Row(
children: [
Expanded(
child: ListView.builder(
itemCount: leftItems.length,
itemBuilder: (context, index) {
final item = leftItems[index];
return Dismissible(
key: Key('$item left'),
onDismissed: (direction) {
setState(() {
leftItems.removeAt(index);
});
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text("$item dismissed")));
},
background: Container(color: Colors.red),
child: ListTile(title: Text('$item')),
);
},
),
),
Expanded(
child: ListView.builder(
itemCount: rightItems.length,
itemBuilder: (context, index) {
final item = rightItems[index];
return Dismissible(
key: Key('$item right'),
onDismissed: (direction) {
setState(() {
rightItems.removeAt(index);
});
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text("$item dismissed")));
},
background: Container(color: Colors.red),
child: ListTile(title: Text('$item')),
);
},
),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment