diff --git a/CHANGELOG.md b/CHANGELOG.md index bf22ad6..21474f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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-. diff --git a/README.md b/README.md index 8702c06..c63b6e0 100644 --- a/README.md +++ b/README.md @@ -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 @@ -18,5 +18,6 @@ ListTileMoreCustomizable( trailing: Icon(Icons.people), horizontalTitleGap: 0.0, onTap: (details){}, + onLongPress: (details){}, ); ``` diff --git a/example/lib/main.dart b/example/lib/main.dart index d619b4d..0ef5f8f 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -73,6 +73,20 @@ class _MyHomePageState extends State { ], ); }, + onLongPress: (details){ + showMenu( + context: context, + position: RelativeRect.fromLTRB( + details.globalPosition.dx, + details.globalPosition.dy, + details.globalPosition.dx, + details.globalPosition.dy, + ), + items: >[ + PopupMenuItem(child: Text("onLongPressed - 1!")) + ], + ); + }, ), Divider(), ListTileMoreCustomizable( @@ -80,7 +94,7 @@ class _MyHomePageState extends State { title: Text("Title - 2"), subtitle: Text("Subtitle - 2"), trailing: Icon(Icons.palette), - onTap: (details) { + onLongPress: (details) { showMenu( context: context, position: RelativeRect.fromLTRB( diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 0cf2db1..b9040bc 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -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. diff --git a/lib/list_tile_more_customizable.dart b/lib/list_tile_more_customizable.dart index 800ba9e..59469b2 100644 --- a/lib/list_tile_more_customizable.dart +++ b/lib/list_tile_more_customizable.dart @@ -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. /// @@ -472,8 +472,9 @@ class _ListTileMoreCustomizableState extends State { _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( @@ -504,6 +505,10 @@ class _ListTileMoreCustomizableState extends State { widget.onTap(tapDownDetails); } + toOnLongPress() { + widget.onLongPress(tapDownDetails); + } + recordTapDownDetails(TapDownDetails d) { tapDownDetails = d; } diff --git a/pubspec.yaml b/pubspec.yaml index c31574d..7e34cd5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: