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),
|
onTap: () => _onTap(context),
|
||||||
title: Text(message),
|
title: Text(message),
|
||||||
subtitle: Text(diffTimeFromNowToStr(notification.timeCreate)),
|
subtitle: Text(diffTimeFromNowToStr(notification.timeCreate)),
|
||||||
onLongPressWithInfo: (size, offset) {
|
onLongPressOpenMenu: (position) {
|
||||||
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);
|
|
||||||
showMenu(context: context, position: position, items: [
|
showMenu(context: context, position: position, items: [
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
child: Text(tr("Delete")),
|
child: Text(tr("Delete")),
|
||||||
|
@ -21,6 +21,9 @@ class CustomListTile extends StatelessWidget {
|
|||||||
/// Custom onLongPress function
|
/// Custom onLongPress function
|
||||||
final Function(Size, Offset) onLongPressWithInfo;
|
final Function(Size, Offset) onLongPressWithInfo;
|
||||||
|
|
||||||
|
/// Show menu onLongPress
|
||||||
|
final Function(RelativeRect) onLongPressOpenMenu;
|
||||||
|
|
||||||
const CustomListTile({
|
const CustomListTile({
|
||||||
Key key,
|
Key key,
|
||||||
this.leading,
|
this.leading,
|
||||||
@ -35,6 +38,7 @@ class CustomListTile extends StatelessWidget {
|
|||||||
this.onLongPress,
|
this.onLongPress,
|
||||||
this.selected = false,
|
this.selected = false,
|
||||||
this.onLongPressWithInfo,
|
this.onLongPressWithInfo,
|
||||||
|
this.onLongPressOpenMenu,
|
||||||
}) : assert(isThreeLine != null),
|
}) : assert(isThreeLine != null),
|
||||||
assert(enabled != null),
|
assert(enabled != null),
|
||||||
assert(selected != null),
|
assert(selected != null),
|
||||||
@ -59,12 +63,25 @@ class CustomListTile extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _longPress(BuildContext context) {
|
void _longPress(BuildContext context) {
|
||||||
|
if (onLongPress != null) onLongPress();
|
||||||
|
|
||||||
|
if (onLongPressWithInfo != null || onLongPressOpenMenu != null) {
|
||||||
RenderBox renderBox = context.findRenderObject();
|
RenderBox renderBox = context.findRenderObject();
|
||||||
final size = renderBox.size;
|
final size = renderBox.size;
|
||||||
final offset = renderBox.localToGlobal(Offset(size.width, size.height));
|
final offset = renderBox.localToGlobal(Offset(size.width, size.height));
|
||||||
|
|
||||||
if (onLongPress != null) onLongPress();
|
|
||||||
|
|
||||||
if (onLongPressWithInfo != null) onLongPressWithInfo(size, offset);
|
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