1
0
mirror of https://github.com/flutter/samples.git synced 2026-04-06 19:52:04 +00:00

Removed redundant "const" and "new" assignments & Formatted code. (#58)

This commit is contained in:
Abhijeeth Padarthi
2019-03-19 21:57:32 +05:30
committed by Andrew Brogdon
parent be35972637
commit 8fe2999ee8
16 changed files with 87 additions and 75 deletions

View File

@@ -14,15 +14,15 @@
import 'package:flutter/material.dart';
const kShrinePink50 = const Color(0xFFFEEAE6);
const kShrinePink100 = const Color(0xFFFEDBD0);
const kShrinePink300 = const Color(0xFFFBB8AC);
const kShrinePink400 = const Color(0xFFEAA4A4);
const kShrinePink50 = Color(0xFFFEEAE6);
const kShrinePink100 = Color(0xFFFEDBD0);
const kShrinePink300 = Color(0xFFFBB8AC);
const kShrinePink400 = Color(0xFFEAA4A4);
const kShrineBrown900 = const Color(0xFF442B2D);
const kShrineBrown600 = const Color(0xFF7D4F52);
const kShrineBrown900 = Color(0xFF442B2D);
const kShrineBrown600 = Color(0xFF7D4F52);
const kShrineErrorRed = const Color(0xFFC5032B);
const kShrineErrorRed = Color(0xFFC5032B);
const kShrineSurfaceWhite = const Color(0xFFFFFBFA);
const kShrineSurfaceWhite = Color(0xFFFFFBFA);
const kShrineBackgroundWhite = Colors.white;

View File

@@ -25,8 +25,8 @@ import 'model/product.dart';
import 'shopping_cart.dart';
// These curves define the emphasized easing curve.
const Cubic _kAccelerateCurve = const Cubic(0.548, 0.0, 0.757, 0.464);
const Cubic _kDecelerateCurve = const Cubic(0.23, 0.94, 0.41, 1.0);
const Cubic _kAccelerateCurve = Cubic(0.548, 0.0, 0.757, 0.464);
const Cubic _kDecelerateCurve = Cubic(0.23, 0.94, 0.41, 1.0);
// The time at which the accelerate and decelerate curves switch off
const double _kPeakVelocityTime = 0.248210;
// Percent (as a decimal) of animation that should be completed at _peakVelocityTime
@@ -48,7 +48,7 @@ class ExpandingBottomSheet extends StatefulWidget {
_ExpandingBottomSheetState createState() => _ExpandingBottomSheetState();
static _ExpandingBottomSheetState of(BuildContext context,
{bool isNullOk: false}) {
{bool isNullOk = false}) {
assert(isNullOk != null);
assert(context != null);
final _ExpandingBottomSheetState result = context
@@ -115,8 +115,10 @@ double _getPeakPoint({double begin, double end}) {
return begin + (end - begin) * _kPeakVelocityProgress;
}
class _ExpandingBottomSheetState extends State<ExpandingBottomSheet> with TickerProviderStateMixin {
final GlobalKey _expandingBottomSheetKey = GlobalKey(debugLabel: 'Expanding bottom sheet');
class _ExpandingBottomSheetState extends State<ExpandingBottomSheet>
with TickerProviderStateMixin {
final GlobalKey _expandingBottomSheetKey =
GlobalKey(debugLabel: 'Expanding bottom sheet');
// The width of the Material, calculated by _widthFor() & based on the number
// of products in the cart. 64.0 is the width when there are 0 products
@@ -163,7 +165,8 @@ class _ExpandingBottomSheetState extends State<ExpandingBottomSheet> with Ticker
peak: _getPeakPoint(begin: _width, end: screenWidth),
end: screenWidth,
isForward: false,
parent: CurvedAnimation(parent: _controller.view, curve: Interval(0.0, 0.87)),
parent: CurvedAnimation(
parent: _controller.view, curve: Interval(0.0, 0.87)),
);
}
}
@@ -174,7 +177,8 @@ class _ExpandingBottomSheetState extends State<ExpandingBottomSheet> with Ticker
return _getEmphasizedEasingAnimation(
begin: _kCartHeight,
peak: _kCartHeight + (screenHeight - _kCartHeight) * _kPeakVelocityProgress,
peak: _kCartHeight +
(screenHeight - _kCartHeight) * _kPeakVelocityProgress,
end: screenHeight,
isForward: true,
parent: _controller.view,
@@ -189,7 +193,8 @@ class _ExpandingBottomSheetState extends State<ExpandingBottomSheet> with Ticker
parent: _controller.view,
curve: Interval(0.434, 1.0, curve: Curves.linear), // not used
// only the reverseCurve will be used
reverseCurve: Interval(0.434, 1.0, curve: Curves.fastOutSlowIn.flipped),
reverseCurve:
Interval(0.434, 1.0, curve: Curves.fastOutSlowIn.flipped),
),
);
}
@@ -259,7 +264,8 @@ class _ExpandingBottomSheetState extends State<ExpandingBottomSheet> with Ticker
// Returns true if the cart is open or opening and false otherwise.
bool get _isOpen {
final AnimationStatus status = _controller.status;
return status == AnimationStatus.completed || status == AnimationStatus.forward;
return status == AnimationStatus.completed ||
status == AnimationStatus.forward;
}
// Opens the ExpandingBottomSheet if it's closed, otherwise does nothing.
@@ -438,7 +444,8 @@ class _ProductThumbnailRowState extends State<ProductThumbnailRow> {
super.initState();
_list = _ListModel(
listKey: _listKey,
initialItems: ScopedModel.of<AppStateModel>(context).productsInCart.keys.toList(),
initialItems:
ScopedModel.of<AppStateModel>(context).productsInCart.keys.toList(),
removedItemBuilder: _buildRemovedThumbnail,
);
_internalList = List<int>.from(_list.list);
@@ -451,12 +458,15 @@ class _ProductThumbnailRowState extends State<ProductThumbnailRow> {
return product;
}
Widget _buildRemovedThumbnail(int item, BuildContext context, Animation<double> animation) {
Widget _buildRemovedThumbnail(
int item, BuildContext context, Animation<double> animation) {
return ProductThumbnail(animation, animation, _productWithId(item));
}
Widget _buildThumbnail(BuildContext context, int index, Animation<double> animation) {
Animation<double> thumbnailSize = Tween<double>(begin: 0.8, end: 1.0).animate(
Widget _buildThumbnail(
BuildContext context, int index, Animation<double> animation) {
Animation<double> thumbnailSize =
Tween<double>(begin: 0.8, end: 1.0).animate(
CurvedAnimation(
curve: Interval(0.33, 1.0, curve: Curves.easeIn),
parent: animation,
@@ -468,7 +478,8 @@ class _ProductThumbnailRowState extends State<ProductThumbnailRow> {
parent: animation,
);
return ProductThumbnail(thumbnailSize, opacity, _productWithId(_list[index]));
return ProductThumbnail(
thumbnailSize, opacity, _productWithId(_list[index]));
}
// If the lists are the same length, assume nothing has changed.
@@ -476,7 +487,8 @@ class _ProductThumbnailRowState extends State<ProductThumbnailRow> {
// If the internalList is longer, then an item has been added.
void _updateLists() {
// Update _internalList based on the model
_internalList = ScopedModel.of<AppStateModel>(context).productsInCart.keys.toList();
_internalList =
ScopedModel.of<AppStateModel>(context).productsInCart.keys.toList();
Set<int> internalSet = Set<int>.from(_internalList);
Set<int> listSet = Set<int>.from(_list.list);
@@ -550,9 +562,11 @@ class ExtraProductsNumber extends StatelessWidget {
if (model.productsInCart.length > 3) {
int numOverflowProducts = _calculateOverflow(model);
// Maximum of 99 so padding doesn't get messy.
int displayedOverflowProducts = numOverflowProducts <= 99 ? numOverflowProducts : 99;
int displayedOverflowProducts =
numOverflowProducts <= 99 ? numOverflowProducts : 99;
return Container(
child: Text('+$displayedOverflowProducts',
child: Text(
'+$displayedOverflowProducts',
style: Theme.of(context).primaryTextTheme.button,
),
);
@@ -606,8 +620,8 @@ class ProductThumbnail extends StatelessWidget {
class _ListModel {
_ListModel(
{@required this.listKey,
@required this.removedItemBuilder,
Iterable<int> initialItems})
@required this.removedItemBuilder,
Iterable<int> initialItems})
: assert(listKey != null),
assert(removedItemBuilder != null),
_items = List<int>.from(initialItems ?? <int>[]);
@@ -637,7 +651,8 @@ class _ListModel {
void _removeAt(int index) {
final int removedItem = _items.removeAt(index);
if (removedItem != null) {
_animatedList.removeItem(index, (BuildContext context, Animation<double> animation) {
_animatedList.removeItem(index,
(BuildContext context, Animation<double> animation) {
return removedItemBuilder(removedItem, context, animation);
});
}

View File

@@ -24,7 +24,7 @@ import 'supplemental/asymmetric_view.dart';
class ProductPage extends StatelessWidget {
final Category category;
const ProductPage({this.category: Category.all});
const ProductPage({this.category = Category.all});
@override
Widget build(BuildContext context) {
@@ -41,11 +41,8 @@ class HomePage extends StatelessWidget {
final ExpandingBottomSheet expandingBottomSheet;
final Backdrop backdrop;
const HomePage({
Key key,
this.expandingBottomSheet,
this.backdrop
}) : super(key: key);
const HomePage({Key key, this.expandingBottomSheet, this.backdrop})
: super(key: key);
@override
Widget build(BuildContext context) {

View File

@@ -63,8 +63,8 @@ class _ShoppingCartPageState extends State<ShoppingCartPage> {
width: _leftColumnWidth,
child: IconButton(
icon: const Icon(Icons.keyboard_arrow_down),
onPressed: () => ExpandingBottomSheet.of(context).close()
),
onPressed: () =>
ExpandingBottomSheet.of(context).close()),
),
Text(
'CART',

View File

@@ -19,10 +19,10 @@ 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,
@@ -104,8 +104,8 @@ class CutCornersBorder extends OutlineInputBorder {
Canvas canvas,
Rect rect, {
double gapStart,
double gapExtent: 0.0,
double gapPercentage: 0.0,
double gapExtent = 0.0,
double gapPercentage = 0.0,
TextDirection textDirection,
}) {
assert(gapExtent != null);

View File

@@ -20,7 +20,7 @@ import '../model/app_state_model.dart';
import '../model/product.dart';
class ProductCard extends StatelessWidget {
ProductCard({this.imageAspectRatio: 33 / 49, this.product})
ProductCard({this.imageAspectRatio = 33 / 49, this.product})
: assert(imageAspectRatio == null || imageAspectRatio > 0);
final double imageAspectRatio;