Skip to content

Commit

Permalink
Migrate 101-starter to NNBD (#222)
Browse files Browse the repository at this point in the history
* Update version.

* Migrate.
  • Loading branch information
pennzht committed Nov 24, 2020
1 parent 3027117 commit 2f1650b
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 42 deletions.
2 changes: 1 addition & 1 deletion mdc_100_series/lib/app.dart
Expand Up @@ -35,7 +35,7 @@ class ShrineApp extends StatelessWidget {
);
}

Route<dynamic> _getRoute(RouteSettings settings) {
Route<dynamic>? _getRoute(RouteSettings settings) {
if (settings.name != '/login') {
return null;
}
Expand Down
18 changes: 6 additions & 12 deletions mdc_100_series/lib/model/product.dart
Expand Up @@ -12,22 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import 'package:flutter/foundation.dart';

enum Category { all, accessories, clothing, home, }

class Product {
const Product({
@required this.category,
@required this.id,
@required this.isFeatured,
@required this.name,
@required this.price,
}) : assert(category != null),
assert(id != null),
assert(isFeatured != null),
assert(name != null),
assert(price != null);
required this.category,
required this.id,
required this.isFeatured,
required this.name,
required this.price,
});

final Category category;
final int id;
Expand Down
4 changes: 2 additions & 2 deletions mdc_100_series/lib/supplemental/asymmetric_view.dart
Expand Up @@ -20,10 +20,10 @@ import 'product_columns.dart';
class AsymmetricView extends StatelessWidget {
final List<Product> products;

AsymmetricView({Key key, this.products});
AsymmetricView({Key? key, required this.products});

List<Container> _buildColumns(BuildContext context) {
if (products == null || products.isEmpty) {
if (products.isEmpty) {
return <Container>[];
}

Expand Down
33 changes: 16 additions & 17 deletions mdc_100_series/lib/supplemental/cut_corners_border.dart
Expand Up @@ -19,21 +19,21 @@ import 'package:flutter/widgets.dart';

class CutCornersBorder extends OutlineInputBorder {
const CutCornersBorder({
BorderSide borderSide: const BorderSide(),
BorderRadius borderRadius: const BorderRadius.all(Radius.circular(2.0)),
this.cut: 7.0,
double gapPadding: 2.0,
BorderSide borderSide = const BorderSide(),
BorderRadius borderRadius = const BorderRadius.all(Radius.circular(2.0)),
this.cut = 7.0,
double gapPadding = 2.0,
}) : super(
borderSide: borderSide,
borderRadius: borderRadius,
gapPadding: gapPadding);

@override
CutCornersBorder copyWith({
BorderSide borderSide,
BorderRadius borderRadius,
double gapPadding,
double cut,
BorderSide? borderSide,
BorderRadius? borderRadius,
double? gapPadding,
double? cut,
}) {
return CutCornersBorder(
borderRadius: borderRadius ?? this.borderRadius,
Expand All @@ -46,11 +46,11 @@ class CutCornersBorder extends OutlineInputBorder {
final double cut;

@override
ShapeBorder lerpFrom(ShapeBorder a, double t) {
ShapeBorder? lerpFrom(ShapeBorder? a, double t) {
if (a is CutCornersBorder) {
final CutCornersBorder outline = a;
return CutCornersBorder(
borderRadius: BorderRadius.lerp(outline.borderRadius, borderRadius, t),
borderRadius: BorderRadius.lerp(outline.borderRadius, borderRadius, t)!,
borderSide: BorderSide.lerp(outline.borderSide, borderSide, t),
cut: cut,
gapPadding: outline.gapPadding,
Expand All @@ -60,11 +60,11 @@ class CutCornersBorder extends OutlineInputBorder {
}

@override
ShapeBorder lerpTo(ShapeBorder b, double t) {
ShapeBorder? lerpTo(ShapeBorder? b, double t) {
if (b is CutCornersBorder) {
final CutCornersBorder outline = b;
return CutCornersBorder(
borderRadius: BorderRadius.lerp(borderRadius, outline.borderRadius, t),
borderRadius: BorderRadius.lerp(borderRadius, outline.borderRadius, t)!,
borderSide: BorderSide.lerp(borderSide, outline.borderSide, t),
cut: cut,
gapPadding: outline.gapPadding,
Expand Down Expand Up @@ -103,12 +103,11 @@ class CutCornersBorder extends OutlineInputBorder {
void paint(
Canvas canvas,
Rect rect, {
double gapStart,
double? gapStart,
double gapExtent: 0.0,
double gapPercentage: 0.0,
TextDirection textDirection,
TextDirection? textDirection,
}) {
assert(gapExtent != null);
assert(gapPercentage >= 0.0 && gapPercentage <= 1.0);

final Paint paint = borderSide.toPaint();
Expand All @@ -117,8 +116,8 @@ class CutCornersBorder extends OutlineInputBorder {
canvas.drawPath(_notchedCornerPath(outer.middleRect), paint);
} else {
final double extent =
lerpDouble(0.0, gapExtent + gapPadding * 2.0, gapPercentage);
switch (textDirection) {
lerpDouble(0.0, gapExtent + gapPadding * 2.0, gapPercentage)!;
switch (textDirection!) {
case TextDirection.rtl:
{
final Path path = _notchedCornerPath(
Expand Down
8 changes: 4 additions & 4 deletions mdc_100_series/lib/supplemental/product_card.dart
Expand Up @@ -18,8 +18,8 @@ import 'package:intl/intl.dart';
import '../model/product.dart';

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

final double imageAspectRatio;
final Product product;
Expand Down Expand Up @@ -54,15 +54,15 @@ class ProductCard extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
product == null ? '' : product.name,
product.name,
style: theme.textTheme.headline6,
softWrap: false,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
SizedBox(height: 4.0),
Text(
product == null ? '' : formatter.format(product.price),
formatter.format(product.price),
style: theme.textTheme.subtitle2,
),
],
Expand Down
11 changes: 6 additions & 5 deletions mdc_100_series/lib/supplemental/product_columns.dart
Expand Up @@ -19,11 +19,12 @@ import 'product_card.dart';

class TwoProductCardColumn extends StatelessWidget {
TwoProductCardColumn({
this.bottom,
required this.bottom,
this.top,
}) : assert(bottom != null);
});

final Product bottom, top;
final Product bottom;
final Product? top;

@override
Widget build(BuildContext context) {
Expand All @@ -46,7 +47,7 @@ class TwoProductCardColumn extends StatelessWidget {
child: top != null
? ProductCard(
imageAspectRatio: imageAspectRatio,
product: top,
product: top!,
)
: SizedBox(
height: heightOfCards,
Expand All @@ -67,7 +68,7 @@ class TwoProductCardColumn extends StatelessWidget {
}

class OneProductCardColumn extends StatelessWidget {
OneProductCardColumn({this.product});
OneProductCardColumn({required this.product});

final Product product;

Expand Down
5 changes: 4 additions & 1 deletion mdc_100_series/pubspec.yaml
@@ -1,10 +1,13 @@
name: Shrine
description: Learn the basics of using Material Components by building a simple app with core components.

environment:
sdk: '>=2.12.0-0 <3.0.0'

dependencies:
flutter:
sdk: flutter
intl: ^0.15.6
intl: ^0.17.0-nullsafety.2

cupertino_icons: ^0.1.0
shrine_images: 1.1.1
Expand Down

0 comments on commit 2f1650b

Please sign in to comment.