Skip to content

Commit

Permalink
Migrate 104-complete to NNBD. (#211)
Browse files Browse the repository at this point in the history
Migrate 104-complete to NNBD. (#211)
  • Loading branch information
pennzht committed Oct 16, 2020
1 parent 6d38e99 commit 1700d3c
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 85 deletions.
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;

@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

0 comments on commit 1700d3c

Please sign in to comment.