mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-10-23 15:03:22 +00:00
71 lines
1.8 KiB
Dart
71 lines
1.8 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
|
||
|
/// My custom list tile to add extra features to the default
|
||
|
/// implementation
|
||
|
///
|
||
|
/// @author Pierre HUBERT
|
||
|
|
||
|
class CustomListTile extends StatelessWidget {
|
||
|
final Widget leading;
|
||
|
final Widget title;
|
||
|
final Widget subtitle;
|
||
|
final Widget trailing;
|
||
|
final bool isThreeLine;
|
||
|
final bool dense;
|
||
|
final EdgeInsetsGeometry contentPadding;
|
||
|
final bool enabled;
|
||
|
final GestureTapCallback onTap;
|
||
|
final GestureLongPressCallback onLongPress;
|
||
|
final bool selected;
|
||
|
|
||
|
/// Custom onLongPress function
|
||
|
final Function(Size, Offset) onLongPressWithInfo;
|
||
|
|
||
|
const CustomListTile({
|
||
|
Key key,
|
||
|
this.leading,
|
||
|
this.title,
|
||
|
this.subtitle,
|
||
|
this.trailing,
|
||
|
this.isThreeLine = false,
|
||
|
this.dense,
|
||
|
this.contentPadding,
|
||
|
this.enabled = true,
|
||
|
this.onTap,
|
||
|
this.onLongPress,
|
||
|
this.selected = false,
|
||
|
this.onLongPressWithInfo,
|
||
|
}) : assert(isThreeLine != null),
|
||
|
assert(enabled != null),
|
||
|
assert(selected != null),
|
||
|
assert(!isThreeLine || subtitle != null),
|
||
|
super(key: key);
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return ListTile(
|
||
|
leading: leading,
|
||
|
title: title,
|
||
|
subtitle: subtitle,
|
||
|
trailing: trailing,
|
||
|
isThreeLine: isThreeLine,
|
||
|
dense: dense,
|
||
|
contentPadding: contentPadding,
|
||
|
enabled: enabled,
|
||
|
onTap: onTap,
|
||
|
onLongPress: () => _longPress(context),
|
||
|
selected: selected,
|
||
|
);
|
||
|
}
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
}
|