Declare locals final where not reassigned (stocks) (#8573)
This commit is contained in:
@@ -80,7 +80,7 @@ class StocksAppState extends State<StocksApp> {
|
||||
}
|
||||
|
||||
Route<Null> _getRoute(RouteSettings settings) {
|
||||
List<String> path = settings.name.split('/');
|
||||
final List<String> path = settings.name.split('/');
|
||||
if (path[0] != '')
|
||||
return null;
|
||||
if (path[1] == 'stock') {
|
||||
@@ -97,7 +97,7 @@ class StocksAppState extends State<StocksApp> {
|
||||
}
|
||||
|
||||
Future<LocaleQueryData> _onLocaleChanged(Locale locale) async {
|
||||
String localeString = locale.toString();
|
||||
final String localeString = locale.toString();
|
||||
await initializeMessages(localeString);
|
||||
Intl.defaultLocale = localeString;
|
||||
return StockStrings.instance;
|
||||
|
||||
@@ -14,16 +14,16 @@ class StockArrowPainter extends CustomPainter {
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
Paint paint = new Paint()..color = color;
|
||||
final Paint paint = new Paint()..color = color;
|
||||
paint.strokeWidth = 1.0;
|
||||
const double padding = 2.0;
|
||||
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
|
||||
double centerX = padding + r;
|
||||
double centerY = padding + r;
|
||||
final double r = (size.shortestSide - padding) / 2.0; // radius of the circle
|
||||
final double centerX = padding + r;
|
||||
final double centerY = padding + r;
|
||||
|
||||
// Draw the arrow.
|
||||
double w = 8.0;
|
||||
final double w = 8.0;
|
||||
double h = 5.0;
|
||||
double arrowY;
|
||||
if (percentChange < 0.0) {
|
||||
@@ -32,7 +32,7 @@ class StockArrowPainter extends CustomPainter {
|
||||
} else {
|
||||
arrowY = centerX - 1.0;
|
||||
}
|
||||
Path path = new Path();
|
||||
final Path path = new Path();
|
||||
path.moveTo(centerX, arrowY - h); // top of the arrow
|
||||
path.lineTo(centerX + w, arrowY + h);
|
||||
path.lineTo(centerX - w, arrowY + h);
|
||||
@@ -58,8 +58,8 @@ class StockArrow extends StatelessWidget {
|
||||
final double percentChange;
|
||||
|
||||
int _colorIndexForPercentChange(double percentChange) {
|
||||
double maxPercent = 10.0;
|
||||
double normalizedPercentChange = math.min(percentChange.abs(), maxPercent) / maxPercent;
|
||||
final double maxPercent = 10.0;
|
||||
final double normalizedPercentChange = math.min(percentChange.abs(), maxPercent) / maxPercent;
|
||||
return 100 + (normalizedPercentChange * 8.0).floor() * 100;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class StockData {
|
||||
|
||||
void appendTo(Map<String, Stock> stocks, List<String> symbols) {
|
||||
for (List<String> fields in _data) {
|
||||
Stock stock = new Stock.fromFields(fields);
|
||||
final Stock stock = new Stock.fromFields(fields);
|
||||
symbols.add(stock.symbol);
|
||||
stocks[stock.symbol] = stock;
|
||||
}
|
||||
@@ -73,12 +73,12 @@ class StockDataFetcher {
|
||||
if (!actuallyFetchData)
|
||||
return;
|
||||
http.get(_urlToFetch(_nextChunk++)).then<Null>((http.Response response) {
|
||||
String json = response.body;
|
||||
final String json = response.body;
|
||||
if (json == null) {
|
||||
print("Failed to load stock data chunk ${_nextChunk - 1}");
|
||||
return null;
|
||||
}
|
||||
JsonDecoder decoder = const JsonDecoder();
|
||||
final JsonDecoder decoder = const JsonDecoder();
|
||||
callback(new StockData(decoder.convert(json)));
|
||||
if (_nextChunk < _kChunkCount)
|
||||
_fetchNextChunk();
|
||||
|
||||
@@ -241,7 +241,7 @@ class StockHomeState extends State<StockHome> {
|
||||
Iterable<Stock> _filterBySearchQuery(Iterable<Stock> stocks) {
|
||||
if (_searchQuery.text.isEmpty)
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ class StockSettingsState extends State<StockSettings> {
|
||||
}
|
||||
|
||||
Widget buildSettingsPane(BuildContext context) {
|
||||
List<Widget> rows = <Widget>[
|
||||
final List<Widget> rows = <Widget>[
|
||||
new DrawerItem(
|
||||
icon: new Icon(Icons.thumb_up),
|
||||
onPressed: () => _confirmOptimismChange(),
|
||||
|
||||
@@ -15,12 +15,12 @@ class _StockSymbolView extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}";
|
||||
final String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}";
|
||||
String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%";
|
||||
if (stock.percentChange > 0)
|
||||
changeInPrice = "+" + changeInPrice;
|
||||
|
||||
TextStyle headings = Theme.of(context).textTheme.body2;
|
||||
final TextStyle headings = Theme.of(context).textTheme.body2;
|
||||
return new Container(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: new Column(
|
||||
|
||||
@@ -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
|
||||
// regardless of how the menu item is represented, so this is a good
|
||||
// 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);
|
||||
Element asset = findElementOfExactWidgetTypeGoingDown(semantics, RichText);
|
||||
RichText richText = asset.widget;
|
||||
final Element asset = findElementOfExactWidgetTypeGoingDown(semantics, RichText);
|
||||
final RichText richText = asset.widget;
|
||||
expect(richText.text.style.color, equals(color));
|
||||
}
|
||||
|
||||
@@ -64,9 +64,9 @@ void main() {
|
||||
expect(find.text('Account Balance'), findsNothing);
|
||||
|
||||
// drag the drawer out
|
||||
Point left = new Point(0.0, ui.window.physicalSize.height / 2.0);
|
||||
Point right = new Point(ui.window.physicalSize.width, left.y);
|
||||
TestGesture gesture = await tester.startGesture(left);
|
||||
final Point left = new Point(0.0, ui.window.physicalSize.height / 2.0);
|
||||
final Point right = new Point(ui.window.physicalSize.width, left.y);
|
||||
final TestGesture gesture = await tester.startGesture(left);
|
||||
await tester.pump();
|
||||
await gesture.moveTo(right);
|
||||
await tester.pump();
|
||||
|
||||
@@ -21,9 +21,9 @@ void main() {
|
||||
});
|
||||
|
||||
test('measure', () async {
|
||||
Timeline timeline = await driver.traceAction(() async {
|
||||
final Timeline timeline = await driver.traceAction(() async {
|
||||
// Find the scrollable stock list
|
||||
SerializableFinder stockList = find.byValueKey('stock-list');
|
||||
final SerializableFinder stockList = find.byValueKey('stock-list');
|
||||
expect(stockList, isNotNull);
|
||||
|
||||
// Scroll down
|
||||
@@ -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.writeTimelineToFile('stocks_scroll_perf', pretty: true);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user