Skip to content

Commit ad3002d

Browse files
authored
Adds tested null safe code excerpts (#5127)
1 parent 2ba67da commit ad3002d

File tree

16 files changed

+310
-54
lines changed

16 files changed

+310
-54
lines changed

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ jobs:
3737
- TASK="./tool/check-code.sh"
3838
- CHANNEL=dev
3939

40+
- name: "Dev channel: null safety code check"
41+
env:
42+
- TASK="./tool/check-code.sh --null-safety"
43+
- CHANNEL=dev
44+
4045
- name: "Dev channel: jekyll build"
4146
env:
4247
- TASK="bundle exec jekyll build"
@@ -47,6 +52,11 @@ jobs:
4752
- TASK="./tool/check-code.sh"
4853
- CHANNEL=beta
4954

55+
- name: "Beta channel: null safety code check"
56+
env:
57+
- TASK="./tool/check-code.sh --null-safety"
58+
- CHANNEL=beta
59+
5060
- name: "Beta channel: jekyll build"
5161
env:
5262
- TASK="bundle exec jekyll build"

build.excerpt.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ targets:
33
sources:
44
include:
55
- examples/**
6+
- null_safety_examples/**
7+
# Some default includes that aren't really used here but will prevent
8+
# false-negative warnings:
9+
- $package$
10+
- lib/$lib$
611
exclude:
712
- '**/.*/**'
813
- '**/android/**'

null_safety_examples/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Flutter null safety example apps
2+
3+
To analyze, test and run individual apps, execute the following commands from
4+
the repo root (`$PROJECT` represents the app project path, such as
5+
`null_safety_examples/layout/base`):
6+
7+
1. `flutter create --no-overwrite $PROJECT`
8+
1. `cd $PROJECT`
9+
1. `flutter analyze`
10+
1. `flutter test`
11+
1. `flutter run`
12+
13+
To learn more about setting up Flutter and running apps, see
14+
[flutter.dev/get-started][].
15+
16+
[flutter.dev/get-started]: /docs/get-started
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2021 The Flutter team. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// ignore_for_file: avoid_init_to_null
6+
7+
import 'package:flutter/material.dart';
8+
9+
void main() => runApp(MyApp());
10+
11+
// #docregion MyApp
12+
class MyApp extends StatelessWidget {
13+
final int anInt = 3; // Cannot be null.
14+
final int? aNullableInt = null; // Can be null.
15+
16+
@override
17+
Widget build(BuildContext context) {
18+
return MaterialApp(
19+
title: 'Nullable Fields Demo',
20+
home: Scaffold(
21+
appBar: AppBar(
22+
title: Text('Nullable Fields Demo'),
23+
),
24+
body: Center(
25+
child: Column(
26+
children: [
27+
Text('anInt is $anInt.'),
28+
Text('aNullableInt is $aNullableInt.'),
29+
],
30+
),
31+
),
32+
),
33+
);
34+
}
35+
}
36+
// #enddocregion MyApp
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: null_safety_basics
2+
description: Some code to demonstrate null safety.
3+
version: 1.0.0
4+
5+
environment:
6+
sdk: '>=2.12.0-0 <3.0.0'
7+
8+
dependencies:
9+
flutter:
10+
sdk: flutter
11+
12+
dev_dependencies:
13+
flutter_test:
14+
sdk: flutter
15+
16+
flutter:
17+
uses-material-design: true
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
**/ios/Flutter/.last_build_id
26+
.dart_tool/
27+
.flutter-plugins
28+
.flutter-plugins-dependencies
29+
.packages
30+
.pub-cache/
31+
.pub/
32+
/build/
33+
34+
# Web related
35+
lib/generated_plugin_registrant.dart
36+
37+
# Symbolication related
38+
app.*.symbols
39+
40+
# Obfuscation related
41+
app.*.map.json
42+
43+
# Android Studio will place build artifacts here
44+
/android/app/debug
45+
/android/app/profile
46+
/android/app/release
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: ff03a9c362b10e637d6a62f07fffc4eb17f9ea7c
8+
channel: master
9+
10+
project_type: app
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# base
2+
3+
A new Flutter project.
4+
5+
## Getting Started
6+
7+
This project is a starting point for a Flutter application.
8+
9+
A few resources to get you started if this is your first Flutter project:
10+
11+
- [Lab: Write your first Flutter app](/docs/get-started/codelab)
12+
- [Cookbook: Useful Flutter samples](/docs/cookbook)
13+
14+
For help getting started with Flutter, view our
15+
[online documentation](/docs), which offers tutorials,
16+
samples, guidance on mobile development, and a full API reference.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2021 The Flutter team. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
7+
void main() => runApp(MyApp());
8+
9+
// #docregion MyApp
10+
class MyApp extends StatelessWidget {
11+
@override
12+
Widget build(BuildContext context) {
13+
return MaterialApp(
14+
title: 'Flutter layout demo',
15+
home: Scaffold(
16+
appBar: AppBar(
17+
title: Text('Flutter layout demo'),
18+
),
19+
// #docregion centered-text
20+
body: Center(
21+
// #docregion text
22+
child: Text('Hello World'),
23+
// #enddocregion text
24+
),
25+
// #enddocregion centered-text
26+
),
27+
);
28+
}
29+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: layout
2+
description: >
3+
Sample app from "Building Layouts", https://flutter.dev/docs/development/ui/layout.
4+
version: 1.0.0
5+
6+
environment:
7+
sdk: '>=2.12.0-0 <3.0.0'
8+
9+
dependencies:
10+
flutter:
11+
sdk: flutter
12+
cupertino_icons: ^0.1.2
13+
14+
dev_dependencies:
15+
flutter_test:
16+
sdk: flutter
17+
18+
flutter:
19+
uses-material-design: true

0 commit comments

Comments
 (0)