Issue
I have a screen where I am creating a ListView
. For Android I want to implement “long key press”. For iOS I want “swipe gesture”.
For long key press and swipe I have to show 3 options:
Delete | Delete All | More...
How to do that.
Solution
Wrap your listitem UI in a GetureDetector for Android and use the onLongTap callback. For iOS you can wrap your listitem UI in a Dissmissable widget. A simple extraction should help with that.
Have your UI in a function that returns only your UI for the item, then outside wrap it with the above mentioned based on the platform.
// import platform helpers
import 'package:flutter/foundation.dart' show defaultTargetPlatform;
import 'package:flutter/foundation.dart' show TargetPlatform;
// determine your platform
final isIOS = defaultTargetPlatform == TargetPlatform.iOS;
// return your appropriate wrapper
isIOS
? Dismissible(
child: _getListItemUi(),
)
: GestureDetector(
onLongPress: () {
},
child: _getListItemUi()
);
Widget _getListItemUi() {
return Container(child: Text('List Item UI'));
}
Answered By – Filled Stacks
Answer Checked By – Candace Johnson (FlutterFixes Volunteer)