Enable null safety by default in templates (#78619)

This commit is contained in:
Michael Thomsen
2021-03-30 10:16:05 +02:00
committed by GitHub
parent e93590474d
commit 2cdd51900c
13 changed files with 25 additions and 151 deletions

View File

@@ -32,7 +32,7 @@ class MyApp extends StatelessWidget {
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({Key? key, required this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
@@ -135,8 +135,10 @@ class _MyAppState extends State<MyApp> {
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion = await {{pluginDartClass}}.platformVersion;
platformVersion =
await {{pluginDartClass}}.platformVersion ?? 'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}

View File

@@ -40,7 +40,7 @@ void main() {
expect(
find.byWidgetPredicate(
(Widget widget) => widget is Text &&
widget.data.startsWith('Running on:'),
widget.data!.startsWith('Running on:'),
),
findsOneWidget,
);