Skip to content

Commit

Permalink
Federate (MisterJimson#44)
Browse files Browse the repository at this point in the history
* 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
MisterJimson authored Nov 13, 2020
1 parent 1ed4257 commit 250db23
Show file tree
Hide file tree
Showing 178 changed files with 625 additions and 238 deletions.
36 changes: 26 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ jobs:
with:
channel: 'stable'
- run: flutter pub get
- run: flutter test
working-directory: ./flutter_keyboard_visibility_platform_interface
- run: flutter pub get
working-directory: ./example
- run: flutter test
working-directory: ./example
working-directory: ./flutter_keyboard_visibility_web
- run: flutter pub get
working-directory: ./flutter_keyboard_visibility
- run: flutter pub get
working-directory: ./example_old
working-directory: ./flutter_keyboard_visibility/example
- run: flutter pub get
working-directory: ./flutter_keyboard_visibility/example_old
- run: flutter test
working-directory: ./flutter_keyboard_visibility
- run: flutter test
working-directory: ./example_old
working-directory: ./flutter_keyboard_visibility/example
- run: flutter test
working-directory: ./flutter_keyboard_visibility/example_old

lint:
name: Lint
Expand All @@ -34,12 +40,22 @@ jobs:
with:
channel: 'stable'
- run: flutter pub get
working-directory: ./flutter_keyboard_visibility_platform_interface
- run: flutter pub get
working-directory: ./flutter_keyboard_visibility_web
- run: flutter pub get
working-directory: ./flutter_keyboard_visibility
- run: flutter pub get
working-directory: ./example
working-directory: ./flutter_keyboard_visibility/example
- run: flutter pub get
working-directory: ./example_old
working-directory: ./flutter_keyboard_visibility/example_old
- run: flutter analyze
working-directory: ./flutter_keyboard_visibility_platform_interface
- run: flutter analyze
working-directory: ./flutter_keyboard_visibility_web
- run: flutter analyze
working-directory: ./flutter_keyboard_visibility
- run: flutter analyze
working-directory: ./example
working-directory: ./flutter_keyboard_visibility/example
- run: flutter analyze
working-directory: ./example_old
working-directory: ./flutter_keyboard_visibility/example_old
12 changes: 1 addition & 11 deletions .gitignore
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/
2 changes: 1 addition & 1 deletion .idea/runConfigurations/demo_with_provider.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/example.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/example_old.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

React to keyboard visibility changes.

This is a fork, original project [here](https://github.com/adee42/flutter_keyboard_visibility).

## Install
Add the dependency to your pubspec.yaml
```yaml
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions flutter_keyboard_visibility/.gitignore
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.

File renamed without changes.
File renamed without changes.
File renamed without changes.
96 changes: 96 additions & 0 deletions flutter_keyboard_visibility/README.md
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());
});
}
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added flutter_keyboard_visibility/example/web/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions flutter_keyboard_visibility/example/web/index.html
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>
23 changes: 23 additions & 0 deletions flutter_keyboard_visibility/example/web/manifest.json
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"
}
]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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';
53 changes: 53 additions & 0 deletions flutter_keyboard_visibility/lib/src/keyboard_visibility.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);
}
}
Loading

0 comments on commit 250db23

Please sign in to comment.