Skip to content

Commit

Permalink
1.Add TapDownDetails to onLongPress.
Browse files Browse the repository at this point in the history
2.Fixed null problem when onTap/onLongPress not used.
  • Loading branch information
Playhi committed Mar 1, 2020
1 parent 4852b59 commit 98c2c02
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [1.0.0] - 2020-03-01

* Add TapDownDetails to onLongPress.
* Fixed null problem when onTap/onLongPress not used.


## [0.1.0] - 2020-03-01

* Support flutter 1.13.8-.
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This project is a modified version of Flutter ListTile,
and provides more customizable functions,
with these functions,
you can set the horizontalTitleGap
and get the TapDownDetails when onTap occurred.
and get the TapDownDetails when onTap or onLongPress occurred.

## Usage

Expand All @@ -18,5 +18,6 @@ ListTileMoreCustomizable(
trailing: Icon(Icons.people),
horizontalTitleGap: 0.0,
onTap: (details){},
onLongPress: (details){},
);
```
16 changes: 15 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,28 @@ class _MyHomePageState extends State<MyHomePage> {
],
);
},
onLongPress: (details){
showMenu(
context: context,
position: RelativeRect.fromLTRB(
details.globalPosition.dx,
details.globalPosition.dy,
details.globalPosition.dx,
details.globalPosition.dy,
),
items: <PopupMenuEntry<int>>[
PopupMenuItem(child: Text("onLongPressed - 1!"))
],
);
},
),
Divider(),
ListTileMoreCustomizable(
leading: Icon(Icons.priority_high),
title: Text("Title - 2"),
subtitle: Text("Subtitle - 2"),
trailing: Icon(Icons.palette),
onTap: (details) {
onLongPress: (details) {
showMenu(
context: context,
position: RelativeRect.fromLTRB(
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies:
flutter:
sdk: flutter

list_tile_more_customizable: ^0.1.0
list_tile_more_customizable: ^1.0.0

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
Expand Down
15 changes: 10 additions & 5 deletions lib/list_tile_more_customizable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,14 @@ class ListTileMoreCustomizable extends StatefulWidget {
final bool enabled;

/// Called when the user taps this list tile.
///
/// The details information is recorded when InkWell's onTapDown occurred.
/// Inoperative if [enabled] is false.
final GestureTapDownCallback onTap;

/// Called when the user long-presses on this list tile.
///
/// The details information is recorded when InkWell's onTapDown occurred.
/// Inoperative if [enabled] is false.
final GestureLongPressCallback onLongPress;
final GestureTapDownCallback onLongPress;

/// If this tile is also [enabled] then icons and text are rendered with the same color.
///
Expand Down Expand Up @@ -472,8 +472,9 @@ class _ListTileMoreCustomizableState extends State<ListTileMoreCustomizable> {
_defaultContentPadding;

return InkWell(
onTap: widget.enabled ? toOnTap : null,
onLongPress: widget.enabled ? widget.onLongPress : null,
onTap: widget.enabled && widget.onTap != null ? toOnTap : null,
onLongPress:
widget.enabled && widget.onLongPress != null ? toOnLongPress : null,
onTapDown: widget.enabled ? recordTapDownDetails : null,
canRequestFocus: widget.enabled,
child: Semantics(
Expand Down Expand Up @@ -504,6 +505,10 @@ class _ListTileMoreCustomizableState extends State<ListTileMoreCustomizable> {
widget.onTap(tapDownDetails);
}

toOnLongPress() {
widget.onLongPress(tapDownDetails);
}

recordTapDownDetails(TapDownDetails d) {
tapDownDetails = d;
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: list_tile_more_customizable
description: A ListTile with more customizable details, which provides more customizable functions, based on the traditional flutter ListTile.
version: 0.1.0
version: 1.0.0
homepage: https://github.com/Playhi/list_tile_more_customizable

environment:
Expand Down

0 comments on commit 98c2c02

Please sign in to comment.