creativecreatorormaybenot
Committed by GitHub

Platform interface null safety (#59)

* Platform interface null safety

* Flutter action

* exclude

* Annotate

* Exclude
... ... @@ -35,7 +35,7 @@ jobs:
steps:
- uses: actions/checkout@v2.3.3
- uses: subosito/flutter-action@v1.3.2
- uses: subosito/flutter-action@v1.4.0
with:
channel: ${{ matrix.channel }}
- run: flutter pub get
... ... @@ -79,7 +79,7 @@ jobs:
)
xcrun simctl boot "${UDID:?simulator not found}"
- uses: actions/checkout@v2.3.3
- uses: subosito/flutter-action@v1.3.2
- uses: subosito/flutter-action@v1.4.0
with:
channel: ${{ matrix.channel }}
- run: flutter pub get
... ...
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
.metadata
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
build/
pubspec.lock
# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java
# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*
# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
... ...
include: package:pedantic/analysis_options.1.9.2.yaml
include: package:pedantic/analysis_options.yaml
linter:
rules:
- public_member_api_docs
\ No newline at end of file
- public_member_api_docs
... ...
include: ../analysis_options.yaml
analyzer:
exclude:
- 'lib/messages.dart'
... ...
// Ignoring until pigeon is migrated to null safety.
// See https://github.com/flutter/flutter/issues/71360.
// ignore: import_of_legacy_library_into_null_safe
import 'package:wakelock_platform_interface/messages.dart';
import 'package:wakelock_platform_interface/wakelock_platform_interface.dart';
... ... @@ -13,9 +16,7 @@ class MethodChannelWakelock extends WakelockPlatformInterface {
}
@override
Future<void> toggle({bool enable}) async {
assert(enable != null);
Future<void> toggle({required bool enable}) async {
final message = ToggleMessage();
message.enable = enable;
... ...
... ... @@ -25,12 +25,7 @@ abstract class WakelockPlatformInterface {
/// has been resolved.
static set instance(WakelockPlatformInterface instance) {
if (!instance.isMock) {
try {
instance._verifyProvidesDefaultImplementations();
} on NoSuchMethodError catch (_) {
throw AssertionError(
'Platform interfaces must not be implemented with `implements`');
}
instance._verifyProvidesDefaultImplementations();
}
_instance = instance;
}
... ... @@ -45,7 +40,7 @@ abstract class WakelockPlatformInterface {
bool get isMock => false;
/// Toggles the wakelock based on the given [enable] value.
Future<void> toggle({@required bool enable}) {
Future<void> toggle({required bool enable}) {
throw UnimplementedError('toggle() has not been implemented.');
}
... ...
... ... @@ -7,18 +7,17 @@ homepage: >-2
https://github.com/creativecreatorormaybenot/wakelock/tree/master/wakelock_platform_interface
environment:
sdk: ">=2.8.0 <3.0.0"
sdk: '>=2.12.0-0 <3.0.0'
flutter: ">=1.17.0 <2.0.0"
dependencies:
flutter:
sdk: flutter
meta: ^1.2.0
meta: 1.3.0-nullsafety.6
dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^4.1.3
pedantic: ^1.9.2
pedantic: ^1.10.0-nullsafety.3
... ...
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
// Ignoring until pigeon is migrated to null safety.
// See https://github.com/flutter/flutter/issues/71360.
// ignore: import_of_legacy_library_into_null_safe
import 'package:wakelock_platform_interface/messages.dart';
import 'package:wakelock_platform_interface/method_channel_wakelock.dart';
import 'package:wakelock_platform_interface/wakelock_platform_interface.dart';
class _ApiLogger implements TestWakelockApi {
final List<String> log = [];
ToggleMessage toggleMessage;
late ToggleMessage toggleMessage;
@override
IsEnabledMessage isEnabled() {
... ... @@ -33,14 +35,13 @@ void main() {
test('Cannot be implemented with `implements`', () {
expect(() {
WakelockPlatformInterface.instance =
ImplementsWakelockPlatformInterface();
}, throwsA(isInstanceOf<AssertionError>()));
ImplementsWakelockPlatformInterface(false);
}, throwsA(isInstanceOf<NoSuchMethodError>()));
});
test('Can be mocked with `implements`', () {
final mock = ImplementsWakelockPlatformInterface();
when(mock.isMock).thenReturn(true);
WakelockPlatformInterface.instance = mock;
WakelockPlatformInterface.instance =
ImplementsWakelockPlatformInterface(true);
});
test('Can be extended', () {
... ... @@ -50,9 +51,9 @@ void main() {
group('$MethodChannelWakelock', () {
final wakelock = MethodChannelWakelock();
_ApiLogger logger;
late final _ApiLogger logger;
setUp(() {
setUpAll(() {
logger = _ApiLogger();
TestWakelockApi.setup(logger);
});
... ... @@ -79,7 +80,16 @@ void main() {
});
}
class ImplementsWakelockPlatformInterface extends Mock
implements WakelockPlatformInterface {}
class ImplementsWakelockPlatformInterface implements WakelockPlatformInterface {
const ImplementsWakelockPlatformInterface(this.mocked);
final bool mocked;
@override
dynamic noSuchMethod(Invocation invocation) {
if (invocation.memberName == #isMock && mocked) return true;
throw NoSuchMethodError.withInvocation(this, invocation);
}
}
class ExtendsVideoPlayerPlatform extends WakelockPlatformInterface {}
... ...