Unverified Commit 06f051b2 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Migrate remaining examples to null-safety (#74857)

parent c505ee79
...@@ -666,7 +666,7 @@ Future<void> _runFrameworkTests() async { ...@@ -666,7 +666,7 @@ Future<void> _runFrameworkTests() async {
await _runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'android_semantics_testing')); await _runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'android_semantics_testing'));
await _runFlutterTest(path.join(flutterRoot, 'dev', 'manual_tests')); await _runFlutterTest(path.join(flutterRoot, 'dev', 'manual_tests'));
await _runFlutterTest(path.join(flutterRoot, 'dev', 'tools', 'vitool')); await _runFlutterTest(path.join(flutterRoot, 'dev', 'tools', 'vitool'));
await _runFlutterTest(path.join(flutterRoot, 'examples', 'hello_world')); await _runFlutterTest(path.join(flutterRoot, 'examples', 'hello_world'), options: soundNullSafetyOptions);
await _runFlutterTest(path.join(flutterRoot, 'examples', 'layers'), options: soundNullSafetyOptions); await _runFlutterTest(path.join(flutterRoot, 'examples', 'layers'), options: soundNullSafetyOptions);
await _runFlutterTest(path.join(flutterRoot, 'dev', 'benchmarks', 'test_apps', 'stocks')); await _runFlutterTest(path.join(flutterRoot, 'dev', 'benchmarks', 'test_apps', 'stocks'));
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_driver'), tests: <String>[path.join('test', 'src', 'real_tests')]); await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_driver'), tests: <String>[path.join('test', 'src', 'real_tests')]);
......
...@@ -11,7 +11,6 @@ void main() { ...@@ -11,7 +11,6 @@ void main() {
} }
class FlutterView extends StatelessWidget { class FlutterView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
...@@ -33,8 +32,8 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -33,8 +32,8 @@ class _MyHomePageState extends State<MyHomePage> {
static const String _channel = 'increment'; static const String _channel = 'increment';
static const String _pong = 'pong'; static const String _pong = 'pong';
static const String _emptyMessage = ''; static const String _emptyMessage = '';
static const BasicMessageChannel<String> platform = static const BasicMessageChannel<String?> platform =
BasicMessageChannel<String>(_channel, StringCodec()); BasicMessageChannel<String?>(_channel, StringCodec());
int _counter = 0; int _counter = 0;
...@@ -44,7 +43,7 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -44,7 +43,7 @@ class _MyHomePageState extends State<MyHomePage> {
platform.setMessageHandler(_handlePlatformIncrement); platform.setMessageHandler(_handlePlatformIncrement);
} }
Future<String> _handlePlatformIncrement(String message) async { Future<String> _handlePlatformIncrement(String? message) async {
setState(() { setState(() {
_counter++; _counter++;
}); });
......
...@@ -2,7 +2,7 @@ name: flutter_view ...@@ -2,7 +2,7 @@ name: flutter_view
description: A new flutter project. description: A new flutter project.
environment: environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0" sdk: ">=2.12.0-0 <3.0.0"
dependencies: dependencies:
flutter: flutter:
......
...@@ -81,7 +81,7 @@ mhBKvYQc85gja0s1c+1VXA== ...@@ -81,7 +81,7 @@ mhBKvYQc85gja0s1c+1VXA==
class MyHttpOverrides extends HttpOverrides { class MyHttpOverrides extends HttpOverrides {
@override @override
HttpClient createHttpClient(SecurityContext context) { HttpClient createHttpClient(SecurityContext? context) {
return super.createHttpClient( return super.createHttpClient(
(context ?? SecurityContext())..setTrustedCertificatesBytes(certificate.codeUnits) (context ?? SecurityContext())..setTrustedCertificatesBytes(certificate.codeUnits)
); );
...@@ -141,7 +141,7 @@ class MyApp extends StatelessWidget { ...@@ -141,7 +141,7 @@ class MyApp extends StatelessWidget {
} }
class MyHomePage extends StatefulWidget { class MyHomePage extends StatefulWidget {
const MyHomePage({Key key, this.title, this.port}) : super(key: key); const MyHomePage({Key? key, required this.title, required this.port}) : super(key: key);
final String title; final String title;
final int port; final int port;
...@@ -164,7 +164,7 @@ class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin { ...@@ -164,7 +164,7 @@ class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
frameBuilder: ( frameBuilder: (
BuildContext context, BuildContext context,
Widget child, Widget child,
int frame, int? frame,
bool wasSynchronouslyLoaded, bool wasSynchronouslyLoaded,
) { ) {
if (frame == 0 && !completer.isCompleted) { if (frame == 0 && !completer.isCompleted) {
...@@ -177,17 +177,17 @@ class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin { ...@@ -177,17 +177,17 @@ class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final List<AnimationController> controllers = List<AnimationController>.filled(IMAGES, null); final List<AnimationController> controllers = <AnimationController>[
for (int i = 0; i < IMAGES; i++) { for (int i = 0; i < IMAGES; i++)
controllers[i] = AnimationController( AnimationController(
duration: const Duration(milliseconds: 3600), duration: const Duration(milliseconds: 3600),
vsync: this, vsync: this,
)..repeat(); )..repeat(),
} ];
final List<Completer<bool>> completers = List<Completer<bool>>.filled(IMAGES, null); final List<Completer<bool>> completers = <Completer<bool>>[
for (int i = 0; i < IMAGES; i++) { for (int i = 0; i < IMAGES; i++)
completers[i] = Completer<bool>(); Completer<bool>(),
} ];
final List<Future<bool>> futures = completers.map( final List<Future<bool>> futures = completers.map(
(Completer<bool> completer) => completer.future).toList(); (Completer<bool> completer) => completer.future).toList();
final DateTime started = DateTime.now(); final DateTime started = DateTime.now();
......
...@@ -4,7 +4,7 @@ description: Simple Flutter project used for benchmarking image loading over net ...@@ -4,7 +4,7 @@ description: Simple Flutter project used for benchmarking image loading over net
version: 1.0.0+1 version: 1.0.0+1
environment: environment:
sdk: ">=2.1.0 <3.0.0" sdk: ">=2.12.0-0 <3.0.0"
dependencies: dependencies:
flutter: flutter:
......
...@@ -24,7 +24,7 @@ class _PlatformChannelState extends State<PlatformChannel> { ...@@ -24,7 +24,7 @@ class _PlatformChannelState extends State<PlatformChannel> {
Future<void> _getBatteryLevel() async { Future<void> _getBatteryLevel() async {
String batteryLevel; String batteryLevel;
try { try {
final int result = await methodChannel.invokeMethod('getBatteryLevel'); final int? result = await methodChannel.invokeMethod('getBatteryLevel');
batteryLevel = 'Battery level: $result%.'; batteryLevel = 'Battery level: $result%.';
} on PlatformException { } on PlatformException {
batteryLevel = 'Failed to get battery level.'; batteryLevel = 'Failed to get battery level.';
...@@ -40,7 +40,7 @@ class _PlatformChannelState extends State<PlatformChannel> { ...@@ -40,7 +40,7 @@ class _PlatformChannelState extends State<PlatformChannel> {
eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError); eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError);
} }
void _onEvent(Object event) { void _onEvent(Object? event) {
setState(() { setState(() {
_chargingStatus = _chargingStatus =
"Battery status: ${event == 'charging' ? '' : 'dis'}charging."; "Battery status: ${event == 'charging' ? '' : 'dis'}charging.";
......
name: platform_channel name: platform_channel
environment: environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0" sdk: ">=2.12.0-0 <3.0.0"
dependencies: dependencies:
flutter: flutter:
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// TODO(goderbauer): migrate this file to null-safety when flutter_driver is null-safe.
// @dart = 2.9
import 'package:flutter_driver/flutter_driver.dart'; import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf; import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
......
...@@ -24,7 +24,7 @@ class _PlatformChannelState extends State<PlatformChannel> { ...@@ -24,7 +24,7 @@ class _PlatformChannelState extends State<PlatformChannel> {
Future<void> _getBatteryLevel() async { Future<void> _getBatteryLevel() async {
String batteryLevel; String batteryLevel;
try { try {
final int result = await methodChannel.invokeMethod('getBatteryLevel'); final int? result = await methodChannel.invokeMethod('getBatteryLevel');
batteryLevel = 'Battery level: $result%.'; batteryLevel = 'Battery level: $result%.';
} on PlatformException { } on PlatformException {
batteryLevel = 'Failed to get battery level.'; batteryLevel = 'Failed to get battery level.';
...@@ -40,7 +40,7 @@ class _PlatformChannelState extends State<PlatformChannel> { ...@@ -40,7 +40,7 @@ class _PlatformChannelState extends State<PlatformChannel> {
eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError); eventChannel.receiveBroadcastStream().listen(_onEvent, onError: _onError);
} }
void _onEvent(Object event) { void _onEvent(Object? event) {
setState(() { setState(() {
_chargingStatus = _chargingStatus =
"Battery status: ${event == 'charging' ? '' : 'dis'}charging."; "Battery status: ${event == 'charging' ? '' : 'dis'}charging.";
......
name: platform_channel_swift name: platform_channel_swift
environment: environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0" sdk: ">=2.12.0-0 <3.0.0"
dependencies: dependencies:
flutter: flutter:
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// TODO(goderbauer): migrate this file to null-safety when flutter_driver is null-safe.
// @dart = 2.9
import 'package:flutter_driver/flutter_driver.dart'; import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf; import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
......
...@@ -25,7 +25,7 @@ class PlatformView extends StatelessWidget { ...@@ -25,7 +25,7 @@ class PlatformView extends StatelessWidget {
} }
class MyHomePage extends StatefulWidget { class MyHomePage extends StatefulWidget {
const MyHomePage({Key key, this.title}) : super(key: key); const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title; final String title;
...@@ -46,10 +46,10 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -46,10 +46,10 @@ class _MyHomePageState extends State<MyHomePage> {
} }
Future<void> _launchPlatformCount() async { Future<void> _launchPlatformCount() async {
final int platformCounter = final int? platformCounter =
await _methodChannel.invokeMethod('switchView', _counter); await _methodChannel.invokeMethod('switchView', _counter);
setState(() { setState(() {
_counter = platformCounter; _counter = platformCounter!;
}); });
} }
......
name: platform_view name: platform_view
environment: environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0" sdk: ">=2.12.0-0 <3.0.0"
dependencies: dependencies:
flutter: flutter:
......
name: splash name: splash
environment: environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0" sdk: ">=2.12.0-0 <3.0.0"
dependencies: dependencies:
flutter: flutter:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment