|
1 | 1 | import 'dart:async';
|
| 2 | +import 'package:flutter_keyboard_visibility/src/keyboard_visibility_handler.dart'; |
2 | 3 | import 'package:meta/meta.dart';
|
3 |
| -import 'package:flutter_keyboard_visibility_platform_interface/flutter_keyboard_visibility_platform_interface.dart'; |
4 | 4 |
|
5 | 5 | /// Provides access to the current keyboard visibility state and emits
|
6 | 6 | /// changes as they happen.
|
| 7 | +@Deprecated( |
| 8 | + 'Use KeyboardVisibilityController instead. Will be removed in a future release.') |
7 | 9 | class KeyboardVisibility {
|
8 | 10 | KeyboardVisibility._();
|
9 | 11 |
|
10 |
| - static FlutterKeyboardVisibilityPlatform get _platform => |
11 |
| - FlutterKeyboardVisibilityPlatform.instance; |
12 |
| - |
13 |
| - static bool _isInitialized = false; |
14 |
| - static final _onChangeController = StreamController<bool>(); |
15 |
| - static final _onChange = _onChangeController.stream.asBroadcastStream(); |
16 |
| - |
17 | 12 | /// Emits true every time the keyboard is shown, and false every time the
|
18 | 13 | /// keyboard is dismissed.
|
19 |
| - static Stream<bool> get onChange { |
20 |
| - // If _testIsVisible set, don't try to create the EventChannel |
21 |
| - if (!_isInitialized && _testIsVisible == null) { |
22 |
| - _platform.onChange.listen(_updateValue); |
23 |
| - _isInitialized = true; |
24 |
| - } |
25 |
| - return _onChange; |
26 |
| - } |
| 14 | + @Deprecated( |
| 15 | + 'Use KeyboardVisibilityController instead. Will be removed in a future release.') |
| 16 | + static Stream<bool> get onChange => KeyboardVisibilityHandler.onChange; |
27 | 17 |
|
28 | 18 | /// Returns true if the keyboard is currently visible, false if not.
|
29 |
| - static bool get isVisible => _testIsVisible ?? _isVisible; |
30 |
| - static bool _isVisible = false; |
31 |
| - |
32 |
| - /// Fake representation of whether or not the keyboard is visible |
33 |
| - /// for testing purposes. When this value is non-null, it will be |
34 |
| - /// reported exclusively by the `isVisible` getter. |
35 |
| - static bool _testIsVisible; |
| 19 | + @Deprecated( |
| 20 | + 'Use KeyboardVisibilityController instead. Will be removed in a future release.') |
| 21 | + static bool get isVisible => KeyboardVisibilityHandler.isVisible; |
36 | 22 |
|
37 | 23 | /// Forces `KeyboardVisibility` to report `isKeyboardVisible`
|
38 | 24 | /// for testing purposes.
|
39 | 25 | ///
|
40 | 26 | /// `KeyboardVisibility` will continue reporting `isKeyboardVisible`
|
41 | 27 | /// until the value is changed again with this method. To stop
|
42 | 28 | /// using fake values altogether, set `isKeyboardVisible` to null.
|
| 29 | + @Deprecated( |
| 30 | + 'Mock KeyboardVisibilityController instead. Will be removed in a future release.') |
43 | 31 | @visibleForTesting
|
44 |
| - static void setVisibilityForTesting(bool isKeyboardVisible) { |
45 |
| - _updateValue(isKeyboardVisible); |
46 |
| - } |
47 |
| - |
48 |
| - static void _updateValue(bool newValue) { |
49 |
| - _isVisible = newValue; |
50 |
| - _testIsVisible = newValue; |
51 |
| - _onChangeController.add(newValue); |
52 |
| - } |
| 32 | + static void setVisibilityForTesting(bool isKeyboardVisible) => |
| 33 | + KeyboardVisibilityHandler.setVisibilityForTesting(isKeyboardVisible); |
53 | 34 | }
|
0 commit comments