Commit 7a52fb67 authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Declare locals final where not reassigned (stocks) (#8573)

parent 4c8c420e
...@@ -80,7 +80,7 @@ class StocksAppState extends State<StocksApp> { ...@@ -80,7 +80,7 @@ class StocksAppState extends State<StocksApp> {
} }
Route<Null> _getRoute(RouteSettings settings) { Route<Null> _getRoute(RouteSettings settings) {
List<String> path = settings.name.split('/'); final List<String> path = settings.name.split('/');
if (path[0] != '') if (path[0] != '')
return null; return null;
if (path[1] == 'stock') { if (path[1] == 'stock') {
...@@ -97,7 +97,7 @@ class StocksAppState extends State<StocksApp> { ...@@ -97,7 +97,7 @@ class StocksAppState extends State<StocksApp> {
} }
Future<LocaleQueryData> _onLocaleChanged(Locale locale) async { Future<LocaleQueryData> _onLocaleChanged(Locale locale) async {
String localeString = locale.toString(); final String localeString = locale.toString();
await initializeMessages(localeString); await initializeMessages(localeString);
Intl.defaultLocale = localeString; Intl.defaultLocale = localeString;
return StockStrings.instance; return StockStrings.instance;
......
...@@ -14,16 +14,16 @@ class StockArrowPainter extends CustomPainter { ...@@ -14,16 +14,16 @@ class StockArrowPainter extends CustomPainter {
@override @override
void paint(Canvas canvas, Size size) { void paint(Canvas canvas, Size size) {
Paint paint = new Paint()..color = color; final Paint paint = new Paint()..color = color;
paint.strokeWidth = 1.0; paint.strokeWidth = 1.0;
const double padding = 2.0; const double padding = 2.0;
assert(padding > paint.strokeWidth / 2.0); // make sure the circle remains inside the box assert(padding > paint.strokeWidth / 2.0); // make sure the circle remains inside the box
double r = (size.shortestSide - padding) / 2.0; // radius of the circle final double r = (size.shortestSide - padding) / 2.0; // radius of the circle
double centerX = padding + r; final double centerX = padding + r;
double centerY = padding + r; final double centerY = padding + r;
// Draw the arrow. // Draw the arrow.
double w = 8.0; final double w = 8.0;
double h = 5.0; double h = 5.0;
double arrowY; double arrowY;
if (percentChange < 0.0) { if (percentChange < 0.0) {
...@@ -32,7 +32,7 @@ class StockArrowPainter extends CustomPainter { ...@@ -32,7 +32,7 @@ class StockArrowPainter extends CustomPainter {
} else { } else {
arrowY = centerX - 1.0; arrowY = centerX - 1.0;
} }
Path path = new Path(); final Path path = new Path();
path.moveTo(centerX, arrowY - h); // top of the arrow path.moveTo(centerX, arrowY - h); // top of the arrow
path.lineTo(centerX + w, arrowY + h); path.lineTo(centerX + w, arrowY + h);
path.lineTo(centerX - w, arrowY + h); path.lineTo(centerX - w, arrowY + h);
...@@ -58,8 +58,8 @@ class StockArrow extends StatelessWidget { ...@@ -58,8 +58,8 @@ class StockArrow extends StatelessWidget {
final double percentChange; final double percentChange;
int _colorIndexForPercentChange(double percentChange) { int _colorIndexForPercentChange(double percentChange) {
double maxPercent = 10.0; final double maxPercent = 10.0;
double normalizedPercentChange = math.min(percentChange.abs(), maxPercent) / maxPercent; final double normalizedPercentChange = math.min(percentChange.abs(), maxPercent) / maxPercent;
return 100 + (normalizedPercentChange * 8.0).floor() * 100; return 100 + (normalizedPercentChange * 8.0).floor() * 100;
} }
......
...@@ -44,7 +44,7 @@ class StockData { ...@@ -44,7 +44,7 @@ class StockData {
void appendTo(Map<String, Stock> stocks, List<String> symbols) { void appendTo(Map<String, Stock> stocks, List<String> symbols) {
for (List<String> fields in _data) { for (List<String> fields in _data) {
Stock stock = new Stock.fromFields(fields); final Stock stock = new Stock.fromFields(fields);
symbols.add(stock.symbol); symbols.add(stock.symbol);
stocks[stock.symbol] = stock; stocks[stock.symbol] = stock;
} }
...@@ -73,12 +73,12 @@ class StockDataFetcher { ...@@ -73,12 +73,12 @@ class StockDataFetcher {
if (!actuallyFetchData) if (!actuallyFetchData)
return; return;
http.get(_urlToFetch(_nextChunk++)).then<Null>((http.Response response) { http.get(_urlToFetch(_nextChunk++)).then<Null>((http.Response response) {
String json = response.body; final String json = response.body;
if (json == null) { if (json == null) {
print("Failed to load stock data chunk ${_nextChunk - 1}"); print("Failed to load stock data chunk ${_nextChunk - 1}");
return null; return null;
} }
JsonDecoder decoder = const JsonDecoder(); final JsonDecoder decoder = const JsonDecoder();
callback(new StockData(decoder.convert(json))); callback(new StockData(decoder.convert(json)));
if (_nextChunk < _kChunkCount) if (_nextChunk < _kChunkCount)
_fetchNextChunk(); _fetchNextChunk();
......
...@@ -241,7 +241,7 @@ class StockHomeState extends State<StockHome> { ...@@ -241,7 +241,7 @@ class StockHomeState extends State<StockHome> {
Iterable<Stock> _filterBySearchQuery(Iterable<Stock> stocks) { Iterable<Stock> _filterBySearchQuery(Iterable<Stock> stocks) {
if (_searchQuery.text.isEmpty) if (_searchQuery.text.isEmpty)
return stocks; return stocks;
RegExp regexp = new RegExp(_searchQuery.text, caseSensitive: false); final RegExp regexp = new RegExp(_searchQuery.text, caseSensitive: false);
return stocks.where((Stock stock) => stock.symbol.contains(regexp)); return stocks.where((Stock stock) => stock.symbol.contains(regexp));
} }
......
...@@ -102,7 +102,7 @@ class StockSettingsState extends State<StockSettings> { ...@@ -102,7 +102,7 @@ class StockSettingsState extends State<StockSettings> {
} }
Widget buildSettingsPane(BuildContext context) { Widget buildSettingsPane(BuildContext context) {
List<Widget> rows = <Widget>[ final List<Widget> rows = <Widget>[
new DrawerItem( new DrawerItem(
icon: new Icon(Icons.thumb_up), icon: new Icon(Icons.thumb_up),
onPressed: () => _confirmOptimismChange(), onPressed: () => _confirmOptimismChange(),
......
...@@ -15,12 +15,12 @@ class _StockSymbolView extends StatelessWidget { ...@@ -15,12 +15,12 @@ class _StockSymbolView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}"; final String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}";
String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%"; String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%";
if (stock.percentChange > 0) if (stock.percentChange > 0)
changeInPrice = "+" + changeInPrice; changeInPrice = "+" + changeInPrice;
TextStyle headings = Theme.of(context).textTheme.body2; final TextStyle headings = Theme.of(context).textTheme.body2;
return new Container( return new Container(
padding: const EdgeInsets.all(20.0), padding: const EdgeInsets.all(20.0),
child: new Column( child: new Column(
......
...@@ -41,10 +41,10 @@ void checkIconColor(WidgetTester tester, String label, Color color) { ...@@ -41,10 +41,10 @@ void checkIconColor(WidgetTester tester, String label, Color color) {
// The icon is going to be in the same merged semantics box as the text // The icon is going to be in the same merged semantics box as the text
// regardless of how the menu item is represented, so this is a good // regardless of how the menu item is represented, so this is a good
// way to find the menu item. I hope. // way to find the menu item. I hope.
Element semantics = findElementOfExactWidgetTypeGoingUp(tester.element(find.text(label)), MergeSemantics); final Element semantics = findElementOfExactWidgetTypeGoingUp(tester.element(find.text(label)), MergeSemantics);
expect(semantics, isNotNull); expect(semantics, isNotNull);
Element asset = findElementOfExactWidgetTypeGoingDown(semantics, RichText); final Element asset = findElementOfExactWidgetTypeGoingDown(semantics, RichText);
RichText richText = asset.widget; final RichText richText = asset.widget;
expect(richText.text.style.color, equals(color)); expect(richText.text.style.color, equals(color));
} }
...@@ -64,9 +64,9 @@ void main() { ...@@ -64,9 +64,9 @@ void main() {
expect(find.text('Account Balance'), findsNothing); expect(find.text('Account Balance'), findsNothing);
// drag the drawer out // drag the drawer out
Point left = new Point(0.0, ui.window.physicalSize.height / 2.0); final Point left = new Point(0.0, ui.window.physicalSize.height / 2.0);
Point right = new Point(ui.window.physicalSize.width, left.y); final Point right = new Point(ui.window.physicalSize.width, left.y);
TestGesture gesture = await tester.startGesture(left); final TestGesture gesture = await tester.startGesture(left);
await tester.pump(); await tester.pump();
await gesture.moveTo(right); await gesture.moveTo(right);
await tester.pump(); await tester.pump();
......
...@@ -21,9 +21,9 @@ void main() { ...@@ -21,9 +21,9 @@ void main() {
}); });
test('measure', () async { test('measure', () async {
Timeline timeline = await driver.traceAction(() async { final Timeline timeline = await driver.traceAction(() async {
// Find the scrollable stock list // Find the scrollable stock list
SerializableFinder stockList = find.byValueKey('stock-list'); final SerializableFinder stockList = find.byValueKey('stock-list');
expect(stockList, isNotNull); expect(stockList, isNotNull);
// Scroll down // Scroll down
...@@ -39,7 +39,7 @@ void main() { ...@@ -39,7 +39,7 @@ void main() {
} }
}); });
TimelineSummary summary = new TimelineSummary.summarize(timeline); final TimelineSummary summary = new TimelineSummary.summarize(timeline);
summary.writeSummaryToFile('stocks_scroll_perf', pretty: true); summary.writeSummaryToFile('stocks_scroll_perf', pretty: true);
summary.writeTimelineToFile('stocks_scroll_perf', pretty: true); summary.writeTimelineToFile('stocks_scroll_perf', pretty: true);
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment