mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Simplify code
This commit is contained in:
@ -21,6 +21,9 @@ class CustomListTile extends StatelessWidget {
|
||||
/// Custom onLongPress function
|
||||
final Function(Size, Offset) onLongPressWithInfo;
|
||||
|
||||
/// Show menu onLongPress
|
||||
final Function(RelativeRect) onLongPressOpenMenu;
|
||||
|
||||
const CustomListTile({
|
||||
Key key,
|
||||
this.leading,
|
||||
@ -35,6 +38,7 @@ class CustomListTile extends StatelessWidget {
|
||||
this.onLongPress,
|
||||
this.selected = false,
|
||||
this.onLongPressWithInfo,
|
||||
this.onLongPressOpenMenu,
|
||||
}) : assert(isThreeLine != null),
|
||||
assert(enabled != null),
|
||||
assert(selected != null),
|
||||
@ -59,12 +63,25 @@ class CustomListTile extends StatelessWidget {
|
||||
}
|
||||
|
||||
void _longPress(BuildContext context) {
|
||||
RenderBox renderBox = context.findRenderObject();
|
||||
final size = renderBox.size;
|
||||
final offset = renderBox.localToGlobal(Offset(size.width, size.height));
|
||||
|
||||
if (onLongPress != null) onLongPress();
|
||||
|
||||
if (onLongPressWithInfo != null) onLongPressWithInfo(size, offset);
|
||||
if (onLongPressWithInfo != null || onLongPressOpenMenu != null) {
|
||||
RenderBox renderBox = context.findRenderObject();
|
||||
final size = renderBox.size;
|
||||
final offset = renderBox.localToGlobal(Offset(size.width, size.height));
|
||||
|
||||
if (onLongPressWithInfo != null) onLongPressWithInfo(size, offset);
|
||||
|
||||
if (onLongPressOpenMenu != null) {
|
||||
final position = RelativeRect.fromLTRB(
|
||||
offset.dx - size.width,
|
||||
offset.dy,
|
||||
offset.dx,
|
||||
offset.dy + size.height,
|
||||
);
|
||||
|
||||
onLongPressOpenMenu(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user