Declare locals as final where not reassigned (dev) (#8574)

This commit is contained in:
Chris Bracken
2017-03-03 18:06:08 -08:00
committed by GitHub
parent 7a52fb6772
commit 6c97dd2c6c
35 changed files with 215 additions and 215 deletions

View File

@@ -42,7 +42,7 @@ class CardCollectionState extends State<CardCollection> {
bool _varyFontSizes = false;
void _initVariableSizedCardModels() {
List<double> cardHeights = <double>[
final List<double> cardHeights = <double>[
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
@@ -119,7 +119,7 @@ class CardCollectionState extends State<CardCollection> {
}
String _dismissDirectionText(DismissDirection direction) {
String s = direction.toString();
final String s = direction.toString();
return "dismiss ${s.substring(s.indexOf('.') + 1)}";
}
@@ -247,8 +247,8 @@ class CardCollectionState extends State<CardCollection> {
}
Widget _buildCard(BuildContext context, int index) {
CardModel cardModel = _cardModels[index];
Widget card = new Dismissable(
final CardModel cardModel = _cardModels[index];
final Widget card = new Dismissable(
key: new ObjectKey(cardModel),
direction: _dismissDirection,
onDismissed: (DismissDirection direction) { dismissCard(cardModel); },
@@ -318,7 +318,7 @@ class CardCollectionState extends State<CardCollection> {
// size of the background,card Stack will be based only on the card. The
// Viewport ensures that when the card's resize animation occurs, the
// background (text and icons) will just be clipped, not resized.
Widget background = new Positioned.fill(
final Widget background = new Positioned.fill(
child: new Container(
margin: const EdgeInsets.all(4.0),
child: new SingleChildScrollView(
@@ -376,7 +376,7 @@ class CardCollectionState extends State<CardCollection> {
);
}
Widget body = new Container(
final Widget body = new Container(
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 8.0),
color: _primaryColor[50],
child: cardCollection,

View File

@@ -97,7 +97,7 @@ class ExampleDragSource extends StatelessWidget {
if (heavy)
size *= kHeavyMultiplier;
Widget contents = new DefaultTextStyle(
final Widget contents = new DefaultTextStyle(
style: Theme.of(context).textTheme.body1,
textAlign: TextAlign.center,
child: new Dot(
@@ -185,7 +185,7 @@ class MovableBall extends StatelessWidget {
@override
Widget build(BuildContext context) {
Widget ball = new DefaultTextStyle(
final Widget ball = new DefaultTextStyle(
style: Theme.of(context).primaryTextTheme.body1,
textAlign: TextAlign.center,
child: new Dot(
@@ -196,7 +196,7 @@ class MovableBall extends StatelessWidget {
child: new Center(child: new Text('BALL'))
)
);
Widget dashedBall = new Container(
final Widget dashedBall = new Container(
width: kBallSize,
height: kBallSize,
child: new CustomPaint(

View File

@@ -31,8 +31,8 @@ class _MarkerPainter extends CustomPainter {
@override
void paint(Canvas canvas, _) {
Paint paint = new Paint()..color = const Color(0x8000FF00);
double r = size / 2.0;
final Paint paint = new Paint()..color = const Color(0x8000FF00);
final double r = size / 2.0;
canvas.drawCircle(new Point(r, r), r, paint);
paint
@@ -107,7 +107,7 @@ class CardBuilder extends SliverChildDelegate {
Widget build(BuildContext context, int index) {
if (index >= cardModels.length)
return null;
CardModel cardModel = cardModels[index];
final CardModel cardModel = cardModels[index];
return new GestureDetector(
key: cardModel.key,
onTapUp: (TapUpDetails details) { onTapUp(cardModel.targetKey, details.globalPosition); },
@@ -140,13 +140,13 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
@override
void initState() {
super.initState();
List<double> cardHeights = <double>[
final List<double> cardHeights = <double>[
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
];
cardModels = new List<CardModel>.generate(cardHeights.length, (int i) {
Color color = Color.lerp(Colors.red[300], Colors.blue[900], i / cardHeights.length);
final Color color = Color.lerp(Colors.red[300], Colors.blue[900], i / cardHeights.length);
return new CardModel(i, cardHeights[i], color);
});
}
@@ -154,10 +154,10 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
bool handleScrollNotification(ScrollNotification notification) {
if (notification is ScrollUpdateNotification && notification.depth == 1) {
setState(() {
double dy = markersScrollOffset - notification.metrics.extentBefore;
final double dy = markersScrollOffset - notification.metrics.extentBefore;
markersScrollOffset = notification.metrics.extentBefore;
for (MarkerType type in markers.keys) {
Point oldPosition = markers[type];
final Point oldPosition = markers[type];
markers[type] = new Point(oldPosition.x, oldPosition.y + dy);
}
});
@@ -179,7 +179,7 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
@override
Widget build(BuildContext context) {
List<Widget> layers = <Widget>[
final List<Widget> layers = <Widget>[
new Scaffold(
appBar: new AppBar(title: new Text('Tap a Card')),
body: new Container(

View File

@@ -31,7 +31,7 @@ class PageViewAppState extends State<PageViewApp> {
];
cardModels = new List<CardModel>.generate(cardSizes.length, (int i) {
Color color = Color.lerp(Colors.red[300], Colors.blue[900], i / cardSizes.length);
final Color color = Color.lerp(Colors.red[300], Colors.blue[900], i / cardSizes.length);
return new CardModel(i, cardSizes[i], color);
});
}
@@ -45,7 +45,7 @@ class PageViewAppState extends State<PageViewApp> {
bool itemsWrap = false;
Widget buildCard(CardModel cardModel) {
Widget card = new Card(
final Widget card = new Card(
color: cardModel.color,
child: new Container(
width: cardModel.size.width,
@@ -55,7 +55,7 @@ class PageViewAppState extends State<PageViewApp> {
),
);
BoxConstraints constraints = (scrollDirection == Axis.vertical)
final BoxConstraints constraints = (scrollDirection == Axis.vertical)
? new BoxConstraints.tightFor(height: pageSize.height)
: new BoxConstraints.tightFor(width: pageSize.width);

View File

@@ -13,7 +13,7 @@ void main() {
await tester.pump(); // see https://github.com/flutter/flutter/issues/1865
await tester.pump(); // triggers a frame
Finder navigationMenu = find.byWidgetPredicate((Widget widget) {
final Finder navigationMenu = find.byWidgetPredicate((Widget widget) {
if (widget is Tooltip)
return widget.message == 'Open navigation menu';
return false;