Committed by
GitHub
Platform interface null safety (#59)
* Platform interface null safety * Flutter action * exclude * Annotate * Exclude
Showing
8 changed files
with
113 additions
and
27 deletions
| @@ -35,7 +35,7 @@ jobs: | @@ -35,7 +35,7 @@ jobs: | ||
| 35 | 35 | ||
| 36 | steps: | 36 | steps: |
| 37 | - uses: actions/checkout@v2.3.3 | 37 | - uses: actions/checkout@v2.3.3 |
| 38 | - - uses: subosito/flutter-action@v1.3.2 | 38 | + - uses: subosito/flutter-action@v1.4.0 |
| 39 | with: | 39 | with: |
| 40 | channel: ${{ matrix.channel }} | 40 | channel: ${{ matrix.channel }} |
| 41 | - run: flutter pub get | 41 | - run: flutter pub get |
| @@ -79,7 +79,7 @@ jobs: | @@ -79,7 +79,7 @@ jobs: | ||
| 79 | ) | 79 | ) |
| 80 | xcrun simctl boot "${UDID:?simulator not found}" | 80 | xcrun simctl boot "${UDID:?simulator not found}" |
| 81 | - uses: actions/checkout@v2.3.3 | 81 | - uses: actions/checkout@v2.3.3 |
| 82 | - - uses: subosito/flutter-action@v1.3.2 | 82 | + - uses: subosito/flutter-action@v1.4.0 |
| 83 | with: | 83 | with: |
| 84 | channel: ${{ matrix.channel }} | 84 | channel: ${{ matrix.channel }} |
| 85 | - run: flutter pub get | 85 | - run: flutter pub get |
.gitignore
0 → 100644
| 1 | +# Miscellaneous | ||
| 2 | +*.class | ||
| 3 | +*.log | ||
| 4 | +*.pyc | ||
| 5 | +*.swp | ||
| 6 | +.DS_Store | ||
| 7 | +.atom/ | ||
| 8 | +.buildlog/ | ||
| 9 | +.history | ||
| 10 | +.svn/ | ||
| 11 | +.metadata | ||
| 12 | + | ||
| 13 | +# IntelliJ related | ||
| 14 | +*.iml | ||
| 15 | +*.ipr | ||
| 16 | +*.iws | ||
| 17 | +.idea/ | ||
| 18 | + | ||
| 19 | +# The .vscode folder contains launch configuration and tasks you configure in | ||
| 20 | +# VS Code which you may wish to be included in version control, so this line | ||
| 21 | +# is commented out by default. | ||
| 22 | +#.vscode/ | ||
| 23 | + | ||
| 24 | +# Flutter/Dart/Pub related | ||
| 25 | +**/doc/api/ | ||
| 26 | +.dart_tool/ | ||
| 27 | +.flutter-plugins | ||
| 28 | +.flutter-plugins-dependencies | ||
| 29 | +.packages | ||
| 30 | +.pub-cache/ | ||
| 31 | +.pub/ | ||
| 32 | +build/ | ||
| 33 | +pubspec.lock | ||
| 34 | + | ||
| 35 | +# Android related | ||
| 36 | +**/android/**/gradle-wrapper.jar | ||
| 37 | +**/android/.gradle | ||
| 38 | +**/android/captures/ | ||
| 39 | +**/android/gradlew | ||
| 40 | +**/android/gradlew.bat | ||
| 41 | +**/android/local.properties | ||
| 42 | +**/android/**/GeneratedPluginRegistrant.java | ||
| 43 | + | ||
| 44 | +# iOS/XCode related | ||
| 45 | +**/ios/**/*.mode1v3 | ||
| 46 | +**/ios/**/*.mode2v3 | ||
| 47 | +**/ios/**/*.moved-aside | ||
| 48 | +**/ios/**/*.pbxuser | ||
| 49 | +**/ios/**/*.perspectivev3 | ||
| 50 | +**/ios/**/*sync/ | ||
| 51 | +**/ios/**/.sconsign.dblite | ||
| 52 | +**/ios/**/.tags* | ||
| 53 | +**/ios/**/.vagrant/ | ||
| 54 | +**/ios/**/DerivedData/ | ||
| 55 | +**/ios/**/Icon? | ||
| 56 | +**/ios/**/Pods/ | ||
| 57 | +**/ios/**/.symlinks/ | ||
| 58 | +**/ios/**/profile | ||
| 59 | +**/ios/**/xcuserdata | ||
| 60 | +**/ios/.generated/ | ||
| 61 | +**/ios/Flutter/App.framework | ||
| 62 | +**/ios/Flutter/Flutter.framework | ||
| 63 | +**/ios/Flutter/Flutter.podspec | ||
| 64 | +**/ios/Flutter/Generated.xcconfig | ||
| 65 | +**/ios/Flutter/app.flx | ||
| 66 | +**/ios/Flutter/app.zip | ||
| 67 | +**/ios/Flutter/flutter_assets/ | ||
| 68 | +**/ios/Flutter/flutter_export_environment.sh | ||
| 69 | +**/ios/ServiceDefinitions.json | ||
| 70 | +**/ios/Runner/GeneratedPluginRegistrant.* | ||
| 71 | + | ||
| 72 | +# Exceptions to above rules. | ||
| 73 | +!**/ios/**/default.mode1v3 | ||
| 74 | +!**/ios/**/default.mode2v3 | ||
| 75 | +!**/ios/**/default.pbxuser | ||
| 76 | +!**/ios/**/default.perspectivev3 |
| 1 | +// Ignoring until pigeon is migrated to null safety. | ||
| 2 | +// See https://github.com/flutter/flutter/issues/71360. | ||
| 3 | +// ignore: import_of_legacy_library_into_null_safe | ||
| 1 | import 'package:wakelock_platform_interface/messages.dart'; | 4 | import 'package:wakelock_platform_interface/messages.dart'; |
| 2 | import 'package:wakelock_platform_interface/wakelock_platform_interface.dart'; | 5 | import 'package:wakelock_platform_interface/wakelock_platform_interface.dart'; |
| 3 | 6 | ||
| @@ -13,9 +16,7 @@ class MethodChannelWakelock extends WakelockPlatformInterface { | @@ -13,9 +16,7 @@ class MethodChannelWakelock extends WakelockPlatformInterface { | ||
| 13 | } | 16 | } |
| 14 | 17 | ||
| 15 | @override | 18 | @override |
| 16 | - Future<void> toggle({bool enable}) async { | ||
| 17 | - assert(enable != null); | ||
| 18 | - | 19 | + Future<void> toggle({required bool enable}) async { |
| 19 | final message = ToggleMessage(); | 20 | final message = ToggleMessage(); |
| 20 | message.enable = enable; | 21 | message.enable = enable; |
| 21 | 22 |
| @@ -25,12 +25,7 @@ abstract class WakelockPlatformInterface { | @@ -25,12 +25,7 @@ abstract class WakelockPlatformInterface { | ||
| 25 | /// has been resolved. | 25 | /// has been resolved. |
| 26 | static set instance(WakelockPlatformInterface instance) { | 26 | static set instance(WakelockPlatformInterface instance) { |
| 27 | if (!instance.isMock) { | 27 | if (!instance.isMock) { |
| 28 | - try { | ||
| 29 | instance._verifyProvidesDefaultImplementations(); | 28 | instance._verifyProvidesDefaultImplementations(); |
| 30 | - } on NoSuchMethodError catch (_) { | ||
| 31 | - throw AssertionError( | ||
| 32 | - 'Platform interfaces must not be implemented with `implements`'); | ||
| 33 | - } | ||
| 34 | } | 29 | } |
| 35 | _instance = instance; | 30 | _instance = instance; |
| 36 | } | 31 | } |
| @@ -45,7 +40,7 @@ abstract class WakelockPlatformInterface { | @@ -45,7 +40,7 @@ abstract class WakelockPlatformInterface { | ||
| 45 | bool get isMock => false; | 40 | bool get isMock => false; |
| 46 | 41 | ||
| 47 | /// Toggles the wakelock based on the given [enable] value. | 42 | /// Toggles the wakelock based on the given [enable] value. |
| 48 | - Future<void> toggle({@required bool enable}) { | 43 | + Future<void> toggle({required bool enable}) { |
| 49 | throw UnimplementedError('toggle() has not been implemented.'); | 44 | throw UnimplementedError('toggle() has not been implemented.'); |
| 50 | } | 45 | } |
| 51 | 46 |
| @@ -7,18 +7,17 @@ homepage: >-2 | @@ -7,18 +7,17 @@ homepage: >-2 | ||
| 7 | https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_platform_interface | 7 | https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_platform_interface |
| 8 | 8 | ||
| 9 | environment: | 9 | environment: |
| 10 | - sdk: ">=2.8.0 <3.0.0" | 10 | + sdk: '>=2.12.0-0 <3.0.0' |
| 11 | flutter: ">=1.17.0 <2.0.0" | 11 | flutter: ">=1.17.0 <2.0.0" |
| 12 | 12 | ||
| 13 | dependencies: | 13 | dependencies: |
| 14 | flutter: | 14 | flutter: |
| 15 | sdk: flutter | 15 | sdk: flutter |
| 16 | 16 | ||
| 17 | - meta: ^1.2.0 | 17 | + meta: 1.3.0-nullsafety.6 |
| 18 | 18 | ||
| 19 | dev_dependencies: | 19 | dev_dependencies: |
| 20 | flutter_test: | 20 | flutter_test: |
| 21 | sdk: flutter | 21 | sdk: flutter |
| 22 | 22 | ||
| 23 | - mockito: ^4.1.3 | ||
| 24 | - pedantic: ^1.9.2 | 23 | + pedantic: ^1.10.0-nullsafety.3 |
| 1 | import 'package:flutter_test/flutter_test.dart'; | 1 | import 'package:flutter_test/flutter_test.dart'; |
| 2 | -import 'package:mockito/mockito.dart'; | 2 | +// Ignoring until pigeon is migrated to null safety. |
| 3 | +// See https://github.com/flutter/flutter/issues/71360. | ||
| 4 | +// ignore: import_of_legacy_library_into_null_safe | ||
| 3 | import 'package:wakelock_platform_interface/messages.dart'; | 5 | import 'package:wakelock_platform_interface/messages.dart'; |
| 4 | import 'package:wakelock_platform_interface/method_channel_wakelock.dart'; | 6 | import 'package:wakelock_platform_interface/method_channel_wakelock.dart'; |
| 5 | import 'package:wakelock_platform_interface/wakelock_platform_interface.dart'; | 7 | import 'package:wakelock_platform_interface/wakelock_platform_interface.dart'; |
| 6 | 8 | ||
| 7 | class _ApiLogger implements TestWakelockApi { | 9 | class _ApiLogger implements TestWakelockApi { |
| 8 | final List<String> log = []; | 10 | final List<String> log = []; |
| 9 | - ToggleMessage toggleMessage; | 11 | + late ToggleMessage toggleMessage; |
| 10 | 12 | ||
| 11 | @override | 13 | @override |
| 12 | IsEnabledMessage isEnabled() { | 14 | IsEnabledMessage isEnabled() { |
| @@ -33,14 +35,13 @@ void main() { | @@ -33,14 +35,13 @@ void main() { | ||
| 33 | test('Cannot be implemented with `implements`', () { | 35 | test('Cannot be implemented with `implements`', () { |
| 34 | expect(() { | 36 | expect(() { |
| 35 | WakelockPlatformInterface.instance = | 37 | WakelockPlatformInterface.instance = |
| 36 | - ImplementsWakelockPlatformInterface(); | ||
| 37 | - }, throwsA(isInstanceOf<AssertionError>())); | 38 | + ImplementsWakelockPlatformInterface(false); |
| 39 | + }, throwsA(isInstanceOf<NoSuchMethodError>())); | ||
| 38 | }); | 40 | }); |
| 39 | 41 | ||
| 40 | test('Can be mocked with `implements`', () { | 42 | test('Can be mocked with `implements`', () { |
| 41 | - final mock = ImplementsWakelockPlatformInterface(); | ||
| 42 | - when(mock.isMock).thenReturn(true); | ||
| 43 | - WakelockPlatformInterface.instance = mock; | 43 | + WakelockPlatformInterface.instance = |
| 44 | + ImplementsWakelockPlatformInterface(true); | ||
| 44 | }); | 45 | }); |
| 45 | 46 | ||
| 46 | test('Can be extended', () { | 47 | test('Can be extended', () { |
| @@ -50,9 +51,9 @@ void main() { | @@ -50,9 +51,9 @@ void main() { | ||
| 50 | 51 | ||
| 51 | group('$MethodChannelWakelock', () { | 52 | group('$MethodChannelWakelock', () { |
| 52 | final wakelock = MethodChannelWakelock(); | 53 | final wakelock = MethodChannelWakelock(); |
| 53 | - _ApiLogger logger; | 54 | + late final _ApiLogger logger; |
| 54 | 55 | ||
| 55 | - setUp(() { | 56 | + setUpAll(() { |
| 56 | logger = _ApiLogger(); | 57 | logger = _ApiLogger(); |
| 57 | TestWakelockApi.setup(logger); | 58 | TestWakelockApi.setup(logger); |
| 58 | }); | 59 | }); |
| @@ -79,7 +80,16 @@ void main() { | @@ -79,7 +80,16 @@ void main() { | ||
| 79 | }); | 80 | }); |
| 80 | } | 81 | } |
| 81 | 82 | ||
| 82 | -class ImplementsWakelockPlatformInterface extends Mock | ||
| 83 | - implements WakelockPlatformInterface {} | 83 | +class ImplementsWakelockPlatformInterface implements WakelockPlatformInterface { |
| 84 | + const ImplementsWakelockPlatformInterface(this.mocked); | ||
| 85 | + | ||
| 86 | + final bool mocked; | ||
| 87 | + | ||
| 88 | + @override | ||
| 89 | + dynamic noSuchMethod(Invocation invocation) { | ||
| 90 | + if (invocation.memberName == #isMock && mocked) return true; | ||
| 91 | + throw NoSuchMethodError.withInvocation(this, invocation); | ||
| 92 | + } | ||
| 93 | +} | ||
| 84 | 94 | ||
| 85 | class ExtendsVideoPlayerPlatform extends WakelockPlatformInterface {} | 95 | class ExtendsVideoPlayerPlatform extends WakelockPlatformInterface {} |
-
Please register or login to post a comment