Skip to content

Commit

Permalink
Fix MisterJimson#101 Gesture Arena conflicts (MisterJimson#102)
Browse files Browse the repository at this point in the history
* Fix MisterJimson#101 Gesture Arena conflicts

* Added ignore keyboard and config

* update example app for testing

* refactor

* docs

* docs

Co-authored-by: Kensai <[email protected]>
Co-authored-by: Jason Rai <[email protected]>
  • Loading branch information
3 people authored Feb 15, 2022
1 parent 8ef31d6 commit 68feb30
Show file tree
Hide file tree
Showing 13 changed files with 346 additions and 112 deletions.
6 changes: 0 additions & 6 deletions .idea/runConfigurations/demo_with_provider.xml

This file was deleted.

27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ Query and/or subscribe to keyboard visibility directly with the

```dart
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
import 'dart:async';
late StreamSubscription<bool> keyboardSubscription;
@override
void initState() {
Expand All @@ -69,10 +72,16 @@ void initState() {
print('Keyboard visibility direct query: ${keyboardVisibilityController.isVisible}');
// Subscribe
keyboardVisibilityController.onChange.listen((bool visible) {
print('Keyboard visibility update. Is visible: ${visible}');
keyboardSubscription = keyboardVisibilityController.onChange.listen((bool visible) {
print('Keyboard visibility update. Is visible: $visible');
});
}
@override
void dispose() {
keyboardSubscription.cancel();
super.dispose();
}
```
## Usage: Dismiss keyboard on tap
Place a `KeyboardDismissOnTap` near the top of your `Widget` tree. When a user taps outside of the currently focused `Widget`, the `Widget` will drop focus and the keyboard will be dismissed.
Expand All @@ -87,6 +96,20 @@ Widget build(BuildContext context) {
);
}
```
By default `KeyboardDismissOnTap` will only dismiss taps not captured by other interactive `Widget`s, like buttons. If you would like to dismiss the keyboard for any tap, including taps on interactive `Widget`s, set `dismissOnCapturedTaps` to true.
```dart
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
// Somewhere near the top of your tree...
@override
Widget build(BuildContext context) {
return KeyboardDismissOnTap(
dismissOnCapturedTaps: true,
child: MyDemoPage(),
);
}
```
The `IgnoreKeyboardDismiss` `Widget` can be used to further refine which taps do and do not dismiss the keyboard. Checkout the example app for more detail.
## Testing
Call `KeyboardVisibility.setVisibilityForTesting(value)` to set a custom value to use during `flutter test`
```dart
Expand Down
28 changes: 23 additions & 5 deletions flutter_keyboard_visibility/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

React to keyboard visibility changes.

### Note about Flutter Web support

Web support is an open issue [here](https://github.com/MisterJimson/flutter_keyboard_visibility/issues/10). Currently this library will just return `false` for keyboard visibility on web.

## Install
[Install the package](https://pub.dev/packages/flutter_keyboard_visibility/install)
## Usage: React to Keyboard Visibility Changes
Expand All @@ -16,11 +20,11 @@ import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
@override
Widget build(BuildContext context) {
return KeyboardVisibilityBuilder(
builder: (context, isKeyboardVisible) {
return Text(
'The keyboard is: ${isKeyboardVisible ? 'VISIBLE' : 'NOT VISIBLE'}',
);
}
builder: (context, isKeyboardVisible) {
return Text(
'The keyboard is: ${isKeyboardVisible ? 'VISIBLE' : 'NOT VISIBLE'}',
);
}
);
```
### Option 2: Within your `Widget` tree using a provider
Expand Down Expand Up @@ -92,6 +96,20 @@ Widget build(BuildContext context) {
);
}
```
By default `KeyboardDismissOnTap` will only dismiss taps not captured by other interactive `Widget`s, like buttons. If you would like to dismiss the keyboard for any tap, including taps on interactive `Widget`s, set `dismissOnCapturedTaps` to true.
```dart
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
// Somewhere near the top of your tree...
@override
Widget build(BuildContext context) {
return KeyboardDismissOnTap(
dismissOnCapturedTaps: true,
child: MyDemoPage(),
);
}
```
The `IgnoreKeyboardDismiss` `Widget` can be used to further refine which taps do and do not dismiss the keyboard. Checkout the example app for more detail.
## Testing
Call `KeyboardVisibility.setVisibilityForTesting(value)` to set a custom value to use during `flutter test`
```dart
Expand Down
3 changes: 3 additions & 0 deletions flutter_keyboard_visibility/example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ app.*.map.json

# Exceptions to above rules.
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

# Not supported yet
.macos/
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>8.0</string>
<string>9.0</string>
</dict>
</plist>
4 changes: 2 additions & 2 deletions flutter_keyboard_visibility/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/flutter_keyboard_visibility/ios"

SPEC CHECKSUMS:
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069

PODFILE CHECKSUM: 8e679eca47255a8ca8067c4c67aab20e64cb974d

COCOAPODS: 1.10.1
COCOAPODS: 1.11.2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 50;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -166,7 +166,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1020;
LastUpgradeCheck = 1300;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -333,7 +333,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -412,7 +412,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -461,7 +461,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
56 changes: 0 additions & 56 deletions flutter_keyboard_visibility/example/lib/demo_with_provider.dart

This file was deleted.

95 changes: 95 additions & 0 deletions flutter_keyboard_visibility/example/lib/keyboard_dismiss_demo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import 'package:flutter/material.dart';
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';

class KeyboardDismissDemo extends StatelessWidget {
const KeyboardDismissDemo({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Keyboard Dismiss Demo'),
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
KeyboardDismissOnTap(
child: Container(
height: 80,
width: double.infinity,
color: Colors.red,
child: Center(child: Text('Red dismisses on tap')),
),
),
KeyboardDismissOnTap(
child: Container(
height: 80,
width: double.infinity,
color: Colors.blue,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Button does not dismiss, blue does'),
ElevatedButton(
onPressed: () {},
child: Text('Button'),
),
],
),
),
),
KeyboardDismissOnTap(
dismissOnCapturedTaps: true,
child: Container(
height: 80,
width: double.infinity,
color: Colors.green,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Button and green both dismiss'),
ElevatedButton(
onPressed: () {},
child: Text('Button'),
),
],
),
),
),
KeyboardDismissOnTap(
child: Container(
height: 80,
width: double.infinity,
color: Colors.orange,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Orange dismisses, black does not'),
IgnoreKeyboardDismiss(
child: Container(
margin: EdgeInsets.only(top: 4),
height: 40,
width: 40,
color: Colors.black,
),
),
],
),
),
),
Spacer(),
TextField(
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: 'Input box for keyboard test',
),
),
],
),
),
),
);
}
}
Loading

0 comments on commit 68feb30

Please sign in to comment.