mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Simplify code
This commit is contained in:
parent
8943ae8144
commit
89d3b79617
@ -292,15 +292,7 @@ class _NotificationTile extends StatelessWidget {
|
||||
onTap: () => _onTap(context),
|
||||
title: Text(message),
|
||||
subtitle: Text(diffTimeFromNowToStr(notification.timeCreate)),
|
||||
onLongPressWithInfo: (size, offset) {
|
||||
final position = RelativeRect.fromLTRB(
|
||||
offset.dx - size.width,
|
||||
offset.dy,
|
||||
offset.dx,
|
||||
offset.dy + size.height,
|
||||
); //fromSize(Rect.fromPoints(offset, Offset.zero), size);*/
|
||||
|
||||
print(position);
|
||||
onLongPressOpenMenu: (position) {
|
||||
showMenu(context: context, position: position, items: [
|
||||
PopupMenuItem(
|
||||
child: Text(tr("Delete")),
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user