Skip to content

Commit

Permalink
add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kyuqw committed Jul 17, 2021
1 parent 2a96fb5 commit 78c216d
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
* Initial Release.
87 changes: 78 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,83 @@
# gesture_handlers
# Gesture handlers

[![Pub Version](https://img.shields.io/pub/v/gesture_handlers?logo=dart&logoColor=white)](https://pub.dev/packages/gesture_handlers)
[![Pub Likes](https://badgen.net/pub/likes/gesture_handlers)](https://pub.dev/packages/gesture_handlers)
[![Pub popularity](https://badgen.net/pub/popularity/gesture_handlers)](https://pub.dev/packages/gesture_handlers/score)
[![Flutter Platform](https://badgen.net/pub/flutter-platform/gesture_handlers)](https://pub.dev/packages/gesture_handlers)

Gesture handlers Flutter project.

## Getting Started
Provide reusable gesture handler and Support interactive transitions between routes (i.e., controlled by gesture).

## Preview

[<img src="https://raw.githubusercontent.com/kyuqw/gesture_handlers/master/example/media/bottom_sheet_demo.gif" width="250" alt="bottom sheet demo"/>](https://pub.dev/packages/gesture_handlers/example)
[<img src="https://raw.githubusercontent.com/kyuqw/gesture_handlers/master/example/media/right_sheet_demo.gif" width="250" alt="right sheet demo"/>](https://pub.dev/packages/gesture_handlers/example)


## Installation

Add [*`gesture_handlers`*](https://pub.dev/packages/gesture_handlers/install)
as a dependency in [your pubspec.yaml file](https://flutter.dev/using-packages).

```shell
flutter pub add gesture_handlers
```
Import it in your Dart code
```dart
import 'package:gesture_handlers/gesture_handlers.dart';
```

## Usage

### Basic usage

Initialize concrete `GestureHandler` implementation.

```dart
final tapHandler = TapHandlerDelegate(onTap: () => print('tap handled'));
```

Pass handler to `GestureListener`.

```dart
@override
Widget build(BuildContext context) {
return GestureListener(
handler: tapHandler,
child: Scaffold(body: Center(child: Text('Tap'))),
);
}
```

Dispose it at the end.

```dart
@override
void dispose() {
tapHandler.dispose();
super.dispose();
}
```

### Route gesture transition

* Initialize `NavigatorGesturesFlutterBinding`
or use your own `NavigatorGesturesBinding` implementation
for prevent route `GestureHandler` active pointers canceling by `NavigatorState`.

```dart
import 'package:gesture_handlers/gesture_handlers.dart';
void main() {
/// Prints information about preventing cancel pointer with [GestureBinding.cancelPointer].
// debugPrintPreventCancelPointer = true;
This project is a starting point for a Dart
[package](https://flutter.dev/developing-packages/),
a library module containing code that can be shared easily across
multiple Flutter or Dart projects.
NavigatorGesturesFlutterBinding.ensureInitialized();
runApp(const MyApp());
}
```

For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
* Initialize `SwipeRouteHandler` or your own `GestureRouteDelegate` implementation.
* Use `GestureModalBottomSheetRoute`, `MaterialGesturePageRoute`
or create custom gesture route with `GestureRouteTransitionMixin`.
24 changes: 6 additions & 18 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,7 @@ class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
handler: handlerComposer,
child: Scaffold(
appBar: AppBar(title: Text(widget.title)),
body: Stack(
children: [
Center(
child: Text('Swipe up \nSwipe left \nTap', textAlign: TextAlign.center, style: style),
),
],
),
body: Center(child: Text('Swipe up \nSwipe left \nTap', textAlign: TextAlign.center, style: style)),
bottomNavigationBar: buildPersistentBottom(context),
),
);
Expand All @@ -136,13 +130,10 @@ class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
color: Colors.white12,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(22.0))),
child: Container(
alignment: Alignment.center,
height: persistentBottomHeight,
padding: const EdgeInsets.all(16.0),
child: Container(
alignment: Alignment.center,
child: const Text('swipe up to modal sheet'),
),
// child: const Placeholder(),
child: const Text('swipe up to modal sheet'),
),
),
);
Expand All @@ -161,16 +152,13 @@ class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
}

ShowGestureRouteDelegate openRightSheet() {
return (handler) => Navigator.push(
return (gestureDelegate) => Navigator.push(
context,
MaterialGesturePageRoute(
gestureDelegate: handler,
gestureDelegate: gestureDelegate,
builder: (ctx) => Scaffold(
appBar: AppBar(title: const Text('Page Route')),
body: Container(
alignment: Alignment.center,
child: const Text('Material Gesture Page Route'),
),
body: Center(child: const Text('Material Gesture Page Route')),
),
),
);
Expand Down
Binary file added example/media/bottom_sheet_demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/media/right_sheet_demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/src/gesture_handler.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class GestureListener extends StatefulWidget {
final GestureHandler handler;
Expand Down
1 change: 0 additions & 1 deletion lib/src/gesture_handlers/any_tap_handler.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/widgets.dart';

Expand Down
5 changes: 2 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: gesture_handlers
description: Gesture handlers Flutter project.
version: 0.0.1
author: kyuqw
description: Gesture handlers Flutter project provide reusable gesture handler and interactive transitions between routes.
version: 0.0.1+2
homepage: 'https://github.com/kyuqw/gesture_handlers'

environment:
Expand Down

0 comments on commit 78c216d

Please sign in to comment.