Created
July 15, 2019 10:20
-
-
Save leonardarnold/3fb295c2359f5a0e9f0d5de921966195 to your computer and use it in GitHub Desktop.
Weird swipe dismiss behaviour with rounded corners
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(MyApp()); | |
| class MyApp extends StatefulWidget { | |
| createState() => MyAppState(); | |
| } | |
| List<String> listItems = [ | |
| "Hello", | |
| "World", | |
| "Flutter", | |
| "Love" | |
| ]; //dummy list of items | |
| class MyAppState extends State<MyApp> { | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| title: 'Flutter Demo', | |
| theme: ThemeData( | |
| primarySwatch: Colors.blue, | |
| ), | |
| home: Scaffold( | |
| backgroundColor: Colors.blue, | |
| appBar: AppBar( | |
| title: Text("Swipe List"), | |
| ), | |
| body: Container( | |
| child: ListView.builder( | |
| itemCount: listItems.length, | |
| itemBuilder: (context, index) { | |
| return Padding( | |
| padding: const EdgeInsets.all(8.0), | |
| child: Dismissible( | |
| onResize: (){print("resize");}, | |
| background: stackBehindDismiss(), | |
| key: ObjectKey(listItems[index]), | |
| child: ClipRRect( | |
| borderRadius: BorderRadius.all(Radius.circular(16)), | |
| child: SizedBox( | |
| height: 72, | |
| child: Container( | |
| color: Colors.green, | |
| child:Row( | |
| children: <Widget>[ | |
| Text(listItems[index]), | |
| ], | |
| )), | |
| ), | |
| ), | |
| onDismissed: (direction) { | |
| deleteItem(index); | |
| }, | |
| ), | |
| ); | |
| }, | |
| )), | |
| )); | |
| } | |
| void deleteItem(index) { | |
| setState(() { | |
| listItems.removeAt(index); | |
| }); | |
| } | |
| Widget stackBehindDismiss() { | |
| return Card( | |
| margin: EdgeInsets.all(0), | |
| shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16))), | |
| color: Colors.redAccent, | |
| child: Row( | |
| children: <Widget>[ | |
| Expanded( | |
| child: Padding( | |
| padding: const EdgeInsets.all(8.0), | |
| child: Text( | |
| "Löschen", | |
| textAlign: TextAlign.end, | |
| style: Theme.of(context) | |
| .textTheme | |
| .title | |
| .merge(TextStyle(color: Colors.white)), | |
| ), | |
| ), | |
| ), | |
| ], | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment