diff --git a/platform_channels/android/app/src/main/kotlin/dev/flutter/platform_channels/AccelerometerStreamHandler.kt b/platform_channels/android/app/src/main/kotlin/dev/flutter/platform_channels/AccelerometerStreamHandler.kt
index cd3371ed7..845c7ad0d 100644
--- a/platform_channels/android/app/src/main/kotlin/dev/flutter/platform_channels/AccelerometerStreamHandler.kt
+++ b/platform_channels/android/app/src/main/kotlin/dev/flutter/platform_channels/AccelerometerStreamHandler.kt
@@ -32,6 +32,8 @@ class AccelerometerStreamHandler(sManager: SensorManager, s: Sensor) : EventChan
if (sensorEvent != null) {
val axisValues = listOf(sensorEvent.values[0], sensorEvent.values[1], sensorEvent.values[2])
eventSink.success(axisValues)
+ } else {
+ eventSink.error("DATA_UNAVAILABLE", "Cannot get accelerometer data", null)
}
}
}
diff --git a/platform_channels/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/platform_channels/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata
index 1d526a16e..919434a62 100644
--- a/platform_channels/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata
+++ b/platform_channels/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -2,6 +2,6 @@
+ location = "self:">
diff --git a/platform_channels/lib/main.dart b/platform_channels/lib/main.dart
index 80c0cb602..a33634e81 100644
--- a/platform_channels/lib/main.dart
+++ b/platform_channels/lib/main.dart
@@ -39,9 +39,7 @@ class DemoInfo {
final String demoTitle;
final String demoRoute;
- DemoInfo(this.demoTitle, this.demoRoute)
- : assert(demoTitle != null),
- assert(demoRoute != null);
+ DemoInfo(this.demoTitle, this.demoRoute);
}
List demoList = [
diff --git a/platform_channels/lib/src/add_pet_details.dart b/platform_channels/lib/src/add_pet_details.dart
index bb4834152..fe9756f08 100644
--- a/platform_channels/lib/src/add_pet_details.dart
+++ b/platform_channels/lib/src/add_pet_details.dart
@@ -64,7 +64,7 @@ class _AddPetDetailsState extends State {
groupValue: petType,
onChanged: (value) {
setState(() {
- petType = value;
+ petType = value!;
});
},
),
@@ -74,7 +74,7 @@ class _AddPetDetailsState extends State {
groupValue: petType,
onChanged: (value) {
setState(() {
- petType = value;
+ petType = value!;
});
},
),
diff --git a/platform_channels/lib/src/counter_method_channel.dart b/platform_channels/lib/src/counter_method_channel.dart
index 69fc2d882..fe945b118 100644
--- a/platform_channels/lib/src/counter_method_channel.dart
+++ b/platform_channels/lib/src/counter_method_channel.dart
@@ -14,16 +14,16 @@ class Counter {
static MethodChannel methodChannel = const MethodChannel('methodChannelDemo');
/// This method is responsible to increment and return the value of count.
- static Future increment({int counterValue}) async {
+ static Future increment({required int counterValue}) async {
final result = await methodChannel
.invokeMethod('increment', {'count': counterValue});
- return result;
+ return result!;
}
/// This method is responsible to decrement and return the value of count.
- static Future decrement({int counterValue}) async {
+ static Future decrement({required int counterValue}) async {
final result = await methodChannel
.invokeMethod('decrement', {'count': counterValue});
- return result;
+ return result!;
}
}
diff --git a/platform_channels/lib/src/event_channel_demo.dart b/platform_channels/lib/src/event_channel_demo.dart
index 02d569a83..0f84f3ae1 100644
--- a/platform_channels/lib/src/event_channel_demo.dart
+++ b/platform_channels/lib/src/event_channel_demo.dart
@@ -26,21 +26,21 @@ class EventChannelDemo extends StatelessWidget {
stream: Accelerometer.readings,
builder: (context, snapshot) {
if (snapshot.hasError) {
- return Text((snapshot.error as PlatformException).message);
+ return Text((snapshot.error as PlatformException).message!);
} else if (snapshot.hasData) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
- 'x axis: ' + snapshot.data.x.toStringAsFixed(3),
+ 'x axis: ' + snapshot.data!.x.toStringAsFixed(3),
style: textStyle,
),
Text(
- 'y axis: ' + snapshot.data.y.toStringAsFixed(3),
+ 'y axis: ' + snapshot.data!.y.toStringAsFixed(3),
style: textStyle,
),
Text(
- 'z axis: ' + snapshot.data.z.toStringAsFixed(3),
+ 'z axis: ' + snapshot.data!.z.toStringAsFixed(3),
style: textStyle,
)
],
diff --git a/platform_channels/lib/src/image_basic_message_channel.dart b/platform_channels/lib/src/image_basic_message_channel.dart
index 6c127dc70..240bd6b6f 100644
--- a/platform_channels/lib/src/image_basic_message_channel.dart
+++ b/platform_channels/lib/src/image_basic_message_channel.dart
@@ -15,7 +15,7 @@ class PlatformImageFetcher {
/// Method responsible for providing the platform image.
static Future getImage() async {
- final reply = await _basicMessageChannel.send('getImage') as Uint8List;
+ final reply = await _basicMessageChannel.send('getImage') as Uint8List?;
if (reply == null) {
throw PlatformException(
code: 'Error',
diff --git a/platform_channels/lib/src/method_channel_demo.dart b/platform_channels/lib/src/method_channel_demo.dart
index 6b80e5f4a..d1389c736 100644
--- a/platform_channels/lib/src/method_channel_demo.dart
+++ b/platform_channels/lib/src/method_channel_demo.dart
@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
import 'package:platform_channels/src/counter_method_channel.dart';
/// The widget demonstrates how to use [MethodChannel] to invoke platform methods.
@@ -45,7 +46,7 @@ class _MethodChannelDemoState extends State {
} catch (error) {
showErrorMessage(
context,
- error.message as String,
+ (error as PlatformException).message!,
);
}
},
@@ -63,7 +64,7 @@ class _MethodChannelDemoState extends State {
} catch (error) {
showErrorMessage(
context,
- error.message as String,
+ (error as PlatformException).message!,
);
}
},
diff --git a/platform_channels/lib/src/pet_list_message_channel.dart b/platform_channels/lib/src/pet_list_message_channel.dart
index 3db2fc8d0..3148f4ebc 100644
--- a/platform_channels/lib/src/pet_list_message_channel.dart
+++ b/platform_channels/lib/src/pet_list_message_channel.dart
@@ -44,7 +44,7 @@ class PetListMessageChannel {
/// A model class that provides [petList] which is received from platform.
class PetListModel {
PetListModel({
- this.petList,
+ required this.petList,
});
final List petList;
@@ -65,8 +65,8 @@ class PetListModel {
/// A simple model that provides pet details like [petType] and [breed] of pet.
class PetDetails {
PetDetails({
- this.petType,
- this.breed,
+ required this.petType,
+ required this.breed,
});
final String petType;
diff --git a/platform_channels/lib/src/pet_list_screen.dart b/platform_channels/lib/src/pet_list_screen.dart
index 2775c6244..f7861afda 100644
--- a/platform_channels/lib/src/pet_list_screen.dart
+++ b/platform_channels/lib/src/pet_list_screen.dart
@@ -14,7 +14,7 @@ class PetListScreen extends StatefulWidget {
}
class _PetListScreenState extends State {
- PetListModel petListModel;
+ PetListModel petListModel = PetListModel(petList: []);
final scaffoldKey = GlobalKey();
@override
@@ -22,7 +22,7 @@ class _PetListScreenState extends State {
super.initState();
// Receives a string of json object from the platform and converts it
// to PetModel.
- const BasicMessageChannel('stringCodecDemo', StringCodec())
+ const BasicMessageChannel('stringCodecDemo', StringCodec())
.setMessageHandler((message) async {
if (message == null) {
showSnackBar('An error occurred while adding pet details.', context);
@@ -31,7 +31,7 @@ class _PetListScreenState extends State {
petListModel = PetListModel.fromJson(message);
});
}
- return;
+ return null;
});
}
@@ -48,7 +48,7 @@ class _PetListScreenState extends State {
Navigator.pushNamed(context, '/addPetDetails');
},
),
- body: petListModel?.petList?.isEmpty ?? true
+ body: petListModel.petList.isEmpty
? const Center(child: Text('Enter Pet Details'))
: BuildPetList(petListModel.petList),
);
@@ -79,7 +79,7 @@ class BuildPetList extends StatelessWidget {
await PetListMessageChannel.removePet(index);
showSnackBar('Removed successfully!', context);
} catch (error) {
- showSnackBar(error.message.toString(), context);
+ showSnackBar((error as PlatformException).message!, context);
}
},
),
diff --git a/platform_channels/lib/src/platform_image_demo.dart b/platform_channels/lib/src/platform_image_demo.dart
index 6689e0cae..593026daf 100644
--- a/platform_channels/lib/src/platform_image_demo.dart
+++ b/platform_channels/lib/src/platform_image_demo.dart
@@ -18,7 +18,7 @@ class PlatformImageDemo extends StatefulWidget {
}
class _PlatformImageDemoState extends State {
- Future imageData;
+ Future? imageData;
@override
Widget build(BuildContext context) {
@@ -41,12 +41,14 @@ class _PlatformImageDemoState extends State {
return const Placeholder();
} else if (snapshot.hasError) {
return Center(
- child: Text(snapshot.error.toString()),
+ child: Text(
+ (snapshot.error as PlatformException).message!,
+ ),
);
} else if (snapshot.connectionState ==
ConnectionState.done) {
return Image.memory(
- snapshot.data,
+ snapshot.data!,
fit: BoxFit.fill,
);
}
diff --git a/platform_channels/pubspec.lock b/platform_channels/pubspec.lock
index 29526b6b5..0dd2532a0 100644
--- a/platform_channels/pubspec.lock
+++ b/platform_channels/pubspec.lock
@@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
- version: "2.6.1"
+ version: "2.5.0"
boolean_selector:
dependency: transitive
description:
@@ -113,7 +113,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
- version: "1.8.1"
+ version: "1.8.0"
stack_trace:
dependency: transitive
description:
@@ -148,7 +148,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
- version: "0.3.0"
+ version: "0.2.19"
typed_data:
dependency: transitive
description:
diff --git a/platform_channels/pubspec.yaml b/platform_channels/pubspec.yaml
index fb8b16ea8..0b630eb1a 100644
--- a/platform_channels/pubspec.yaml
+++ b/platform_channels/pubspec.yaml
@@ -4,13 +4,13 @@ description: A new Flutter project.
version: 1.0.0+1
environment:
- sdk: ">=2.7.0 <3.0.0"
+ sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
- cupertino_icons: ^1.0.0
+ cupertino_icons: ^1.0.3
dev_dependencies:
flutter_test:
diff --git a/platform_channels/test/src/event_channel_demo_test.dart b/platform_channels/test/src/event_channel_demo_test.dart
index 9082b14aa..c79f4bba2 100644
--- a/platform_channels/test/src/event_channel_demo_test.dart
+++ b/platform_channels/test/src/event_channel_demo_test.dart
@@ -19,8 +19,8 @@ void main() {
// calls the BinaryMessenger.setMessageHandler registered for the EventChannel
// and add the incoming message to the StreamController used by the EventChannel
// after decoding the message with codec used by the EventChannel.
- void emitValues(ByteData event) {
- ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
+ void emitValues(ByteData? event) {
+ ServicesBinding.instance?.defaultBinaryMessenger.handlePlatformMessage(
'eventChannelDemo',
event,
(reply) {},
@@ -29,7 +29,7 @@ void main() {
// Register a mock for EventChannel. EventChannel under the hood uses
// MethodChannel to listen and cancel the created stream.
- ServicesBinding.instance.defaultBinaryMessenger
+ ServicesBinding.instance?.defaultBinaryMessenger
.setMockMessageHandler('eventChannelDemo', (message) async {
// Decode the message into MethodCallHandler.
final methodCall = standardMethod.decodeMethodCall(message);
diff --git a/platform_channels/test/src/pet_list_screen_test.dart b/platform_channels/test/src/pet_list_screen_test.dart
index 0687ab592..88d73b351 100644
--- a/platform_channels/test/src/pet_list_screen_test.dart
+++ b/platform_channels/test/src/pet_list_screen_test.dart
@@ -13,7 +13,7 @@ import 'package:platform_channels/src/pet_list_screen.dart';
void main() {
group('PetListScreen tests', () {
const basicMessageChannel =
- BasicMessageChannel('stringCodecDemo', StringCodec());
+ BasicMessageChannel('stringCodecDemo', StringCodec());
var petList = [
{
@@ -22,21 +22,21 @@ void main() {
}
];
- PetListModel petListModel;
+ PetListModel? petListModel;
setUpAll(() {
// Mock for the pet list received from the platform.
basicMessageChannel.setMockMessageHandler((message) async {
- petListModel = PetListModel.fromJson(message);
- return;
+ petListModel = PetListModel.fromJson(message!);
+ return null;
});
// Mock for the index received from the Dart to delete the pet details,
// and send the updated pet list back to Dart.
- const BasicMessageChannel('binaryCodecDemo', BinaryCodec())
+ const BasicMessageChannel('binaryCodecDemo', BinaryCodec())
.setMockMessageHandler((message) async {
// Convert the ByteData to String.
- final index = utf8.decoder.convert(message.buffer
+ final index = utf8.decoder.convert(message!.buffer
.asUint8List(message.offsetInBytes, message.lengthInBytes));
// Remove the pet details at the given index.
@@ -45,7 +45,8 @@ void main() {
// Send the updated petList back.
final map = {'petList': petList};
await basicMessageChannel.send(json.encode(map));
- return;
+
+ return null;
});
});
@@ -60,7 +61,7 @@ void main() {
basicMessageChannel.send(json.encode(map));
// Get the details of first pet.
- final petDetails = petListModel.petList.first;
+ final petDetails = petListModel!.petList.first;
expect(petDetails.petType, 'Dog');
expect(petDetails.breed, 'Pug');
});
@@ -68,7 +69,7 @@ void main() {
testWidgets('BuildPetList test', (tester) async {
await tester.pumpWidget(MaterialApp(
home: Scaffold(
- body: BuildPetList(petListModel.petList),
+ body: BuildPetList(petListModel!.petList),
),
));
@@ -77,7 +78,7 @@ void main() {
// Delete the pet details.
await tester.tap(find.byIcon(Icons.delete).first);
- expect(petListModel.petList, isEmpty);
+ expect(petListModel!.petList, isEmpty);
});
});
}