-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
* minor * move project to inner package * add interface project * basic working for iOS and Android * cleanup structure * more cleanup * web project * web working * started on docs * some cleanup * CI * CI part 2
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,6 @@ | ||
.DS_Store | ||
.dart_tool/ | ||
|
||
.packages | ||
.pub/ | ||
|
||
pubspec.lock | ||
|
||
build/ | ||
|
||
*.iml | ||
|
||
# Ignore the root .idea folder except the runConfigurations folder | ||
!idea/ | ||
.idea/* | ||
!/.idea/runConfigurations/ | ||
!/.idea/runConfigurations/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.DS_Store | ||
.dart_tool/ | ||
|
||
.packages | ||
.pub/ | ||
|
||
pubspec.lock | ||
|
||
build/ | ||
|
||
*.iml | ||
|
||
.idea/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Flutter Keyboard Visibility | ||
[![pub package](https://img.shields.io/pub/v/flutter_keyboard_visibility.svg?label=flutter_keyboard_visibility&color=blue)](https://pub.dev/packages/flutter_keyboard_visibility) | ||
|
||
React to keyboard visibility changes. | ||
|
||
## Install | ||
Add the dependency to your pubspec.yaml | ||
```yaml | ||
dependencies: | ||
flutter_keyboard_visibility: ^3.3.0 | ||
``` | ||
## Usage: React to Keyboard Visibility Changes | ||
### Option 1: Within your `Widget` tree using a builder | ||
Build your Widget tree based on whether or not the keyboard is visible by using `KeyboardVisibilityBuilder`. | ||
```dart | ||
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'; | ||
/// In any of your widgets... | ||
@override | ||
Widget build(BuildContext context) { | ||
return KeyboardVisibilityBuilder( | ||
builder: (context, isKeyboardVisible) { | ||
return Text( | ||
'The keyboard is: ${isKeyboardVisible ? 'VISIBLE' : 'NOT VISIBLE'}', | ||
); | ||
} | ||
); | ||
``` | ||
### Option 2: Within your `Widget` tree using a provider | ||
Build your `Widget` tree based on whether or not the keyboard is | ||
visible by including a `KeyboardVisibilityProvider` near the top | ||
of your tree. | ||
```dart | ||
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'; | ||
// Somewhere near the top of your tree... | ||
@override | ||
Widget build(BuildContext context) { | ||
return KeyboardVisibilityProvider( | ||
child: MyDemoPage(), | ||
); | ||
} | ||
// Within MyDemoPage... | ||
@override | ||
Widget build(BuildContext context) { | ||
final bool isKeyboardVisible = KeyboardVisibilityProvider.isKeyboardVisible(context); | ||
return Text( | ||
'The keyboard is: ${isKeyboardVisible ? 'VISIBLE' : 'NOT VISIBLE'}', | ||
); | ||
} | ||
``` | ||
|
||
### Option 3: Direct query and subscription | ||
|
||
Query and/or subscribe to keyboard visibility directly with the | ||
`KeyboardVisibility` class. | ||
|
||
```dart | ||
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'; | ||
@override | ||
void initState() { | ||
super.initState(); | ||
// Query | ||
print('Keyboard visibility direct query: ${KeyboardVisibility.isVisible}'); | ||
// Subscribe | ||
KeyboardVisibility.onChange.listen((bool visible) { | ||
print('Keyboard visibility update. Is visible: ${visible}'); | ||
}); | ||
} | ||
``` | ||
## 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. | ||
```dart | ||
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'; | ||
// Somewhere near the top of your tree... | ||
@override | ||
Widget build(BuildContext context) { | ||
return KeyboardDismissOnTap( | ||
child: MyDemoPage(), | ||
); | ||
} | ||
``` | ||
## Testing | ||
Call `KeyboardVisibility.setVisibilityForTesting(value)` to set a custom value to use during `flutter test` | ||
```dart | ||
void main() { | ||
testWidgets('My Test', (WidgetTester tester) async { | ||
KeyboardVisibility.setVisibilityForTesting(true); | ||
await tester.pumpWidget(MyApp()); | ||
}); | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<!-- | ||
If you are serving your web app in a path other than the root, change the | ||
href value below to reflect the base path you are serving from. | ||
The path provided below has to start and end with a slash "/" in order for | ||
it to work correctly. | ||
Fore more details: | ||
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base | ||
--> | ||
<base href="/"> | ||
|
||
<meta charset="UTF-8"> | ||
<meta content="IE=Edge" http-equiv="X-UA-Compatible"> | ||
<meta name="description" content="A new Flutter project."> | ||
|
||
<!-- iOS meta tags & icons --> | ||
<meta name="apple-mobile-web-app-capable" content="yes"> | ||
<meta name="apple-mobile-web-app-status-bar-style" content="black"> | ||
<meta name="apple-mobile-web-app-title" content="example"> | ||
<link rel="apple-touch-icon" href="icons/Icon-192.png"> | ||
|
||
<!-- Favicon --> | ||
<link rel="icon" type="image/png" href="favicon.png"/> | ||
|
||
<title>example</title> | ||
<link rel="manifest" href="manifest.json"> | ||
</head> | ||
<body> | ||
<!-- This script installs service_worker.js to provide PWA functionality to | ||
application. For more information, see: | ||
https://developers.google.com/web/fundamentals/primers/service-workers --> | ||
<script> | ||
if ('serviceWorker' in navigator) { | ||
window.addEventListener('flutter-first-frame', function () { | ||
navigator.serviceWorker.register('flutter_service_worker.js'); | ||
}); | ||
} | ||
</script> | ||
<script src="main.dart.js" type="application/javascript"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "example", | ||
"short_name": "example", | ||
"start_url": ".", | ||
"display": "standalone", | ||
"background_color": "#0175C2", | ||
"theme_color": "#0175C2", | ||
"description": "A new Flutter project.", | ||
"orientation": "portrait-primary", | ||
"prefer_related_applications": false, | ||
"icons": [ | ||
{ | ||
"src": "icons/Icon-192.png", | ||
"sizes": "192x192", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "icons/Icon-512.png", | ||
"sizes": "512x512", | ||
"type": "image/png" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
library flutter_keyboard_visibility; | ||
|
||
export 'package:flutter_keyboard_visibility/src/keyboard_visibility.dart'; | ||
export 'package:flutter_keyboard_visibility/src/ui/keyboard_visibility_provider.dart'; | ||
export 'package:flutter_keyboard_visibility/src/ui/keyboard_visibility_builder.dart'; | ||
export 'package:flutter_keyboard_visibility/src/ui/keyboard_dismiss_on_tap.dart'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'dart:async'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:flutter_keyboard_visibility_platform_interface/flutter_keyboard_visibility_platform_interface.dart'; | ||
|
||
/// Provides access to the current keyboard visibility state and emits | ||
/// changes as they happen. | ||
class KeyboardVisibility { | ||
KeyboardVisibility._(); | ||
|
||
static FlutterKeyboardVisibilityPlatform get _platform => | ||
FlutterKeyboardVisibilityPlatform.instance; | ||
|
||
static bool _isInitialized = false; | ||
static final _onChangeController = StreamController<bool>(); | ||
static final _onChange = _onChangeController.stream.asBroadcastStream(); | ||
|
||
/// Emits true every time the keyboard is shown, and false every time the | ||
/// keyboard is dismissed. | ||
static Stream<bool> get onChange { | ||
// If _testIsVisible set, don't try to create the EventChannel | ||
if (!_isInitialized && _testIsVisible == null) { | ||
_platform.onChange.listen(_updateValue); | ||
_isInitialized = true; | ||
} | ||
return _onChange; | ||
} | ||
|
||
/// Returns true if the keyboard is currently visible, false if not. | ||
static bool get isVisible => _testIsVisible ?? _isVisible; | ||
static bool _isVisible = false; | ||
|
||
/// Fake representation of whether or not the keyboard is visible | ||
/// for testing purposes. When this value is non-null, it will be | ||
/// reported exclusively by the `isVisible` getter. | ||
static bool _testIsVisible; | ||
|
||
/// Forces `KeyboardVisibility` to report `isKeyboardVisible` | ||
/// for testing purposes. | ||
/// | ||
/// `KeyboardVisibility` will continue reporting `isKeyboardVisible` | ||
/// until the value is changed again with this method. To stop | ||
/// using fake values altogether, set `isKeyboardVisible` to null. | ||
@visibleForTesting | ||
static void setVisibilityForTesting(bool isKeyboardVisible) { | ||
_updateValue(isKeyboardVisible); | ||
} | ||
|
||
static void _updateValue(bool newValue) { | ||
_isVisible = newValue; | ||
_testIsVisible = newValue; | ||
_onChangeController.add(newValue); | ||
} | ||
} |