Skip to content

Instantly share code, notes, and snippets.

@RedBrogdon
Last active October 22, 2020 00:45
Show Gist options
  • Save RedBrogdon/82ec268ff15fa501a42dfea7b0d17dd7 to your computer and use it in GitHub Desktop.
Save RedBrogdon/82ec268ff15fa501a42dfea7b0d17dd7 to your computer and use it in GitHub Desktop.
Some null-safe Flutter code
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({required this.title});
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int a = 0;
int? b = 1;
int? c;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('a is $a, of type ${a.runtimeType}'),
Text('b is $b, of type ${b.runtimeType}'),
Text('c is $c, of type ${c.runtimeType}'),
Text(<Null>[] is List<int>
? 'Running without sound null safety. :('
: 'Running with sound null safety!'),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {},
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment