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

pull/60/head
Abhijeeth Padarthi 6 years ago committed by Andrew Brogdon
parent be35972637
commit 8fe2999ee8

@ -4,3 +4,4 @@
# Name/Organization <email address> # Name/Organization <email address>
Google Inc. Google Inc.
Abhijeeth Padarthi <rkinabhi@gmail.com>

@ -12,7 +12,7 @@ import 'package:jsonexample/built_value/built_simple_object.dart';
part 'built_value_serializers.g.dart'; part 'built_value_serializers.g.dart';
@SerializersFor(const [ @SerializersFor([
BuiltSimpleObject, BuiltSimpleObject,
BuiltComplexObject, BuiltComplexObject,
]) ])

@ -46,7 +46,7 @@ class MyHomePage extends StatelessWidget {
], ],
), ),
), ),
body: new SafeArea( body: SafeArea(
bottom: false, bottom: false,
child: TabBarView( child: TabBarView(
children: [ children: [

@ -129,7 +129,7 @@ class ComplexObjectView extends StatelessWidget {
if (simpleObjects == null) { if (simpleObjects == null) {
return [ return [
const Padding( const Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0), padding: EdgeInsets.symmetric(vertical: 8.0),
child: Text('NULL'), child: Text('NULL'),
), ),
]; ];
@ -138,7 +138,7 @@ class ComplexObjectView extends StatelessWidget {
if (simpleObjects.length == 0) { if (simpleObjects.length == 0) {
return [ return [
const Padding( const Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0), padding: EdgeInsets.symmetric(vertical: 4.0),
child: Text('[]'), child: Text('[]'),
), ),
]; ];

@ -233,8 +233,8 @@ class PlaceMapState extends State<PlaceMap> {
Scaffold.of(context).showSnackBar( Scaffold.of(context).showSnackBar(
SnackBar( SnackBar(
duration: Duration(seconds: 3), duration: Duration(seconds: 3),
content: const Text('New place added.', content:
style: const TextStyle(fontSize: 16.0)), const Text('New place added.', style: TextStyle(fontSize: 16.0)),
action: SnackBarAction( action: SnackBarAction(
label: 'Edit', label: 'Edit',
onPressed: () async { onPressed: () async {

@ -7,15 +7,15 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
void main() { void main() {
runApp(new PlatformView()); runApp(PlatformView());
} }
class PlatformView extends StatelessWidget { class PlatformView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new MaterialApp( return MaterialApp(
title: 'Platform View', title: 'Platform View',
theme: new ThemeData( theme: ThemeData(
primarySwatch: Colors.grey, primarySwatch: Colors.grey,
), ),
home: const MyHomePage(title: 'Platform View'), home: const MyHomePage(title: 'Platform View'),
@ -29,12 +29,12 @@ class MyHomePage extends StatefulWidget {
final String title; final String title;
@override @override
_MyHomePageState createState() => new _MyHomePageState(); _MyHomePageState createState() => _MyHomePageState();
} }
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
static const MethodChannel _methodChannel = static const MethodChannel _methodChannel =
const MethodChannel('samples.flutter.io/platform_view_swift'); MethodChannel('samples.flutter.io/platform_view_swift');
int _counter = 0; int _counter = 0;
@ -53,25 +53,25 @@ class _MyHomePageState extends State<MyHomePage> {
} }
@override @override
Widget build(BuildContext context) => new Scaffold( Widget build(BuildContext context) => Scaffold(
appBar: new AppBar( appBar: AppBar(
title: new Text(widget.title), title: Text(widget.title),
), ),
body: new Column( body: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
new Expanded( Expanded(
child: new Center( child: Center(
child: new Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
new Text( Text(
'Button tapped $_counter time${_counter == 1 ? '' : 's'}.', 'Button tapped $_counter time${_counter == 1 ? '' : 's'}.',
style: const TextStyle(fontSize: 17.0), style: const TextStyle(fontSize: 17.0),
), ),
new Padding( Padding(
padding: const EdgeInsets.all(18.0), padding: const EdgeInsets.all(18.0),
child: new RaisedButton( child: RaisedButton(
child: const Text('Continue in iOS view'), child: const Text('Continue in iOS view'),
onPressed: _launchPlatformCount), onPressed: _launchPlatformCount),
), ),
@ -79,22 +79,21 @@ class _MyHomePageState extends State<MyHomePage> {
), ),
), ),
), ),
new Container( Container(
padding: const EdgeInsets.only(bottom: 15.0, left: 5.0), padding: const EdgeInsets.only(bottom: 15.0, left: 5.0),
child: new Row( child: Row(
children: <Widget>[ children: <Widget>[
new Image.asset('assets/flutter-mark-square-64.png', Image.asset('assets/flutter-mark-square-64.png', scale: 1.5),
scale: 1.5),
const Text( const Text(
'Flutter', 'Flutter',
style: const TextStyle(fontSize: 30.0), style: TextStyle(fontSize: 30.0),
), ),
], ],
), ),
), ),
], ],
), ),
floatingActionButton: new FloatingActionButton( floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter, onPressed: _incrementCounter,
tooltip: 'Increment', tooltip: 'Increment',
child: const Icon(Icons.add), child: const Icon(Icons.add),

@ -14,15 +14,15 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
const kShrinePink50 = const Color(0xFFFEEAE6); const kShrinePink50 = Color(0xFFFEEAE6);
const kShrinePink100 = const Color(0xFFFEDBD0); const kShrinePink100 = Color(0xFFFEDBD0);
const kShrinePink300 = const Color(0xFFFBB8AC); const kShrinePink300 = Color(0xFFFBB8AC);
const kShrinePink400 = const Color(0xFFEAA4A4); const kShrinePink400 = Color(0xFFEAA4A4);
const kShrineBrown900 = const Color(0xFF442B2D); const kShrineBrown900 = Color(0xFF442B2D);
const kShrineBrown600 = const Color(0xFF7D4F52); 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; const kShrineBackgroundWhite = Colors.white;

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

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

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

@ -19,10 +19,10 @@ import 'package:flutter/widgets.dart';
class CutCornersBorder extends OutlineInputBorder { class CutCornersBorder extends OutlineInputBorder {
const CutCornersBorder({ const CutCornersBorder({
BorderSide borderSide: const BorderSide(), BorderSide borderSide = const BorderSide(),
BorderRadius borderRadius: const BorderRadius.all(Radius.circular(2.0)), BorderRadius borderRadius = const BorderRadius.all(Radius.circular(2.0)),
this.cut: 7.0, this.cut = 7.0,
double gapPadding: 2.0, double gapPadding = 2.0,
}) : super( }) : super(
borderSide: borderSide, borderSide: borderSide,
borderRadius: borderRadius, borderRadius: borderRadius,
@ -104,8 +104,8 @@ class CutCornersBorder extends OutlineInputBorder {
Canvas canvas, Canvas canvas,
Rect rect, { Rect rect, {
double gapStart, double gapStart,
double gapExtent: 0.0, double gapExtent = 0.0,
double gapPercentage: 0.0, double gapPercentage = 0.0,
TextDirection textDirection, TextDirection textDirection,
}) { }) {
assert(gapExtent != null); assert(gapExtent != null);

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

@ -14,7 +14,7 @@ import 'package:veggieseasons/widgets/veggie_card.dart';
class ListScreen extends StatelessWidget { class ListScreen extends StatelessWidget {
List<Widget> _generateVeggieRows(List<Veggie> veggies, Preferences prefs) { List<Widget> _generateVeggieRows(List<Veggie> veggies, Preferences prefs) {
final cards = new List<Widget>(); final cards = List<Widget>();
for (Veggie veggie in veggies) { for (Veggie veggie in veggies) {
cards.add(Padding( cards.add(Padding(

@ -118,7 +118,7 @@ abstract class Styles {
Season.autumn: Color(0xff724913), Season.autumn: Color(0xff724913),
}; };
static const seasonBorder = const Border( static const seasonBorder = Border(
top: BorderSide(color: Color(0xff606060)), top: BorderSide(color: Color(0xff606060)),
left: BorderSide(color: Color(0xff606060)), left: BorderSide(color: Color(0xff606060)),
bottom: BorderSide(color: Color(0xff606060)), bottom: BorderSide(color: Color(0xff606060)),

@ -86,7 +86,7 @@ class CloseButton extends StatefulWidget {
@override @override
CloseButtonState createState() { CloseButtonState createState() {
return new CloseButtonState(); return CloseButtonState();
} }
} }

@ -13,7 +13,7 @@ import 'package:veggieseasons/styles.dart';
// //
// See https://github.com/flutter/flutter/projects/29 for more info. // See https://github.com/flutter/flutter/projects/29 for more info.
typedef FutureOr<void> SettingsItemCallback(); typedef SettingsItemCallback = FutureOr<void> Function();
class SettingsNavigationIndicator extends StatelessWidget { class SettingsNavigationIndicator extends StatelessWidget {
const SettingsNavigationIndicator({Key key}) : super(key: key); const SettingsNavigationIndicator({Key key}) : super(key: key);
@ -77,7 +77,7 @@ class SettingsItem extends StatefulWidget {
final SettingsItemCallback onPress; final SettingsItemCallback onPress;
@override @override
State<StatefulWidget> createState() => new SettingsItemState(); State<StatefulWidget> createState() => SettingsItemState();
} }
class SettingsItemState extends State<SettingsItem> { class SettingsItemState extends State<SettingsItem> {

Loading…
Cancel
Save