Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate 104-complete to NNBD. #211

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions mdc_100_series/analysis_options.yaml
@@ -0,0 +1,3 @@
analyzer:
enable-experiment:
- non-nullable
10 changes: 5 additions & 5 deletions mdc_100_series/lib/app.dart
Expand Up @@ -58,7 +58,7 @@ class _ShrineAppState extends State<ShrineApp> {
}
}

Route<dynamic> _getRoute(RouteSettings settings) {
Route<dynamic>? _getRoute(RouteSettings settings) {
if (settings.name != '/login') {
return null;
}
Expand Down Expand Up @@ -107,17 +107,17 @@ ThemeData _buildShrineTheme() {

TextTheme _buildShrineTextTheme(TextTheme base) {
return base.copyWith(
headline5: base.headline5.copyWith(
headline5: base.headline5!.copyWith(
fontWeight: FontWeight.w500,
),
headline6: base.headline6.copyWith(
headline6: base.headline6!.copyWith(
fontSize: 18.0
),
caption: base.caption.copyWith(
caption: base.caption!.copyWith(
fontWeight: FontWeight.w400,
fontSize: 14.0,
),
bodyText1: base.bodyText1.copyWith(
bodyText1: base.bodyText1!.copyWith(
fontWeight: FontWeight.w500,
fontSize: 16.0,
),
Expand Down
46 changes: 21 additions & 25 deletions mdc_100_series/lib/backdrop.dart
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

import 'package:flutter/material.dart';
import 'package:meta/meta.dart';

import 'model/product.dart';
import 'login.dart';
Expand All @@ -22,12 +21,12 @@ const double _kFlingVelocity = 2.0;

class _FrontLayer extends StatelessWidget {
const _FrontLayer({
Key key,
Key? key,
this.onTap,
this.child,
required this.child,
}) : super(key: key);

final VoidCallback onTap;
final VoidCallback? onTap;
final Widget child;

@override
Expand Down Expand Up @@ -58,26 +57,27 @@ class _FrontLayer extends StatelessWidget {
}

class _BackdropTitle extends AnimatedWidget {
final Function onPress;
final void Function() onPress;
final Widget frontTitle;
final Widget backTitle;

const _BackdropTitle({
Key key,
Listenable listenable,
this.onPress,
@required this.frontTitle,
@required this.backTitle,
}) : assert(frontTitle != null),
assert(backTitle != null),
Key? key,
required Animation<double> listenable,
required this.onPress,
required this.frontTitle,
required this.backTitle,
}) : _listenable = listenable,
super(key: key, listenable: listenable);

final Animation<double> _listenable;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the type changed and no longer using the super's listenable anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super's listenable has type Listenable.

In this widget, listenable is used as an Animation<double> for its value, so listenable must be an Animation<double>. Animation<double> is a subclass of Listenable.

If we use super's listenable, then we must do a casting similar to

    final Animation<double> animation = this.listenable;	

on line 77 (before the change).

This also permits the user to pass in any Listenable, including ones that don't have a value, which breaks the widget. By restricting listenable to Animation<double>, we can ensure that the animation passed in by the user is valid, and all errors can be caught at compile-time.


@override
Widget build(BuildContext context) {
final Animation<double> animation = this.listenable;
final Animation<double> animation = _listenable;

return DefaultTextStyle(
style: Theme.of(context).primaryTextTheme.headline6,
style: Theme.of(context)!.primaryTextTheme.headline6!,
softWrap: false,
overflow: TextOverflow.ellipsis,
child: Row(children: <Widget>[
Expand Down Expand Up @@ -158,16 +158,12 @@ class Backdrop extends StatefulWidget {
final Widget backTitle;

const Backdrop({
@required this.currentCategory,
@required this.frontLayer,
@required this.backLayer,
@required this.frontTitle,
@required this.backTitle,
}) : assert(currentCategory != null),
assert(frontLayer != null),
assert(backLayer != null),
assert(frontTitle != null),
assert(backTitle != null);
required this.currentCategory,
required this.frontLayer,
required this.backLayer,
required this.frontTitle,
required this.backTitle,
});

@override
_BackdropState createState() => _BackdropState();
Expand All @@ -176,7 +172,7 @@ class Backdrop extends StatefulWidget {
class _BackdropState extends State<Backdrop>
with SingleTickerProviderStateMixin {
final GlobalKey _backdropKey = GlobalKey(debugLabel: 'Backdrop');
AnimationController _controller;
late AnimationController _controller;

@override
void initState() {
Expand Down
14 changes: 6 additions & 8 deletions mdc_100_series/lib/category_menu_page.dart
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

import 'package:flutter/material.dart';
import 'package:meta/meta.dart';

import 'colors.dart';
import 'model/product.dart';
Expand All @@ -24,16 +23,15 @@ class CategoryMenuPage extends StatelessWidget {
final List<Category> _categories = Category.values;

const CategoryMenuPage({
Key key,
@required this.currentCategory,
@required this.onCategoryTap,
}) : assert(currentCategory != null),
assert(onCategoryTap != null);
Key? key,
required this.currentCategory,
required this.onCategoryTap,
});

Widget _buildCategory(Category category, BuildContext context) {
final categoryString =
category.toString().replaceAll('Category.', '').toUpperCase();
final ThemeData theme = Theme.of(context);
final ThemeData theme = Theme.of(context)!;
return GestureDetector(
onTap: () => onCategoryTap(category),
child: category == currentCategory
Expand All @@ -57,7 +55,7 @@ class CategoryMenuPage extends StatelessWidget {
padding: EdgeInsets.symmetric(vertical: 16.0),
child: Text(
categoryString,
style: theme.textTheme.bodyText1.copyWith(
style: theme.textTheme.bodyText1!.copyWith(
color: kShrineBrown900.withAlpha(153)
),
textAlign: TextAlign.center,
Expand Down
6 changes: 3 additions & 3 deletions mdc_100_series/lib/login.dart
Expand Up @@ -39,7 +39,7 @@ class _LoginPageState extends State<LoginPage> {
SizedBox(height: 16.0),
Text(
'SHRINE',
style: Theme.of(context).textTheme.headline5,
style: Theme.of(context)!.textTheme.headline5,
),
],
),
Expand Down Expand Up @@ -96,7 +96,7 @@ class _LoginPageState extends State<LoginPage> {
}

class AccentColorOverride extends StatelessWidget {
const AccentColorOverride({Key key, this.color, this.child})
const AccentColorOverride({Key? key, required this.color, required this.child})
: super(key: key);

final Color color;
Expand All @@ -106,7 +106,7 @@ class AccentColorOverride extends StatelessWidget {
Widget build(BuildContext context) {
return Theme(
child: child,
data: Theme.of(context).copyWith(
data: Theme.of(context)!.copyWith(
accentColor: color,
brightness: Brightness.dark,
),
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
6 changes: 3 additions & 3 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 All @@ -36,7 +36,7 @@ class AsymmetricView extends StatelessWidget {
/// helpers for creating the index of the product list that will correspond
/// to the index of the list of columns.
return List.generate(_listItemCount(products.length), (int index) {
double width = .59 * MediaQuery.of(context).size.width;
double width = .59 * MediaQuery.of(context)!.size.width;
Widget column;
if (index % 2 == 0) {
/// Even cases
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
12 changes: 6 additions & 6 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 All @@ -30,7 +30,7 @@ class ProductCard extends StatelessWidget {
Widget build(BuildContext context) {
final NumberFormat formatter = NumberFormat.simpleCurrency(
decimalDigits: 0, locale: Localizations.localeOf(context).toString());
final ThemeData theme = Theme.of(context);
final ThemeData theme = Theme.of(context)!;

final imageWidget = Image.asset(
product.assetName,
Expand All @@ -47,22 +47,22 @@ class ProductCard extends StatelessWidget {
child: imageWidget,
),
SizedBox(
height: kTextBoxHeight * MediaQuery.of(context).textScaleFactor,
height: kTextBoxHeight * MediaQuery.of(context)!.textScaleFactor,
width: 121.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
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