Skip to content

Commit 5a48a99

Browse files
authored
Migrate 102-complete to NNBD (#220)
* Migrate. * Update SDK version. * Update version for intl.
1 parent 7a3caca commit 5a48a99

File tree

8 files changed

+40
-43
lines changed

8 files changed

+40
-43
lines changed

mdc_100_series/lib/app.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ShrineApp extends StatelessWidget {
3535
);
3636
}
3737

38-
Route<dynamic> _getRoute(RouteSettings settings) {
38+
Route<dynamic>? _getRoute(RouteSettings settings) {
3939
if (settings.name != '/login') {
4040
return null;
4141
}

mdc_100_series/lib/home.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class HomePage extends StatelessWidget {
2424
List<Card> _buildGridCards(BuildContext context) {
2525
List<Product> products = ProductsRepository.loadProducts(Category.all);
2626

27-
if (products == null || products.isEmpty) {
27+
if (products.isEmpty) {
2828
return const <Card>[];
2929
}
3030

mdc_100_series/lib/model/product.dart

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,16 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import 'package:flutter/foundation.dart';
16-
1715
enum Category { all, accessories, clothing, home, }
1816

1917
class Product {
2018
const Product({
21-
@required this.category,
22-
@required this.id,
23-
@required this.isFeatured,
24-
@required this.name,
25-
@required this.price,
26-
}) : assert(category != null),
27-
assert(id != null),
28-
assert(isFeatured != null),
29-
assert(name != null),
30-
assert(price != null);
19+
required this.category,
20+
required this.id,
21+
required this.isFeatured,
22+
required this.name,
23+
required this.price,
24+
});
3125

3226
final Category category;
3327
final int id;

mdc_100_series/lib/supplemental/asymmetric_view.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import 'product_columns.dart';
2020
class AsymmetricView extends StatelessWidget {
2121
final List<Product> products;
2222

23-
AsymmetricView({Key key, this.products});
23+
AsymmetricView({Key? key, required this.products});
2424

2525
List<Container> _buildColumns(BuildContext context) {
26-
if (products == null || products.isEmpty) {
26+
if (products.isEmpty) {
2727
return <Container>[];
2828
}
2929

mdc_100_series/lib/supplemental/cut_corners_border.dart

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ import 'package:flutter/widgets.dart';
1919

2020
class CutCornersBorder extends OutlineInputBorder {
2121
const CutCornersBorder({
22-
BorderSide borderSide: const BorderSide(),
23-
BorderRadius borderRadius: const BorderRadius.all(Radius.circular(2.0)),
24-
this.cut: 7.0,
25-
double gapPadding: 2.0,
22+
BorderSide borderSide = const BorderSide(),
23+
BorderRadius borderRadius = const BorderRadius.all(Radius.circular(2.0)),
24+
this.cut = 7.0,
25+
double gapPadding = 2.0,
2626
}) : super(
2727
borderSide: borderSide,
2828
borderRadius: borderRadius,
2929
gapPadding: gapPadding);
3030

3131
@override
3232
CutCornersBorder copyWith({
33-
BorderSide borderSide,
34-
BorderRadius borderRadius,
35-
double gapPadding,
36-
double cut,
33+
BorderSide? borderSide,
34+
BorderRadius? borderRadius,
35+
double? gapPadding,
36+
double? cut,
3737
}) {
3838
return CutCornersBorder(
3939
borderRadius: borderRadius ?? this.borderRadius,
@@ -46,11 +46,11 @@ class CutCornersBorder extends OutlineInputBorder {
4646
final double cut;
4747

4848
@override
49-
ShapeBorder lerpFrom(ShapeBorder a, double t) {
49+
ShapeBorder? lerpFrom(ShapeBorder? a, double t) {
5050
if (a is CutCornersBorder) {
5151
final CutCornersBorder outline = a;
5252
return CutCornersBorder(
53-
borderRadius: BorderRadius.lerp(outline.borderRadius, borderRadius, t),
53+
borderRadius: BorderRadius.lerp(outline.borderRadius, borderRadius, t)!,
5454
borderSide: BorderSide.lerp(outline.borderSide, borderSide, t),
5555
cut: cut,
5656
gapPadding: outline.gapPadding,
@@ -60,11 +60,11 @@ class CutCornersBorder extends OutlineInputBorder {
6060
}
6161

6262
@override
63-
ShapeBorder lerpTo(ShapeBorder b, double t) {
63+
ShapeBorder? lerpTo(ShapeBorder? b, double t) {
6464
if (b is CutCornersBorder) {
6565
final CutCornersBorder outline = b;
6666
return CutCornersBorder(
67-
borderRadius: BorderRadius.lerp(borderRadius, outline.borderRadius, t),
67+
borderRadius: BorderRadius.lerp(borderRadius, outline.borderRadius, t)!,
6868
borderSide: BorderSide.lerp(borderSide, outline.borderSide, t),
6969
cut: cut,
7070
gapPadding: outline.gapPadding,
@@ -103,12 +103,11 @@ class CutCornersBorder extends OutlineInputBorder {
103103
void paint(
104104
Canvas canvas,
105105
Rect rect, {
106-
double gapStart,
106+
double? gapStart,
107107
double gapExtent: 0.0,
108108
double gapPercentage: 0.0,
109-
TextDirection textDirection,
109+
TextDirection? textDirection,
110110
}) {
111-
assert(gapExtent != null);
112111
assert(gapPercentage >= 0.0 && gapPercentage <= 1.0);
113112

114113
final Paint paint = borderSide.toPaint();
@@ -117,8 +116,8 @@ class CutCornersBorder extends OutlineInputBorder {
117116
canvas.drawPath(_notchedCornerPath(outer.middleRect), paint);
118117
} else {
119118
final double extent =
120-
lerpDouble(0.0, gapExtent + gapPadding * 2.0, gapPercentage);
121-
switch (textDirection) {
119+
lerpDouble(0.0, gapExtent + gapPadding * 2.0, gapPercentage)!;
120+
switch (textDirection!) {
122121
case TextDirection.rtl:
123122
{
124123
final Path path = _notchedCornerPath(

mdc_100_series/lib/supplemental/product_card.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import 'package:intl/intl.dart';
1818
import '../model/product.dart';
1919

2020
class ProductCard extends StatelessWidget {
21-
ProductCard({this.imageAspectRatio: 33 / 49, this.product})
22-
: assert(imageAspectRatio == null || imageAspectRatio > 0);
21+
ProductCard({this.imageAspectRatio = 33 / 49, required this.product})
22+
: assert(imageAspectRatio > 0);
2323

2424
final double imageAspectRatio;
2525
final Product product;
@@ -54,15 +54,15 @@ class ProductCard extends StatelessWidget {
5454
crossAxisAlignment: CrossAxisAlignment.center,
5555
children: <Widget>[
5656
Text(
57-
product == null ? '' : product.name,
57+
product.name,
5858
style: theme.textTheme.headline6,
5959
softWrap: false,
6060
overflow: TextOverflow.ellipsis,
6161
maxLines: 1,
6262
),
6363
SizedBox(height: 4.0),
6464
Text(
65-
product == null ? '' : formatter.format(product.price),
65+
formatter.format(product.price),
6666
style: theme.textTheme.subtitle2,
6767
),
6868
],

mdc_100_series/lib/supplemental/product_columns.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ import 'product_card.dart';
1919

2020
class TwoProductCardColumn extends StatelessWidget {
2121
TwoProductCardColumn({
22-
this.bottom,
22+
required this.bottom,
2323
this.top,
24-
}) : assert(bottom != null);
24+
});
2525

26-
final Product bottom, top;
26+
final Product bottom;
27+
final Product? top;
2728

2829
@override
2930
Widget build(BuildContext context) {
@@ -46,7 +47,7 @@ class TwoProductCardColumn extends StatelessWidget {
4647
child: top != null
4748
? ProductCard(
4849
imageAspectRatio: imageAspectRatio,
49-
product: top,
50+
product: top!,
5051
)
5152
: SizedBox(
5253
height: heightOfCards,
@@ -67,7 +68,7 @@ class TwoProductCardColumn extends StatelessWidget {
6768
}
6869

6970
class OneProductCardColumn extends StatelessWidget {
70-
OneProductCardColumn({this.product});
71+
OneProductCardColumn({required this.product});
7172

7273
final Product product;
7374

mdc_100_series/pubspec.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
name: Shrine
22
description: Learn how to use Material for structure and layout.
33

4+
environment:
5+
sdk: '>=2.12.0-0 <3.0.0'
6+
47
dependencies:
58
flutter:
69
sdk: flutter
7-
intl: ^0.15.6
10+
intl: ^0.17.0-nullsafety.2
811

912
cupertino_icons: ^0.1.0
1013
shrine_images: 1.1.1

0 commit comments

Comments
 (0)