From f2cc43a483784a5106a49cf8fab9dd570d287a1d Mon Sep 17 00:00:00 2001 From: Hixie Date: Fri, 9 Oct 2015 13:54:40 -0700 Subject: [PATCH] Lots of trivial warning fixes Add type annotations in many places. Fix some identifiers to have more lint-satisfying names. Make all operator==s consistent in style. Reorder some functions for consistency. Make ParentData no longer dynamic, and fix all the code around that. --- examples/stocks/lib/stock_data.dart | 6 +- examples/stocks/lib/stock_home.dart | 24 +-- examples/stocks/lib/stock_menu.dart | 6 +- examples/stocks/lib/stock_row.dart | 14 +- examples/stocks/lib/stock_settings.dart | 10 +- examples/stocks/lib/stock_symbol_viewer.dart | 6 +- .../flutter/lib/src/animation/scheduler.dart | 2 +- .../flutter/lib/src/gestures/recognizer.dart | 2 +- .../flutter/lib/src/material/checkbox.dart | 2 +- packages/flutter/lib/src/material/colors.dart | 70 ++++---- .../flutter/lib/src/material/date_picker.dart | 12 +- packages/flutter/lib/src/material/dialog.dart | 2 +- packages/flutter/lib/src/material/drawer.dart | 2 +- .../lib/src/material/drawer_header.dart | 2 +- packages/flutter/lib/src/material/edges.dart | 2 +- packages/flutter/lib/src/material/icon.dart | 10 +- packages/flutter/lib/src/material/input.dart | 1 + .../flutter/lib/src/material/popup_menu.dart | 8 +- .../lib/src/material/progress_indicator.dart | 2 +- .../lib/src/material/radial_reaction.dart | 2 +- .../flutter/lib/src/material/shadows.dart | 12 +- .../flutter/lib/src/material/snack_bar.dart | 4 +- packages/flutter/lib/src/material/switch.dart | 2 +- packages/flutter/lib/src/material/tabs.dart | 52 +++--- .../flutter/lib/src/material/tool_bar.dart | 2 +- .../flutter/lib/src/painting/box_painter.dart | 31 ++-- .../flutter/lib/src/painting/shadows.dart | 23 +-- .../lib/src/painting/text_painter.dart | 84 ++++++++-- .../flutter/lib/src/painting/text_style.dart | 36 ++-- .../lib/src/rendering/auto_layout.dart | 26 +-- packages/flutter/lib/src/rendering/block.dart | 45 +++-- packages/flutter/lib/src/rendering/box.dart | 63 +++---- packages/flutter/lib/src/rendering/flex.dart | 47 +++--- packages/flutter/lib/src/rendering/grid.dart | 9 +- packages/flutter/lib/src/rendering/image.dart | 2 +- .../flutter/lib/src/rendering/object.dart | 157 +++++++++--------- .../flutter/lib/src/rendering/proxy_box.dart | 18 +- .../lib/src/rendering/shifted_box.dart | 34 ++-- packages/flutter/lib/src/rendering/stack.dart | 87 +++++----- .../flutter/lib/src/rendering/viewport.dart | 4 +- .../lib/src/services/asset_bundle.dart | 2 +- packages/flutter/lib/src/services/fetch.dart | 2 +- .../flutter/lib/src/services/image_cache.dart | 5 +- packages/flutter/lib/src/widgets/basic.dart | 4 +- .../lib/src/widgets/editable_text.dart | 40 +++-- .../flutter/lib/src/widgets/framework.dart | 76 +++++---- .../lib/src/widgets/mixed_viewport.dart | 10 +- .../flutter/lib/src/widgets/scrollable.dart | 4 +- .../lib/src/widgets/statistics_overlay.dart | 14 +- packages/unit/test/widget/input_test.dart | 16 +- 50 files changed, 611 insertions(+), 485 deletions(-) diff --git a/examples/stocks/lib/stock_data.dart b/examples/stocks/lib/stock_data.dart index ed7c726501..53bffc3ba3 100644 --- a/examples/stocks/lib/stock_data.dart +++ b/examples/stocks/lib/stock_data.dart @@ -57,8 +57,8 @@ const _kChunkCount = 30; String _urlToFetch(int chunk) { if (rootBundle == null) - return '../data/stock_data_${chunk}.json'; - return 'https://domokit.github.io/examples/stocks/data/stock_data_${chunk}.json'; + return '../data/stock_data_$chunk.json'; + return 'https://domokit.github.io/examples/stocks/data/stock_data_$chunk.json'; } class StockDataFetcher { @@ -81,9 +81,7 @@ class StockDataFetcher { return; } JsonDecoder decoder = new JsonDecoder(); - callback(new StockData(decoder.convert(json))); - if (_nextChunk < _kChunkCount) _fetchNextChunk(); }); diff --git a/examples/stocks/lib/stock_home.dart b/examples/stocks/lib/stock_home.dart index b42f035783..0d18aec008 100644 --- a/examples/stocks/lib/stock_home.dart +++ b/examples/stocks/lib/stock_home.dart @@ -37,8 +37,10 @@ class StockHomeState extends State { } void _handleSearchEnd() { - assert(config.navigator.currentRoute is StateRoute); - assert((config.navigator.currentRoute as StateRoute).owner == this); // TODO(ianh): remove cast once analyzer is cleverer + assert(() { + final StateRoute currentRoute = config.navigator.currentRoute; + assert(currentRoute.owner == this); + }); config.navigator.pop(); setState(() { _isSearching = false; @@ -74,7 +76,7 @@ class StockHomeState extends State { void _showDrawer() { showDrawer( navigator: config.navigator, - child: new Block([ + child: new Block([ new DrawerHeader(child: new Text('Stocks')), new DrawerItem( icon: 'action/assessment', @@ -88,7 +90,7 @@ class StockHomeState extends State { return new Dialog( title: new Text('Not Implemented'), content: new Text('This feature has not yet been implemented.'), - actions: [ + actions: [ new FlatButton( child: new Text('USE IT'), enabled: false, @@ -117,7 +119,7 @@ class StockHomeState extends State { new DrawerItem( icon: 'action/thumb_up', onPressed: () => _handleStockModeChange(StockMode.optimistic), - child: new Row([ + child: new Row([ new Flexible(child: new Text('Optimistic')), new Radio(value: StockMode.optimistic, groupValue: config.stockMode, onChanged: _handleStockModeChange) ]) @@ -125,7 +127,7 @@ class StockHomeState extends State { new DrawerItem( icon: 'action/thumb_down', onPressed: () => _handleStockModeChange(StockMode.pessimistic), - child: new Row([ + child: new Row([ new Flexible(child: new Text('Pessimistic')), new Radio(value: StockMode.pessimistic, groupValue: config.stockMode, onChanged: _handleStockModeChange) ]) @@ -155,7 +157,7 @@ class StockHomeState extends State { onPressed: _showDrawer ), center: new Text('Stocks'), - right: [ + right: [ new IconButton( icon: "action/search", onPressed: _handleSearchBegin @@ -171,14 +173,14 @@ class StockHomeState extends State { int selectedTabIndex = 0; Iterable _getStockList(Iterable symbols) { - return symbols.map((symbol) => config.stocks[symbol]); + return symbols.map((String symbol) => config.stocks[symbol]); } Iterable _filterBySearchQuery(Iterable stocks) { if (_searchQuery == null) return stocks; RegExp regexp = new RegExp(_searchQuery, caseSensitive: false); - return stocks.where((stock) => stock.symbol.contains(regexp)); + return stocks.where((Stock stock) => stock.symbol.contains(regexp)); } Widget buildStockList(BuildContext context, Iterable stocks) { @@ -211,7 +213,7 @@ class StockHomeState extends State { ) ], selectedIndex: selectedTabIndex, - onChanged: (tabIndex) { + onChanged: (int tabIndex) { setState(() { selectedTabIndex = tabIndex; } ); } ); @@ -245,7 +247,7 @@ class StockHomeState extends State { navigator: config.navigator, placeholderKey: _snackBarPlaceholderKey, content: new Text("Stock purchased!"), - actions: [ + actions: [ new SnackBarAction(label: "UNDO", onPressed: _handleUndo) ] ); diff --git a/examples/stocks/lib/stock_menu.dart b/examples/stocks/lib/stock_menu.dart index 1a1ca9af4e..d6ab8b998f 100644 --- a/examples/stocks/lib/stock_menu.dart +++ b/examples/stocks/lib/stock_menu.dart @@ -19,7 +19,7 @@ Future showStockMenu(NavigatorState navigator, { bool autorefresh, ValueChanged return [ new PopupMenuItem( value: _MenuItems.autorefresh, - child: new Row([ + child: new Row([ new Flexible(child: new Text('Autorefresh')), new Checkbox( value: autorefresh, @@ -59,9 +59,9 @@ Future showStockMenu(NavigatorState navigator, { bool autorefresh, ValueChanged return new Dialog( title: new Text('Not Implemented'), content: new Text('This feature has not yet been implemented.'), - actions: [ + actions: [ new FlatButton( - child: new Row([ + child: new Row([ new Icon( type: 'device/dvr', size: 18 diff --git a/examples/stocks/lib/stock_row.dart b/examples/stocks/lib/stock_row.dart index da95327cf1..3014eb21ff 100644 --- a/examples/stocks/lib/stock_row.dart +++ b/examples/stocks/lib/stock_row.dart @@ -10,9 +10,15 @@ class StockRowPartGlobalKey extends GlobalKey { const StockRowPartGlobalKey(this.stock, this.part) : super.constructor(); final Stock stock; final StockRowPartKind part; - String toString() => '[StockRowPartGlobalKey ${stock.symbol}:${part.toString().split(".")[1]})]'; - bool operator==(other) => other is StockRowPartGlobalKey && identical(other.stock, stock) && identical(other.part, part); + bool operator ==(dynamic other) { + if (other is! StockRowPartGlobalKey) + return false; + final StockRowPartGlobalKey typedOther = other; + return stock == typedOther.stock && + part == typedOther.part; + } int get hashCode => 37 * (37 * (373) + identityHashCode(stock)) + identityHashCode(part); + String toString() => '[StockRowPartGlobalKey ${stock.symbol}:${part.toString().split(".")[1]})]'; } typedef void StockRowActionCallback(Stock stock, GlobalKey row, GlobalKey arrowKey, GlobalKey symbolKey, GlobalKey priceKey); @@ -65,14 +71,14 @@ class StockRow extends StatelessComponent { bottom: new BorderSide(color: Theme.of(context).dividerColor) ) ), - child: new Row([ + child: new Row([ new Container( key: arrowKey, child: new StockArrow(percentChange: stock.percentChange), margin: const EdgeDims.only(right: 5.0) ), new Flexible( - child: new Row([ + child: new Row([ new Flexible( flex: 2, child: new Text( diff --git a/examples/stocks/lib/stock_settings.dart b/examples/stocks/lib/stock_settings.dart index 1be3c8266c..c0404c7268 100644 --- a/examples/stocks/lib/stock_settings.dart +++ b/examples/stocks/lib/stock_settings.dart @@ -42,7 +42,7 @@ class StockSettingsState extends State { onDismiss: () { navigator.pop(false); }, - actions: [ + actions: [ new FlatButton( child: new Text('NO THANKS'), onPressed: () { @@ -87,22 +87,22 @@ class StockSettingsState extends State { child: new ScrollableViewport( child: new Container( padding: const EdgeDims.symmetric(vertical: 20.0), - child: new BlockBody([ + child: new BlockBody([ new DrawerItem( icon: 'action/thumb_up', onPressed: () => _confirmOptimismChange(), - child: new Row([ + child: new Row([ new Flexible(child: new Text('Everything is awesome')), new Checkbox( value: config.optimism == StockMode.optimistic, - onChanged: (_) => _confirmOptimismChange() + onChanged: (bool value) => _confirmOptimismChange() ), ]) ), new DrawerItem( icon: 'action/backup', onPressed: () { _handleBackupChanged(!(config.backup == BackupMode.enabled)); }, - child: new Row([ + child: new Row([ new Flexible(child: new Text('Back up stock list to the cloud')), new Switch( value: config.backup == BackupMode.enabled, diff --git a/examples/stocks/lib/stock_symbol_viewer.dart b/examples/stocks/lib/stock_symbol_viewer.dart index 3f73b08a19..ec0dd6c275 100644 --- a/examples/stocks/lib/stock_symbol_viewer.dart +++ b/examples/stocks/lib/stock_symbol_viewer.dart @@ -33,12 +33,12 @@ class StockSymbolViewerState extends State { center: new Text('${config.stock.name} (${config.stock.symbol})') ), body: new Material( - child: new Block([ + child: new Block([ new Container( padding: new EdgeDims.all(20.0), - child: new Column([ + child: new Column([ new Text('Last Sale', style: headings), - new Text('${lastSale} (${changeInPrice})'), + new Text('$lastSale ($changeInPrice)'), new Container( height: 8.0 ), diff --git a/packages/flutter/lib/src/animation/scheduler.dart b/packages/flutter/lib/src/animation/scheduler.dart index 064762ded6..699ced4830 100644 --- a/packages/flutter/lib/src/animation/scheduler.dart +++ b/packages/flutter/lib/src/animation/scheduler.dart @@ -45,7 +45,7 @@ class Scheduler { Map callbacks = _transientCallbacks; _transientCallbacks = new Map(); - callbacks.forEach((id, callback) { + callbacks.forEach((int id, SchedulerCallback callback) { if (!_removedIds.contains(id)) callback(timeStamp); }); diff --git a/packages/flutter/lib/src/gestures/recognizer.dart b/packages/flutter/lib/src/gestures/recognizer.dart index a2fca88a5f..9adcb3d90a 100644 --- a/packages/flutter/lib/src/gestures/recognizer.dart +++ b/packages/flutter/lib/src/gestures/recognizer.dart @@ -30,7 +30,7 @@ abstract class GestureRecognizer extends GestureArenaMember { void didStopTrackingLastPointer(int pointer); void resolve(GestureDisposition disposition) { - List localEntries = new List.from(_entries); + List localEntries = new List.from(_entries); _entries.clear(); for (GestureArenaEntry entry in localEntries) entry.resolve(disposition); diff --git a/packages/flutter/lib/src/material/checkbox.dart b/packages/flutter/lib/src/material/checkbox.dart index df7ee5ce57..4de7ed9f4e 100644 --- a/packages/flutter/lib/src/material/checkbox.dart +++ b/packages/flutter/lib/src/material/checkbox.dart @@ -151,7 +151,7 @@ class _RenderCheckbox extends RenderToggleable { paint.setStyle(ui.PaintingStyle.fill); paint.setShader(new ui.Gradient.radial( new Point(_kEdgeSize / 2.0, _kEdgeSize / 2.0), - _kEdgeSize * (_kMidpoint - position) * 8.0, [ + _kEdgeSize * (_kMidpoint - position) * 8.0, [ const ui.Color(0x00000000), uncheckedColor ])); diff --git a/packages/flutter/lib/src/material/colors.dart b/packages/flutter/lib/src/material/colors.dart index 7df8de2529..68fa5913e3 100644 --- a/packages/flutter/lib/src/material/colors.dart +++ b/packages/flutter/lib/src/material/colors.dart @@ -21,7 +21,7 @@ class Colors { static const white30 = const Color(0x4DFFFFFF); // text of disabled flat button in dark theme static const white12 = const Color(0x1FFFFFFF); // background of disabled raised buttons in dark theme - static const Map red = const { + static const Map red = const { 50: const Color(0xFFFFEBEE), 100: const Color(0xFFFFCDD2), 200: const Color(0xFFEF9A9A), @@ -34,14 +34,14 @@ class Colors { 900: const Color(0xFFB71C1C), }; - static const Map redAccent = const { + static const Map redAccent = const { 100: const Color(0xFFFF8A80), 200: const Color(0xFFFF5252), 400: const Color(0xFFFF1744), 700: const Color(0xFFD50000), }; - static const Map pink = const { + static const Map pink = const { 50: const Color(0xFFFCE4EC), 100: const Color(0xFFF8BBD0), 200: const Color(0xFFF48FB1), @@ -54,14 +54,14 @@ class Colors { 900: const Color(0xFF880E4F), }; - static const Map pinkAccent = const { + static const Map pinkAccent = const { 100: const Color(0xFFFF80AB), 200: const Color(0xFFFF4081), 400: const Color(0xFFF50057), 700: const Color(0xFFC51162), }; - static const Map purple = const { + static const Map purple = const { 50: const Color(0xFFF3E5F5), 100: const Color(0xFFE1BEE7), 200: const Color(0xFFCE93D8), @@ -74,14 +74,14 @@ class Colors { 900: const Color(0xFF4A148C), }; - static const Map purpleAccent = const { + static const Map purpleAccent = const { 100: const Color(0xFFEA80FC), 200: const Color(0xFFE040FB), 400: const Color(0xFFD500F9), 700: const Color(0xFFAA00FF), }; - static const Map deepPurple = const { + static const Map deepPurple = const { 50: const Color(0xFFEDE7F6), 100: const Color(0xFFD1C4E9), 200: const Color(0xFFB39DDB), @@ -94,14 +94,14 @@ class Colors { 900: const Color(0xFF311B92), }; - static const Map deepPurpleAccent = const { + static const Map deepPurpleAccent = const { 100: const Color(0xFFB388FF), 200: const Color(0xFF7C4DFF), 400: const Color(0xFF651FFF), 700: const Color(0xFF6200EA), }; - static const Map indigo = const { + static const Map indigo = const { 50: const Color(0xFFE8EAF6), 100: const Color(0xFFC5CAE9), 200: const Color(0xFF9FA8DA), @@ -114,14 +114,14 @@ class Colors { 900: const Color(0xFF1A237E), }; - static const Map indigoAccent = const { + static const Map indigoAccent = const { 100: const Color(0xFF8C9EFF), 200: const Color(0xFF536DFE), 400: const Color(0xFF3D5AFE), 700: const Color(0xFF304FFE), }; - static const Map blue = const { + static const Map blue = const { 50: const Color(0xFFE3F2FD), 100: const Color(0xFFBBDEFB), 200: const Color(0xFF90CAF9), @@ -134,14 +134,14 @@ class Colors { 900: const Color(0xFF0D47A1), }; - static const Map blueAccent = const { + static const Map blueAccent = const { 100: const Color(0xFF82B1FF), 200: const Color(0xFF448AFF), 400: const Color(0xFF2979FF), 700: const Color(0xFF2962FF), }; - static const Map lightBlue = const { + static const Map lightBlue = const { 50: const Color(0xFFE1F5FE), 100: const Color(0xFFB3E5FC), 200: const Color(0xFF81D4FA), @@ -154,14 +154,14 @@ class Colors { 900: const Color(0xFF01579B), }; - static const Map lightBlueAccent = const { + static const Map lightBlueAccent = const { 100: const Color(0xFF80D8FF), 200: const Color(0xFF40C4FF), 400: const Color(0xFF00B0FF), 700: const Color(0xFF0091EA), }; - static const Map cyan = const { + static const Map cyan = const { 50: const Color(0xFFE0F7FA), 100: const Color(0xFFB2EBF2), 200: const Color(0xFF80DEEA), @@ -174,14 +174,14 @@ class Colors { 900: const Color(0xFF006064), }; - static const Map cyanAccent = const { + static const Map cyanAccent = const { 100: const Color(0xFF84FFFF), 200: const Color(0xFF18FFFF), 400: const Color(0xFF00E5FF), 700: const Color(0xFF00B8D4), }; - static const Map teal = const { + static const Map teal = const { 50: const Color(0xFFE0F2F1), 100: const Color(0xFFB2DFDB), 200: const Color(0xFF80CBC4), @@ -194,14 +194,14 @@ class Colors { 900: const Color(0xFF004D40), }; - static const Map tealAccent = const { + static const Map tealAccent = const { 100: const Color(0xFFA7FFEB), 200: const Color(0xFF64FFDA), 400: const Color(0xFF1DE9B6), 700: const Color(0xFF00BFA5), }; - static const Map green = const { + static const Map green = const { 50: const Color(0xFFE8F5E9), 100: const Color(0xFFC8E6C9), 200: const Color(0xFFA5D6A7), @@ -214,14 +214,14 @@ class Colors { 900: const Color(0xFF1B5E20), }; - static const Map greenAccent = const { + static const Map greenAccent = const { 100: const Color(0xFFB9F6CA), 200: const Color(0xFF69F0AE), 400: const Color(0xFF00E676), 700: const Color(0xFF00C853), }; - static const Map lightGreen = const { + static const Map lightGreen = const { 50: const Color(0xFFF1F8E9), 100: const Color(0xFFDCEDC8), 200: const Color(0xFFC5E1A5), @@ -234,14 +234,14 @@ class Colors { 900: const Color(0xFF33691E), }; - static const Map lightGreenAccent = const { + static const Map lightGreenAccent = const { 100: const Color(0xFFCCFF90), 200: const Color(0xFFB2FF59), 400: const Color(0xFF76FF03), 700: const Color(0xFF64DD17), }; - static const Map lime = const { + static const Map lime = const { 50: const Color(0xFFF9FBE7), 100: const Color(0xFFF0F4C3), 200: const Color(0xFFE6EE9C), @@ -254,14 +254,14 @@ class Colors { 900: const Color(0xFF827717), }; - static const Map limeAccent = const { + static const Map limeAccent = const { 100: const Color(0xFFF4FF81), 200: const Color(0xFFEEFF41), 400: const Color(0xFFC6FF00), 700: const Color(0xFFAEEA00), }; - static const Map yellow = const { + static const Map yellow = const { 50: const Color(0xFFFFFDE7), 100: const Color(0xFFFFF9C4), 200: const Color(0xFFFFF59D), @@ -274,14 +274,14 @@ class Colors { 900: const Color(0xFFF57F17), }; - static const Map yellowAccent = const { + static const Map yellowAccent = const { 100: const Color(0xFFFFFF8D), 200: const Color(0xFFFFFF00), 400: const Color(0xFFFFEA00), 700: const Color(0xFFFFD600), }; - static const Map amber = const { + static const Map amber = const { 50: const Color(0xFFFFF8E1), 100: const Color(0xFFFFECB3), 200: const Color(0xFFFFE082), @@ -294,14 +294,14 @@ class Colors { 900: const Color(0xFFFF6F00), }; - static const Map amberAccent = const { + static const Map amberAccent = const { 100: const Color(0xFFFFE57F), 200: const Color(0xFFFFD740), 400: const Color(0xFFFFC400), 700: const Color(0xFFFFAB00), }; - static const Map orange = const { + static const Map orange = const { 50: const Color(0xFFFFF3E0), 100: const Color(0xFFFFE0B2), 200: const Color(0xFFFFCC80), @@ -314,14 +314,14 @@ class Colors { 900: const Color(0xFFE65100), }; - static const Map orangeAccent = const { + static const Map orangeAccent = const { 100: const Color(0xFFFFD180), 200: const Color(0xFFFFAB40), 400: const Color(0xFFFF9100), 700: const Color(0xFFFF6D00), }; - static const Map deepOrange = const { + static const Map deepOrange = const { 50: const Color(0xFFFBE9E7), 100: const Color(0xFFFFCCBC), 200: const Color(0xFFFFAB91), @@ -334,14 +334,14 @@ class Colors { 900: const Color(0xFFBF360C), }; - static const Map deepOrangeAccent = const { + static const Map deepOrangeAccent = const { 100: const Color(0xFFFF9E80), 200: const Color(0xFFFF6E40), 400: const Color(0xFFFF3D00), 700: const Color(0xFFDD2C00), }; - static const Map brown = const { + static const Map brown = const { 50: const Color(0xFFEFEBE9), 100: const Color(0xFFD7CCC8), 200: const Color(0xFFBCAAA4), @@ -354,7 +354,7 @@ class Colors { 900: const Color(0xFF3E2723), }; - static const Map grey = const { + static const Map grey = const { 50: const Color(0xFFFAFAFA), 100: const Color(0xFFF5F5F5), 200: const Color(0xFFEEEEEE), @@ -369,7 +369,7 @@ class Colors { 900: const Color(0xFF212121), }; - static const Map blueGrey = const { + static const Map blueGrey = const { 50: const Color(0xFFECEFF1), 100: const Color(0xFFCFD8DC), 200: const Color(0xFFB0BEC5), diff --git a/packages/flutter/lib/src/material/date_picker.dart b/packages/flutter/lib/src/material/date_picker.dart index 12b9227c67..46caf21ff3 100644 --- a/packages/flutter/lib/src/material/date_picker.dart +++ b/packages/flutter/lib/src/material/date_picker.dart @@ -94,7 +94,7 @@ class _DatePickerState extends State { ); break; } - return new Column([ + return new Column([ header, new Container( height: _calendarHeight, @@ -145,7 +145,7 @@ class _DatePickerHeader extends StatelessComponent { return new Container( padding: new EdgeDims.all(10.0), decoration: new BoxDecoration(backgroundColor: theme.primaryColor), - child: new Column([ + child: new Column([ new GestureDetector( onTap: () => _handleChangeMode(DatePickerMode.day), child: new Text(new DateFormat("MMM").format(selectedDate).toUpperCase(), style: monthStyle) @@ -190,11 +190,11 @@ class DayPicker extends StatelessComponent { DateFormat dateFormat = new DateFormat(); DateSymbols symbols = dateFormat.dateSymbols; - List headers = []; + List headers = []; for (String weekDay in symbols.NARROWWEEKDAYS) { headers.add(new Text(weekDay, style: headerStyle)); } - List rows = [ + List rows = [ new Text(new DateFormat("MMMM y").format(displayedMonth), style: monthStyle), new Flex( headers, @@ -208,7 +208,7 @@ class DayPicker extends StatelessComponent { int daysInMonth = new DateTime(year, month + 1).difference(new DateTime(year, month)).inDays; int firstDay = new DateTime(year, month).day; int weeksShown = 6; - List days = [ + List days = [ DateTime.SUNDAY, DateTime.MONDAY, DateTime.TUESDAY, @@ -218,7 +218,7 @@ class DayPicker extends StatelessComponent { DateTime.SATURDAY ]; int daySlots = weeksShown * days.length; - List labels = []; + List labels = []; for (int i = 0; i < daySlots; i++) { // This assumes a start day of SUNDAY, but could be changed. int day = i - firstDay + 1; diff --git a/packages/flutter/lib/src/material/dialog.dart b/packages/flutter/lib/src/material/dialog.dart index 1f60f36f96..9a39a00578 100644 --- a/packages/flutter/lib/src/material/dialog.dart +++ b/packages/flutter/lib/src/material/dialog.dart @@ -101,7 +101,7 @@ class Dialog extends StatelessComponent { )); } - return new Stack([ + return new Stack([ new GestureDetector( onTap: onDismiss, child: new Container( diff --git a/packages/flutter/lib/src/material/drawer.dart b/packages/flutter/lib/src/material/drawer.dart index 8e6dc024f4..d41e0875de 100644 --- a/packages/flutter/lib/src/material/drawer.dart +++ b/packages/flutter/lib/src/material/drawer.dart @@ -61,7 +61,7 @@ class _Drawer extends StatelessComponent { if (interactive) route._settle(velocity); }, - child: new Stack([ + child: new Stack([ // mask new GestureDetector( onTap: () { diff --git a/packages/flutter/lib/src/material/drawer_header.dart b/packages/flutter/lib/src/material/drawer_header.dart index 8078c0179b..650d0f2422 100644 --- a/packages/flutter/lib/src/material/drawer_header.dart +++ b/packages/flutter/lib/src/material/drawer_header.dart @@ -29,7 +29,7 @@ class DrawerHeader extends StatelessComponent { ), padding: const EdgeDims.only(bottom: 7.0), margin: const EdgeDims.only(bottom: 8.0), - child: new Column([ + child: new Column([ new Flexible(child: new Container()), new Container( padding: const EdgeDims.symmetric(horizontal: 16.0), diff --git a/packages/flutter/lib/src/material/edges.dart b/packages/flutter/lib/src/material/edges.dart index fad0e0f09d..c753c423ba 100644 --- a/packages/flutter/lib/src/material/edges.dart +++ b/packages/flutter/lib/src/material/edges.dart @@ -5,7 +5,7 @@ enum MaterialEdge { canvas, card, circle } // This map gives the border radii for each type of material. -const Map edges = const { +const Map edges = const { MaterialEdge.canvas: null, MaterialEdge.card: 2.0, MaterialEdge.circle: null, diff --git a/packages/flutter/lib/src/material/icon.dart b/packages/flutter/lib/src/material/icon.dart index 223dc78de5..8c25d35387 100644 --- a/packages/flutter/lib/src/material/icon.dart +++ b/packages/flutter/lib/src/material/icon.dart @@ -15,7 +15,13 @@ class IconThemeData { const IconThemeData({ this.color }); final IconThemeColor color; - bool operator==(other) => other.runtimeType == runtimeType && other.color == color; + bool operator ==(dynamic other) { + if (other is! IconThemeData) + return false; + final IconThemeData typedOther = other; + return color == typedOther; + } + int get hashCode => color.hashCode; } @@ -96,7 +102,7 @@ class Icon extends StatelessComponent { String colorSuffix = _getColorSuffix(context); return new AssetImage( bundle: _iconBundle, - name: '${category}/${density}/ic_${subtype}_${colorSuffix}_${size}dp.png', + name: '$category/$density/ic_${subtype}_${colorSuffix}_${size}dp.png', width: size.toDouble(), height: size.toDouble(), colorFilter: colorFilter diff --git a/packages/flutter/lib/src/material/input.dart b/packages/flutter/lib/src/material/input.dart index 608601d4d4..1322f68473 100644 --- a/packages/flutter/lib/src/material/input.dart +++ b/packages/flutter/lib/src/material/input.dart @@ -119,6 +119,7 @@ class _InputState extends ScrollableState { ) ), onPointerDown: (_) { + // TODO(ianh): https://github.com/flutter/engine/issues/1530 if (Focus.at(context, config)) { assert(_keyboardHandle.attached); _keyboardHandle.showByRequest(); diff --git a/packages/flutter/lib/src/material/popup_menu.dart b/packages/flutter/lib/src/material/popup_menu.dart index 65bf342b09..10d0c2bab0 100644 --- a/packages/flutter/lib/src/material/popup_menu.dart +++ b/packages/flutter/lib/src/material/popup_menu.dart @@ -49,7 +49,7 @@ class PopupMenu extends StatelessComponent { )); double unit = 1.0 / (items.length + 1.5); // 1.0 for the width and 0.5 for the last item's fade. - List children = []; + List children = []; for (int i = 0; i < items.length; ++i) { double start = (i + 1) * unit; @@ -64,15 +64,15 @@ class PopupMenu extends StatelessComponent { ); } - final width = new AnimatedValue(0.0, end: 1.0, curve: new Interval(0.0, unit)); - final height = new AnimatedValue(0.0, end: 1.0, curve: new Interval(0.0, unit * items.length)); + final AnimatedValue width = new AnimatedValue(0.0, end: 1.0, curve: new Interval(0.0, unit)); + final AnimatedValue height = new AnimatedValue(0.0, end: 1.0, curve: new Interval(0.0, unit * items.length)); return new FadeTransition( performance: performance, opacity: new AnimatedValue(0.0, end: 1.0, curve: new Interval(0.0, 1.0 / 3.0)), child: new BuilderTransition( performance: performance, - variables: [width, height], + variables: >[width, height], builder: (BuildContext context) { return new CustomPaint( callback: (ui.Canvas canvas, Size size) { diff --git a/packages/flutter/lib/src/material/progress_indicator.dart b/packages/flutter/lib/src/material/progress_indicator.dart index 46d31717a2..2c20a0af3e 100644 --- a/packages/flutter/lib/src/material/progress_indicator.dart +++ b/packages/flutter/lib/src/material/progress_indicator.dart @@ -60,7 +60,7 @@ class _ProgressIndicatorState extends State { return config._buildIndicator(context, _performance.value); return new BuilderTransition( - variables: [_performance.variable], + variables: >[_performance.variable], performance: _performance.view, builder: (BuildContext context) { return config._buildIndicator(context, _performance.value); diff --git a/packages/flutter/lib/src/material/radial_reaction.dart b/packages/flutter/lib/src/material/radial_reaction.dart index 35538fa79f..ee4748f909 100644 --- a/packages/flutter/lib/src/material/radial_reaction.dart +++ b/packages/flutter/lib/src/material/radial_reaction.dart @@ -37,7 +37,7 @@ class RadialReaction { _showPerformance.updateVariable(_innerRadius); }); _fade = new ValuePerformance( - variable: new AnimatedValue(1.0, end: 0.0, curve: easeIn), + variable: new AnimatedValue(1.0, end: 0.0, curve: easeIn), duration: _kHideDuration ); } diff --git a/packages/flutter/lib/src/material/shadows.dart b/packages/flutter/lib/src/material/shadows.dart index f9e998eef4..32be8300d2 100644 --- a/packages/flutter/lib/src/material/shadows.dart +++ b/packages/flutter/lib/src/material/shadows.dart @@ -6,8 +6,8 @@ import 'dart:ui' show Color, Offset; import 'package:flutter/painting.dart'; -const Map> shadows = const { - 1: const [ +const Map> shadows = const >{ + 1: const [ const BoxShadow( color: const Color(0x1F000000), offset: const Offset(0.0, 1.0), @@ -17,7 +17,7 @@ const Map> shadows = const { offset: const Offset(0.0, 1.0), blur: 2.0), ], - 2: const [ + 2: const [ const BoxShadow( color: const Color(0x29000000), offset: const Offset(0.0, 3.0), @@ -27,7 +27,7 @@ const Map> shadows = const { offset: const Offset(0.0, 3.0), blur: 6.0), ], - 3: const [ + 3: const [ const BoxShadow( color: const Color(0x30000000), offset: const Offset(0.0, 10.0), @@ -37,7 +37,7 @@ const Map> shadows = const { offset: const Offset(0.0, 6.0), blur: 6.0), ], - 4: const [ + 4: const [ const BoxShadow( color: const Color(0x40000000), offset: const Offset(0.0, 14.0), @@ -47,7 +47,7 @@ const Map> shadows = const { offset: const Offset(0.0, 10.0), blur: 10.0), ], - 5: const [ + 5: const [ const BoxShadow( color: const Color(0x4E000000), offset: const Offset(0.0, 19.0), diff --git a/packages/flutter/lib/src/material/snack_bar.dart b/packages/flutter/lib/src/material/snack_bar.dart index 8b631d0ce4..3441fa7438 100644 --- a/packages/flutter/lib/src/material/snack_bar.dart +++ b/packages/flutter/lib/src/material/snack_bar.dart @@ -24,7 +24,7 @@ class SnackBarAction extends StatelessComponent { final String label; final GestureTapCallback onPressed; - Widget build(BuildContext) { + Widget build(BuildContext context) { return new GestureDetector( onTap: onPressed, child: new Container( @@ -51,7 +51,7 @@ class SnackBar extends StatelessComponent { final PerformanceView performance; Widget build(BuildContext context) { - List children = [ + List children = [ new Flexible( child: new Container( margin: const EdgeDims.symmetric(vertical: _kVerticalPadding), diff --git a/packages/flutter/lib/src/material/switch.dart b/packages/flutter/lib/src/material/switch.dart index 9b6573dd04..c5233fa2a3 100644 --- a/packages/flutter/lib/src/material/switch.dart +++ b/packages/flutter/lib/src/material/switch.dart @@ -70,7 +70,7 @@ class _RenderSwitch extends RenderToggleable { Color thumbColor: _kThumbOffColor, ValueChanged onChanged }) : _thumbColor = thumbColor, - super(value: value, onChanged: onChanged, size: _kSwitchSize) {} + super(value: value, onChanged: onChanged, size: _kSwitchSize); Color _thumbColor; Color get thumbColor => _thumbColor; diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index 982efcf7ea..695708b531 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -33,8 +33,7 @@ const int _kTabIconSize = 24; const double _kTabBarScrollDrag = 0.025; const Duration _kTabBarScroll = const Duration(milliseconds: 200); -class _TabBarParentData extends BoxParentData with - ContainerParentDataMixin { } +class _TabBarParentData extends ContainerBoxParentDataMixin { } class _RenderTabBar extends RenderBox with ContainerRenderObjectMixin, @@ -100,8 +99,8 @@ class _RenderTabBar extends RenderBox with RenderBox child = firstChild; while (child != null) { maxWidth = math.max(maxWidth, child.getMinIntrinsicWidth(widthConstraints)); - assert(child.parentData is _TabBarParentData); - child = child.parentData.nextSibling; + final _TabBarParentData childParentData = child.parentData; + child = childParentData.nextSibling; } double width = isScrollable ? maxWidth : maxWidth * childCount; return constraints.constrainWidth(width); @@ -115,8 +114,8 @@ class _RenderTabBar extends RenderBox with RenderBox child = firstChild; while (child != null) { maxWidth = math.max(maxWidth, child.getMaxIntrinsicWidth(widthConstraints)); - assert(child.parentData is _TabBarParentData); - child = child.parentData.nextSibling; + final _TabBarParentData childParentData = child.parentData; + child = childParentData.nextSibling; } double width = isScrollable ? maxWidth : maxWidth * childCount; return constraints.constrainWidth(width); @@ -139,10 +138,10 @@ class _RenderTabBar extends RenderBox with RenderBox child = firstChild; while (child != null) { child.layout(tabConstraints); - assert(child.parentData is _TabBarParentData); - child.parentData.position = new Point(x, 0.0); + final _TabBarParentData childParentData = child.parentData; + childParentData.position = new Point(x, 0.0); x += tabWidth; - child = child.parentData.nextSibling; + child = childParentData.nextSibling; } } @@ -157,10 +156,10 @@ class _RenderTabBar extends RenderBox with RenderBox child = firstChild; while (child != null) { child.layout(tabConstraints, parentUsesSize: true); - assert(child.parentData is _TabBarParentData); - child.parentData.position = new Point(x, 0.0); + final _TabBarParentData childParentData = child.parentData; + childParentData.position = new Point(x, 0.0); x += child.size.width; - child = child.parentData.nextSibling; + child = childParentData.nextSibling; } return x; } @@ -180,7 +179,8 @@ class _RenderTabBar extends RenderBox with int childIndex = 0; while (child != null) { widths[childIndex++] = child.size.width; - child = child.parentData.nextSibling; + final _TabBarParentData childParentData = child.parentData; + child = childParentData.nextSibling; } assert(childIndex == widths.length); } @@ -221,24 +221,24 @@ class _RenderTabBar extends RenderBox with return; } - var size = new Size(selectedTab.size.width, _kTabIndicatorHeight); - var point = new Point( - selectedTab.parentData.position.x, + final Size size = new Size(selectedTab.size.width, _kTabIndicatorHeight); + final _TabBarParentData selectedTabParentData = selectedTab.parentData; + final Point point = new Point( + selectedTabParentData.position.x, _tabBarHeight - _kTabIndicatorHeight ); - Rect rect = (point + offset) & size; - canvas.drawRect(rect, new Paint()..color = indicatorColor); + canvas.drawRect((point + offset) & size, new Paint()..color = indicatorColor); } void paint(PaintingContext context, Offset offset) { int index = 0; RenderBox child = firstChild; while (child != null) { - assert(child.parentData is _TabBarParentData); - context.paintChild(child, child.parentData.position + offset); + final _TabBarParentData childParentData = child.parentData; + context.paintChild(child, childParentData.position + offset); if (index++ == selectedIndex) _paintIndicator(context.canvas, child, offset); - child = child.parentData.nextSibling; + child = childParentData.nextSibling; } } } @@ -426,7 +426,7 @@ class _TabBarState extends ScrollableState { assert(tabIndex >= 0 && tabIndex < _tabWidths.length); double tabLeft = 0.0; if (tabIndex > 0) - tabLeft = _tabWidths.take(tabIndex).reduce((sum, width) => sum + width); + tabLeft = _tabWidths.take(tabIndex).reduce((double sum, double width) => sum + width); double tabTop = 0.0; double tabBottom = _tabBarSize.height - _kTabIndicatorHeight; double tabRight = tabLeft + _tabWidths[tabIndex]; @@ -469,7 +469,7 @@ class _TabBarState extends ScrollableState { void _updateScrollBehavior() { scrollBehavior.updateExtents( containerExtent: config.scrollDirection == ScrollDirection.vertical ? _viewportSize.height : _viewportSize.width, - contentExtent: _tabWidths.reduce((sum, width) => sum + width) + contentExtent: _tabWidths.reduce((double sum, double width) => sum + width) ); } @@ -523,7 +523,7 @@ class _TabBarState extends ScrollableState { child: new DefaultTextStyle( style: textStyle, child: new BuilderTransition( - variables: [_indicatorRect], + variables: >[_indicatorRect], performance: _indicatorAnimation.view, builder: (BuildContext context) { return new _TabBarWrapper( @@ -591,9 +591,9 @@ class TabNavigator extends StatelessComponent { Widget build(BuildContext context) { assert(views != null && views.isNotEmpty); assert(selectedIndex >= 0 && selectedIndex < views.length); - return new Column([ + return new Column([ new TabBar( - labels: views.map((view) => view.label), + labels: views.map((TabNavigatorView view) => view.label), onChanged: onChanged, selectedIndex: selectedIndex, isScrollable: isScrollable diff --git a/packages/flutter/lib/src/material/tool_bar.dart b/packages/flutter/lib/src/material/tool_bar.dart index 5629b1d5fb..cdcbe9ccac 100644 --- a/packages/flutter/lib/src/material/tool_bar.dart +++ b/packages/flutter/lib/src/material/tool_bar.dart @@ -70,7 +70,7 @@ class ToolBar extends StatelessComponent { ), child: new DefaultTextStyle( style: sideStyle, - child: new Column([ + child: new Column([ new Container( child: new Row(children), height: kToolBarHeight diff --git a/packages/flutter/lib/src/painting/box_painter.dart b/packages/flutter/lib/src/painting/box_painter.dart index 959394f266..e018615599 100644 --- a/packages/flutter/lib/src/painting/box_painter.dart +++ b/packages/flutter/lib/src/painting/box_painter.dart @@ -101,15 +101,6 @@ class EdgeDims { ); } - bool operator ==(other) { - return identical(this, other) || - (other is EdgeDims && - top == other.top && - right == other.right && - bottom == other.bottom && - left == other.left); - } - /// Linearly interpolate between two EdgeDims /// /// If either is null, this function interpolates from [EdgeDims.zero]. @@ -131,6 +122,18 @@ class EdgeDims { /// An EdgeDims with zero offsets in each direction static const EdgeDims zero = const EdgeDims.TRBL(0.0, 0.0, 0.0, 0.0); + bool operator ==(dynamic other) { + if (identical(this, other)) + return true; + if (other is! EdgeDims) + return false; + final EdgeDims typedOther = other; + return top == typedOther.top && + right == typedOther.right && + bottom == typedOther.bottom && + left == typedOther.left; + } + int get hashCode { int value = 373; value = 37 * value + top.hashCode; @@ -139,6 +142,7 @@ class EdgeDims { value = 37 * value + right.hashCode; return value; } + String toString() => "EdgeDims($top, $right, $bottom, $left)"; } @@ -322,8 +326,7 @@ class LinearGradient extends Gradient { final ui.TileMode tileMode; ui.Shader createShader() { - return new ui.Gradient.linear([begin, end], this.colors, - this.stops, this.tileMode); + return new ui.Gradient.linear([begin, end], this.colors, this.stops, this.tileMode); } String toString() { @@ -612,7 +615,7 @@ class BoxDecoration { } String toString([String prefix = '']) { - List result = []; + List result = []; if (backgroundColor != null) result.add('${prefix}backgroundColor: $backgroundColor'); if (backgroundImage != null) @@ -622,13 +625,13 @@ class BoxDecoration { if (borderRadius != null) result.add('${prefix}borderRadius: $borderRadius'); if (boxShadow != null) - result.add('${prefix}boxShadow: ${boxShadow.map((shadow) => shadow.toString())}'); + result.add('${prefix}boxShadow: ${boxShadow.map((BoxShadow shadow) => shadow.toString())}'); if (gradient != null) result.add('${prefix}gradient: $gradient'); if (shape != Shape.rectangle) result.add('${prefix}shape: $shape'); if (result.isEmpty) - return '${prefix}'; + return '$prefix'; return result.join('\n'); } } diff --git a/packages/flutter/lib/src/painting/shadows.dart b/packages/flutter/lib/src/painting/shadows.dart index d0ad34638e..28cc7be7ac 100644 --- a/packages/flutter/lib/src/painting/shadows.dart +++ b/packages/flutter/lib/src/painting/shadows.dart @@ -6,23 +6,24 @@ import 'dart:ui' as ui; /// A helper class to build a [ui.DrawLooper] for drawing shadows class ShadowDrawLooperBuilder { - var builder_ = new ui.LayerDrawLooperBuilder(); + ui.LayerDrawLooperBuilder _builder = new ui.LayerDrawLooperBuilder(); /// Add a shadow with the given parameters void addShadow(ui.Offset offset, ui.Color color, double blur) { - builder_.addLayerOnTop( - new ui.DrawLooperLayerInfo() - ..setPaintBits(ui.PaintBits.all) - ..setOffset(offset) - ..setColorMode(ui.TransferMode.src), - new ui.Paint() - ..color = color - ..maskFilter = new ui.MaskFilter.blur(ui.BlurStyle.normal, blur)); + _builder.addLayerOnTop( + new ui.DrawLooperLayerInfo() + ..setPaintBits(ui.PaintBits.all) + ..setOffset(offset) + ..setColorMode(ui.TransferMode.src), + new ui.Paint() + ..color = color + ..maskFilter = new ui.MaskFilter.blur(ui.BlurStyle.normal, blur) + ); } /// Returns the draw looper built for the added shadows ui.DrawLooper build() { - builder_.addLayerOnTop(new ui.DrawLooperLayerInfo(), new ui.Paint()); - return builder_.build(); + _builder.addLayerOnTop(new ui.DrawLooperLayerInfo(), new ui.Paint()); + return _builder.build(); } } diff --git a/packages/flutter/lib/src/painting/text_painter.dart b/packages/flutter/lib/src/painting/text_painter.dart index 733a42b8b8..710a11f11d 100644 --- a/packages/flutter/lib/src/painting/text_painter.dart +++ b/packages/flutter/lib/src/painting/text_painter.dart @@ -38,10 +38,16 @@ class PlainTextSpan extends TextSpan { builder.addText(text); } - bool operator ==(other) => other is PlainTextSpan && text == other.text; + bool operator ==(dynamic other) { + if (other is! PlainTextSpan) + return false; + final PlainTextSpan typedOther = other; + return text == typedOther.text; + } + int get hashCode => text.hashCode; - String toString([String prefix = '']) => '${prefix}${runtimeType}: "${text}"'; + String toString([String prefix = '']) => '$prefix$runtimeType: "$text"'; } /// An immutable text span that applies a style to a list of children @@ -79,15 +85,17 @@ class StyledTextSpan extends TextSpan { style.applyToContainerCSSStyle(container.style); } - bool operator ==(other) { + bool operator ==(dynamic other) { if (identical(this, other)) return true; - if (other is! StyledTextSpan - || style != other.style - || children.length != other.children.length) + if (other is! StyledTextSpan) + return false; + final StyledTextSpan typedOther = other; + if (style != typedOther.style || + children.length != typedOther.children.length) return false; for (int i = 0; i < children.length; ++i) { - if (children[i] != other.children[i]) + if (children[i] != typedOther.children[i]) return false; } return true; @@ -102,28 +110,72 @@ class StyledTextSpan extends TextSpan { } String toString([String prefix = '']) { - List result = []; - result.add('${prefix}${runtimeType}:'); - var indent = '${prefix} '; + List result = []; + result.add('$prefix$runtimeType:'); + var indent = '$prefix '; result.add('${style.toString(indent)}'); - for (TextSpan child in children) { + for (TextSpan child in children) result.add(child.toString(indent)); - } return result.join('\n'); } } const bool _kEnableNewTextPainter = false; -/// An object that paints a [TextSpan] into a canvas -class TextPainter { +abstract class TextPainter { + factory TextPainter(TextSpan text) { if (_kEnableNewTextPainter) return new _NewTextPainter(text); - return new TextPainter._(text); + return new _OldTextPainter(text); } - TextPainter._(TextSpan text) { + /// The (potentially styled) text to paint + TextSpan get text; + void set text(TextSpan value); + + /// The minimum width at which to layout the text + double get minWidth; + void set minWidth(double value); + + /// The maximum width at which to layout the text + double get maxWidth; + void set maxWidth(double value); + + /// The minimum height at which to layout the text + double get minHeight; + void set minHeight(double value); + + /// The maximum height at which to layout the text + double get maxHeight; + void set maxHeight(double value); + + /// The width at which decreasing the width of the text would prevent it from + /// painting itself completely within its bounds + double get minContentWidth; + + /// The width at which increasing the width of the text no longer decreases + /// the height + double get maxContentWidth; + + /// The height required to paint the text completely within its bounds + double get height; + + /// The distance from the top of the text to the first baseline of the given + /// type + double computeDistanceToActualBaseline(TextBaseline baseline); + + /// Compute the visual position of the glyphs for painting the text + void layout(); + + /// Paint the text onto the given canvas at the given offset + void paint(ui.Canvas canvas, ui.Offset offset); + +} + +/// An object that paints a [TextSpan] into a canvas +class _OldTextPainter implements TextPainter { + _OldTextPainter(TextSpan text) { _layoutRoot.rootElement = _document.createElement('p'); assert(text != null); this.text = text; diff --git a/packages/flutter/lib/src/painting/text_style.dart b/packages/flutter/lib/src/painting/text_style.dart index 43ffa44967..dc840cef93 100644 --- a/packages/flutter/lib/src/painting/text_style.dart +++ b/packages/flutter/lib/src/painting/text_style.dart @@ -137,7 +137,7 @@ class TextStyle { TextDecoration.overline: 'overline', TextDecoration.lineThrough: 'lineThrough' }; - return decoration.map((d) => toCSS[d]).join(' '); + return decoration.map((TextDecoration d) => toCSS[d]).join(' '); } static String _decorationStyleToCSSString(TextDecorationStyle decorationStyle) { @@ -210,24 +210,26 @@ class TextStyle { }[textAlign]; } if (height != null) { - cssStyle['line-height'] = '${height}'; + cssStyle['line-height'] = '$height'; } } - bool operator ==(other) { + bool operator ==(dynamic other) { if (identical(this, other)) return true; - return other is TextStyle && - color == other.color && - fontFamily == other.fontFamily && - fontSize == other.fontSize && - fontWeight == other.fontWeight && - fontStyle == other.fontStyle && - textAlign == other.textAlign && - textBaseline == other.textBaseline && - decoration == other.decoration && - decorationColor == other.decorationColor && - decorationStyle == other.decorationStyle; + if (other is! TextStyle) + return false; + final TextStyle typedOther = other; + return color == typedOther.color && + fontFamily == typedOther.fontFamily && + fontSize == typedOther.fontSize && + fontWeight == typedOther.fontWeight && + fontStyle == typedOther.fontStyle && + textAlign == typedOther.textAlign && + textBaseline == typedOther.textBaseline && + decoration == typedOther.decoration && + decorationColor == typedOther.decorationColor && + decorationStyle == typedOther.decorationStyle; } int get hashCode { @@ -247,12 +249,12 @@ class TextStyle { } String toString([String prefix = '']) { - List result = []; + List result = []; if (color != null) result.add('${prefix}color: $color'); // TODO(hansmuller): escape the fontFamily string. if (fontFamily != null) - result.add('${prefix}fontFamily: "${fontFamily}"'); + result.add('${prefix}fontFamily: "$fontFamily"'); if (fontSize != null) result.add('${prefix}fontSize: $fontSize'); if (fontWeight != null) @@ -270,7 +272,7 @@ class TextStyle { if (decorationStyle != null) result.add('${prefix}decorationStyle: $decorationStyle'); if (result.isEmpty) - return '${prefix}'; + return '$prefix'; return result.join('\n'); } } diff --git a/packages/flutter/lib/src/rendering/auto_layout.dart b/packages/flutter/lib/src/rendering/auto_layout.dart index f394f558a3..4aca6f7dd0 100644 --- a/packages/flutter/lib/src/rendering/auto_layout.dart +++ b/packages/flutter/lib/src/rendering/auto_layout.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:cassowary/cassowary.dart' as al; +import 'package:cassowary/cassowary.dart' as al; // "auto layout" import 'box.dart'; import 'object.dart'; @@ -40,11 +40,12 @@ abstract class _AutoLayoutParamMixin { } void _setupEditVariablesInSolver(al.Solver solver, double priority) { - solver.addEditVariables([ + solver.addEditVariables([ _leftEdge.variable, _rightEdge.variable, _topEdge.variable, - _bottomEdge.variable], priority); + _bottomEdge.variable + ], priority); } void _applyEditsAtSize(al.Solver solver, Size size) { @@ -90,8 +91,7 @@ abstract class _AutoLayoutParamMixin { } } -class AutoLayoutParentData extends BoxParentData - with ContainerParentDataMixin, _AutoLayoutParamMixin { +class AutoLayoutParentData extends ContainerBoxParentDataMixin with _AutoLayoutParamMixin { AutoLayoutParentData(this._renderBox) { _setupLayoutParameters(this); @@ -103,8 +103,10 @@ class AutoLayoutParentData extends BoxParentData // This is called by the parent's layout function // to lay our box out. assert(_renderBox.parentData == this); - assert(_renderBox.parent is RenderAutoLayout); - assert((_renderBox.parent as RenderAutoLayout).debugDoingThisLayout); // TODO(ianh): Remove cast once the analyzer is cleverer + assert(() { + final RenderAutoLayout parent = _renderBox.parent; + assert(parent.debugDoingThisLayout); + }); BoxConstraints size = new BoxConstraints.tightFor( width: _rightEdge.value - _leftEdge.value, height: _bottomEdge.value - _topEdge.value @@ -114,7 +116,7 @@ class AutoLayoutParentData extends BoxParentData } List _constructImplicitConstraints() { - return [ + return [ _leftEdge >= al.cm(0.0), // The left edge must be positive. _rightEdge >= _leftEdge, // Width must be positive. ]; @@ -174,11 +176,15 @@ class RenderAutoLayout extends RenderBox void adoptChild(RenderObject child) { // Make sure to call super first to setup the parent data super.adoptChild(child); - child.parentData._setupImplicitConstraints(_solver); + final AutoLayoutParentData childParentData = child.parentData; + childParentData._setupImplicitConstraints(_solver); + assert(child.parentData == childParentData); } void dropChild(RenderObject child) { - child.parentData._removeImplicitConstraints(_solver); + final AutoLayoutParentData childParentData = child.parentData; + childParentData._removeImplicitConstraints(_solver); + assert(child.parentData == childParentData); super.dropChild(child); } diff --git a/packages/flutter/lib/src/rendering/block.dart b/packages/flutter/lib/src/rendering/block.dart index 1d3ba27751..18745490dc 100644 --- a/packages/flutter/lib/src/rendering/block.dart +++ b/packages/flutter/lib/src/rendering/block.dart @@ -10,7 +10,7 @@ import 'box.dart'; import 'object.dart'; /// Parent data for use with [RenderBlockBase] -class BlockParentData extends BoxParentData with ContainerParentDataMixin { } +class BlockParentData extends ContainerBoxParentDataMixin { } /// The direction in which the block should lay out enum BlockDirection { @@ -106,10 +106,11 @@ abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin RenderBox child = firstChild; while (child != null) { child.layout(innerConstraints, parentUsesSize: true); - assert(child.parentData is BlockParentData); - child.parentData.position = isVertical ? new Point(0.0, position) : new Point(position, 0.0); + final BlockParentData childParentData = child.parentData; + childParentData.position = isVertical ? new Point(0.0, position) : new Point(position, 0.0); position += isVertical ? child.size.height : child.size.width; - child = child.parentData.nextSibling; + assert(child.parentData == childParentData); + child = childParentData.nextSibling; } size = isVertical ? constraints.constrain(new Size(constraints.maxWidth, _mainAxisExtent)) : @@ -117,7 +118,7 @@ abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin assert(!size.isInfinite); } - String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}direction: ${direction}\n'; + String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}direction: $direction\n'; } /// A block layout with a concrete set of children @@ -136,8 +137,8 @@ class RenderBlock extends RenderBlockBase { RenderBox child = firstChild; while (child != null) { extent = math.max(extent, childSize(child, innerConstraints)); - assert(child.parentData is BlockParentData); - child = child.parentData.nextSibling; + final BlockParentData childParentData = child.parentData; + child = childParentData.nextSibling; } return extent; } @@ -156,24 +157,28 @@ class RenderBlock extends RenderBlockBase { return childExtent == child.getMaxIntrinsicWidth(innerConstraints); }); extent += childExtent; - assert(child.parentData is BlockParentData); - child = child.parentData.nextSibling; + final BlockParentData childParentData = child.parentData; + child = childParentData.nextSibling; } return math.max(extent, minExtent); } double getMinIntrinsicWidth(BoxConstraints constraints) { if (isVertical) { - return _getIntrinsicCrossAxis(constraints, - (c, innerConstraints) => c.getMinIntrinsicWidth(innerConstraints)); + return _getIntrinsicCrossAxis( + constraints, + (RenderBox child, BoxConstraints innerConstraints) => child.getMinIntrinsicWidth(innerConstraints) + ); } return _getIntrinsicMainAxis(constraints); } double getMaxIntrinsicWidth(BoxConstraints constraints) { if (isVertical) { - return _getIntrinsicCrossAxis(constraints, - (c, innerConstraints) => c.getMaxIntrinsicWidth(innerConstraints)); + return _getIntrinsicCrossAxis( + constraints, + (RenderBox child, BoxConstraints innerConstraints) => child.getMaxIntrinsicWidth(innerConstraints) + ); } return _getIntrinsicMainAxis(constraints); } @@ -181,15 +186,19 @@ class RenderBlock extends RenderBlockBase { double getMinIntrinsicHeight(BoxConstraints constraints) { if (isVertical) return _getIntrinsicMainAxis(constraints); - return _getIntrinsicCrossAxis(constraints, - (c, innerConstraints) => c.getMinIntrinsicWidth(innerConstraints)); + return _getIntrinsicCrossAxis( + constraints, + (RenderBox child, BoxConstraints innerConstraints) => child.getMinIntrinsicWidth(innerConstraints) + ); } double getMaxIntrinsicHeight(BoxConstraints constraints) { if (isVertical) return _getIntrinsicMainAxis(constraints); - return _getIntrinsicCrossAxis(constraints, - (c, innerConstraints) => c.getMaxIntrinsicWidth(innerConstraints)); + return _getIntrinsicCrossAxis( + constraints, + (RenderBox child, BoxConstraints innerConstraints) => child.getMaxIntrinsicWidth(innerConstraints) + ); } double computeDistanceToActualBaseline(TextBaseline baseline) { @@ -391,5 +400,5 @@ class RenderBlockViewport extends RenderBlockBase { defaultHitTestChildren(result, position: position + new Offset(-startOffset, 0.0)); } - String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}startOffset: ${startOffset}\n'; + String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}startOffset: $startOffset\n'; } diff --git a/packages/flutter/lib/src/rendering/box.dart b/packages/flutter/lib/src/rendering/box.dart index 288610e548..cfc9cd2cd5 100644 --- a/packages/flutter/lib/src/rendering/box.dart +++ b/packages/flutter/lib/src/rendering/box.dart @@ -233,15 +233,18 @@ class BoxConstraints extends Constraints { ); } - bool operator ==(other) { + bool operator ==(dynamic other) { if (identical(this, other)) return true; - return other is BoxConstraints && - minWidth == other.minWidth && - maxWidth == other.maxWidth && - minHeight == other.minHeight && - maxHeight == other.maxHeight; + if (other is! BoxConstraints) + return false; + final BoxConstraints typedOther = other; + return minWidth == typedOther.minWidth && + maxWidth == typedOther.maxWidth && + minHeight == typedOther.minHeight && + maxHeight == typedOther.maxHeight; } + int get hashCode { int value = 373; value = 37 * value + minWidth.hashCode; @@ -274,6 +277,10 @@ class BoxParentData extends ParentData { String toString() => 'position=$position'; } +/// Abstract ParentData subclass for RenderBox subclasses that want the +/// ContainerRenderObjectMixin. +abstract class ContainerBoxParentDataMixin extends BoxParentData with ContainerParentDataMixin { } + /// A render object in a 2D cartesian coordinate system /// /// The size of each box is expressed as a width and a height. Each box has its @@ -349,7 +356,7 @@ abstract class RenderBox extends RenderObject { assert(hasSize); assert(() { if (_size is _DebugSize) { - final _DebugSize _size = this._size; // TODO(ianh): Remove this once the analyzer is cleverer + final _DebugSize _size = this._size; assert(_size._owner == this); if (RenderObject.debugActiveLayout != null) { // we are always allowed to access our own size (for print debugging and asserts if nothing else) @@ -358,7 +365,7 @@ abstract class RenderBox extends RenderObject { assert(debugDoingThisResize || debugDoingThisLayout || (RenderObject.debugActiveLayout == parent && _size._canBeUsedByParent)); } - assert(_size == this._size); // TODO(ianh): Remove this once the analyzer is cleverer + assert(_size == this._size); } return true; }); @@ -406,8 +413,7 @@ abstract class RenderBox extends RenderObject { double getDistanceToBaseline(TextBaseline baseline, { bool onlyReal: false }) { assert(!needsLayout); assert(!_debugDoingBaseline); - final parent = this.parent; // TODO(ianh): Remove this once the analyzer is cleverer - assert(parent is RenderObject); + final RenderObject parent = this.parent; assert(() { if (RenderObject.debugDoingLayout) return (RenderObject.debugActiveLayout == parent) && parent.debugDoingThisLayout; @@ -419,7 +425,7 @@ abstract class RenderBox extends RenderObject { assert(_debugSetDoingBaseline(true)); double result = getDistanceToActualBaseline(baseline); assert(_debugSetDoingBaseline(false)); - assert(parent == this.parent); // TODO(ianh): Remove this once the analyzer is cleverer + assert(parent == this.parent); if (result == null && !onlyReal) return size.height; return result; @@ -475,10 +481,9 @@ abstract class RenderBox extends RenderObject { if (_cachedBaselines != null && _cachedBaselines.isNotEmpty) { // if we have cached data, then someone must have used our data assert(_ancestorUsesBaseline); - final parent = this.parent; // TODO(ianh): Remove this once the analyzer is cleverer - assert(parent is RenderObject); + final RenderObject parent = this.parent; parent.markNeedsLayout(); - assert(parent == this.parent); // TODO(ianh): Remove this once the analyzer is cleverer + assert(parent == this.parent); // Now that they're dirty, we can forget that they used the // baseline. If they use it again, then we'll set the bit // again, and if we get dirty again, we'll notify them again. @@ -628,7 +633,7 @@ abstract class RenderBox extends RenderObject { } } - String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}size: ${size}\n'; + String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}size: $size\n'; } /// A mixin that provides useful default behaviors for boxes with children @@ -637,7 +642,7 @@ abstract class RenderBox extends RenderObject { /// By convention, this class doesn't override any members of the superclass. /// Instead, it provides helpful functions that subclasses can call as /// appropriate. -abstract class RenderBoxContainerDefaultsMixin> implements ContainerRenderObjectMixin { +abstract class RenderBoxContainerDefaultsMixin> implements ContainerRenderObjectMixin { /// Returns the baseline of the first child with a baseline /// @@ -647,11 +652,11 @@ abstract class RenderBoxContainerDefaultsMixin { +class FlexParentData extends ContainerBoxParentDataMixin { /// The flex factor to use for this child /// /// If null, the child is inflexible and determines its own size. If non-null, @@ -174,8 +174,8 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin c.getMinIntrinsicWidth(innerConstraints) + childSize: (RenderBox child, BoxConstraints innerConstraints) => child.getMinIntrinsicWidth(innerConstraints) ); } @@ -291,7 +291,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin c.getMaxIntrinsicWidth(innerConstraints) + childSize: (RenderBox child, BoxConstraints innerConstraints) => child.getMaxIntrinsicWidth(innerConstraints) ); } @@ -299,7 +299,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin c.getMinIntrinsicHeight(innerConstraints) + childSize: (RenderBox child, BoxConstraints innerConstraints) => child.getMinIntrinsicHeight(innerConstraints) ); } @@ -307,7 +307,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin c.getMaxIntrinsicHeight(innerConstraints)); + childSize: (RenderBox child, BoxConstraints innerConstraints) => child.getMaxIntrinsicHeight(innerConstraints)); } double computeDistanceToActualBaseline(TextBaseline baseline) { @@ -317,8 +317,8 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin 0) { @@ -350,7 +350,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin '${super.debugDescribeSettings(prefix)}${prefix}direction: ${_direction}\n${prefix}justifyContent: ${_justifyContent}\n${prefix}alignItems: ${_alignItems}\n${prefix}textBaseline: ${_textBaseline}\n'; + String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}direction: $_direction\n${prefix}justifyContent: $_justifyContent\n${prefix}alignItems: $_alignItems\n${prefix}textBaseline: $_textBaseline\n'; } diff --git a/packages/flutter/lib/src/rendering/grid.dart b/packages/flutter/lib/src/rendering/grid.dart index fe7cc07747..05c69cc469 100644 --- a/packages/flutter/lib/src/rendering/grid.dart +++ b/packages/flutter/lib/src/rendering/grid.dart @@ -42,7 +42,7 @@ class _GridMetrics { } /// Parent data for use with [RenderGrid] -class GridParentData extends BoxParentData with ContainerParentDataMixin {} +class GridParentData extends ContainerBoxParentDataMixin {} /// Implements the grid layout algorithm /// @@ -120,14 +120,17 @@ class RenderGrid extends RenderBox with ContainerRenderObjectMixin= metrics.childrenPerRow) { row += 1; column = 0; } - child = child.parentData.nextSibling; + + assert(child.parentData == childParentData); + child = childParentData.nextSibling; } } diff --git a/packages/flutter/lib/src/rendering/image.dart b/packages/flutter/lib/src/rendering/image.dart index e5e7356a83..ce6800c807 100644 --- a/packages/flutter/lib/src/rendering/image.dart +++ b/packages/flutter/lib/src/rendering/image.dart @@ -174,5 +174,5 @@ class RenderImage extends RenderBox { ); } - String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}width: ${width}\n${prefix}height: ${height}\n'; + String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}width: $width\n${prefix}height: $height\n'; } diff --git a/packages/flutter/lib/src/rendering/object.dart b/packages/flutter/lib/src/rendering/object.dart index f3b1e30d98..7b9c0a1b3d 100644 --- a/packages/flutter/lib/src/rendering/object.dart +++ b/packages/flutter/lib/src/rendering/object.dart @@ -445,7 +445,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { /// used between the parent and child. For example, in box layout, the /// parent data is completely opaque but in sector layout the child is /// permitted to read some fields of the parent data. - dynamic parentData; // TODO(ianh): change the type of this back to ParentData once the analyzer is cleverer + ParentData parentData; /// Override to setup parent data correctly for your children /// @@ -493,13 +493,13 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { dynamic debugExceptionContext = ''; void _debugReportException(String method, dynamic exception, StackTrace stack) { print('-- EXCEPTION --'); - print('The following exception was raised during ${method}():'); + print('The following exception was raised during $method():'); print('$exception'); print('Stack trace:'); print('$stack'); print('The following RenderObject was being processed when the exception was fired:\n${this}'); if (debugExceptionContext != '') - 'That RenderObject had the following exception context:\n${debugExceptionContext}'.split('\n').forEach(print); + 'That RenderObject had the following exception context:\n$debugExceptionContext'.split('\n').forEach(print); if (debugRenderingExceptionHandler != null) debugRenderingExceptionHandler(this, method, exception, stack); } @@ -577,14 +577,13 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { _needsLayout = true; assert(_relayoutSubtreeRoot != null); if (_relayoutSubtreeRoot != this) { - final parent = this.parent; // TODO(ianh): Remove this once the analyzer is cleverer - assert(parent is RenderObject); + final RenderObject parent = this.parent; if (!_doingThisLayoutWithCallback) { parent.markNeedsLayout(); } else { assert(parent._debugDoingThisLayout); } - assert(parent == this.parent); // TODO(ianh): Remove this once the analyzer is cleverer + assert(parent == this.parent); } else { _nodesNeedingLayout.add(this); scheduler.ensureVisualUpdate(); @@ -635,7 +634,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { while(_nodesNeedingLayout.isNotEmpty) { List dirtyNodes = _nodesNeedingLayout; _nodesNeedingLayout = new List(); - dirtyNodes..sort((a, b) => a.depth - b.depth)..forEach((node) { + dirtyNodes..sort((RenderObject a, RenderObject b) => a.depth - b.depth)..forEach((RenderObject node) { if (node._needsLayout && node.attached) node._layoutWithoutResize(); }); @@ -696,13 +695,13 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { /// implemented here) to return early if the child does not need to do any /// work to update its layout information. void layout(Constraints constraints, { bool parentUsesSize: false }) { - final parent = this.parent; // TODO(ianh): Remove this once the analyzer is cleverer + final RenderObject parent = this.parent; RenderObject relayoutSubtreeRoot; if (!parentUsesSize || sizedByParent || constraints.isTight || parent is! RenderObject) relayoutSubtreeRoot = this; else relayoutSubtreeRoot = parent._relayoutSubtreeRoot; - assert(parent == this.parent); // TODO(ianh): Remove this once the analyzer is cleverer + assert(parent == this.parent); if (!needsLayout && constraints == _constraints && relayoutSubtreeRoot == _relayoutSubtreeRoot) return; _constraints = constraints; @@ -745,7 +744,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { }); _needsLayout = false; markNeedsPaint(); - assert(parent == this.parent); // TODO(ianh): Remove this once the analyzer is cleverer + assert(parent == this.parent); } /// Whether the constraints are the only input to the sizing algorithm (in @@ -866,9 +865,10 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { if (_needsCompositingBitsUpdate) return; _needsCompositingBitsUpdate = true; - final AbstractNode parent = this.parent; // TODO(ianh): remove the once the analyzer is cleverer + final AbstractNode parent = this.parent; if (parent is RenderObject) parent._markNeedsCompositingBitsUpdate(); + assert(parent == this.parent); } bool _needsCompositing = false; /// Whether we or one of our descendants has a compositing layer @@ -930,7 +930,9 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { // care of updating the layer we're in and when they do that // we'll get our paint() method called. assert(_layer == null); - (parent as RenderObject).markNeedsPaint(); // TODO(ianh): remove the cast once the analyzer is cleverer + final RenderObject parent = this.parent; + parent.markNeedsPaint(); + assert(parent == this.parent); } else { // If we're the root of the render tree (probably a RenderView), // then we have to paint ourselves, since nobody else can paint @@ -955,7 +957,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { List dirtyNodes = _nodesNeedingPaint; _nodesNeedingPaint = new List(); // Sort the dirty nodes in reverse order (deepest first). - for (RenderObject node in dirtyNodes..sort((a, b) => b.depth - a.depth)) { + for (RenderObject node in dirtyNodes..sort((RenderObject a, RenderObject b) => b.depth - a.depth)) { assert(node._needsPaint); if (node.attached) node._repaint(); @@ -1095,7 +1097,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { /// Returns a human understandable name String toString() { - String header = '${runtimeType}'; + String header = '$runtimeType'; if (_relayoutSubtreeRoot != null && _relayoutSubtreeRoot != this) { int count = 1; RenderObject target = parent; @@ -1127,7 +1129,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget { /// Returns a string describing the current node's fields, one field per line, /// with each line prefixed by the prefix argument. Subclasses should override /// this to have their information included in toStringDeep(). - String debugDescribeSettings(String prefix) => '${prefix}parentData: ${parentData}\n${prefix}constraints: ${constraints}\n'; + String debugDescribeSettings(String prefix) => '${prefix}parentData: $parentData\n${prefix}constraints: $constraints\n'; /// Returns a string describing the current node's descendants. Each line of /// the subtree in the output should be indented by the prefix argument. @@ -1190,16 +1192,16 @@ abstract class ContainerParentDataMixin implemen void detach() { super.detach(); if (previousSibling != null) { - assert(previousSibling.parentData is ContainerParentDataMixin); + final ContainerParentDataMixin previousSiblingParentData = previousSibling.parentData; assert(previousSibling != this); - assert(previousSibling.parentData.nextSibling == this); - previousSibling.parentData.nextSibling = nextSibling; + assert(previousSiblingParentData.nextSibling == this); + previousSiblingParentData.nextSibling = nextSibling; } if (nextSibling != null) { - assert(nextSibling.parentData is ContainerParentDataMixin); + final ContainerParentDataMixin nextSiblingParentData = nextSibling.parentData; assert(nextSibling != this); - assert(nextSibling.parentData.previousSibling == this); - nextSibling.parentData.previousSibling = previousSibling; + assert(nextSiblingParentData.previousSibling == this); + nextSiblingParentData.previousSibling = previousSibling; } previousSibling = null; nextSibling = null; @@ -1213,20 +1215,20 @@ abstract class ContainerParentDataMixin implemen abstract class ContainerRenderObjectMixin> implements RenderObject { bool _debugUltimatePreviousSiblingOf(ChildType child, { ChildType equals }) { - assert(child.parentData is ParentDataType); - while (child.parentData.previousSibling != null) { - assert(child.parentData.previousSibling != child); - child = child.parentData.previousSibling; - assert(child.parentData is ParentDataType); + ParentDataType childParentData = child.parentData; + while (childParentData.previousSibling != null) { + assert(childParentData.previousSibling != child); + child = childParentData.previousSibling; + childParentData = child.parentData; } return child == equals; } bool _debugUltimateNextSiblingOf(ChildType child, { ChildType equals }) { - assert(child.parentData is ParentDataType); - while (child.parentData.nextSibling != null) { - assert(child.parentData.nextSibling != child); - child = child.parentData.nextSibling; - assert(child.parentData is ParentDataType); + ParentDataType childParentData = child.parentData; + while (childParentData.nextSibling != null) { + assert(childParentData.nextSibling != child); + child = childParentData.nextSibling; + childParentData = child.parentData; } return child == equals; } @@ -1238,17 +1240,17 @@ abstract class ContainerRenderObjectMixin 0); if (before == null) { // append at the end (_lastChild) - child.parentData.previousSibling = _lastChild; + childParentData.previousSibling = _lastChild; if (_lastChild != null) { - assert(_lastChild.parentData is ParentDataType); - _lastChild.parentData.nextSibling = child; + final ParentDataType _lastChildParentData = _lastChild.parentData; + _lastChildParentData.nextSibling = child; } _lastChild = child; if (_firstChild == null) @@ -1258,24 +1260,24 @@ abstract class ContainerRenderObjectMixin= 0); - if (child.parentData.previousSibling == null) { + if (childParentData.previousSibling == null) { assert(_firstChild == child); - _firstChild = child.parentData.nextSibling; + _firstChild = childParentData.nextSibling; } else { - assert(child.parentData.previousSibling.parentData is ParentDataType); - child.parentData.previousSibling.parentData.nextSibling = child.parentData.nextSibling; + final ParentDataType childPreviousSiblingParentData = childParentData.previousSibling.parentData; + childPreviousSiblingParentData.nextSibling = childParentData.nextSibling; } - if (child.parentData.nextSibling == null) { + if (childParentData.nextSibling == null) { assert(_lastChild == child); - _lastChild = child.parentData.previousSibling; + _lastChild = childParentData.previousSibling; } else { - assert(child.parentData.nextSibling.parentData is ParentDataType); - child.parentData.nextSibling.parentData.previousSibling = child.parentData.previousSibling; + final ParentDataType childNextSiblingParentData = childParentData.nextSibling.parentData; + childNextSiblingParentData.previousSibling = childParentData.previousSibling; } - child.parentData.previousSibling = null; - child.parentData.nextSibling = null; + childParentData.previousSibling = null; + childParentData.nextSibling = null; _childCount -= 1; } @@ -1337,10 +1339,10 @@ abstract class ContainerRenderObjectMixin '${super.debugDescribeSettings(prefix)}${prefix}additionalConstraints: ${additionalConstraints}\n'; + String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}additionalConstraints: $additionalConstraints\n'; } /// A render object that, for both width and height, imposes a tight constraint @@ -376,7 +376,7 @@ class RenderAspectRatio extends RenderProxyBox { RenderAspectRatio({ RenderBox child, double aspectRatio - }) : super(child), _aspectRatio = aspectRatio { + }) : _aspectRatio = aspectRatio, super(child) { assert(_aspectRatio != null); } @@ -419,7 +419,7 @@ class RenderAspectRatio extends RenderProxyBox { child.layout(new BoxConstraints.tight(size)); } - String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}aspectRatio: ${aspectRatio}\n'; + String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}aspectRatio: $aspectRatio\n'; } /// Sizes its child to the child's intrinsic width @@ -514,7 +514,7 @@ class RenderIntrinsicWidth extends RenderProxyBox { } } - String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}stepWidth: ${stepWidth}\n${prefix}stepHeight: ${stepHeight}\n'; + String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}stepWidth: $stepWidth\n${prefix}stepHeight: $stepHeight\n'; } @@ -628,8 +628,7 @@ class RenderOpacity extends RenderProxyBox { /// child into an intermediate buffer. class RenderColorFilter extends RenderProxyBox { RenderColorFilter({ RenderBox child, Color color, ui.TransferMode transferMode }) - : _color = color, _transferMode = transferMode, super(child) { - } + : _color = color, _transferMode = transferMode, super(child); /// The color to use as input to the color filter Color get color => _color; @@ -661,8 +660,7 @@ class RenderColorFilter extends RenderProxyBox { class RenderShaderMask extends RenderProxyBox { RenderShaderMask({ RenderBox child, ShaderCallback shaderCallback, ui.TransferMode transferMode }) - : _shaderCallback = shaderCallback, _transferMode = transferMode, super(child) { - } + : _shaderCallback = shaderCallback, _transferMode = transferMode, super(child); ShaderCallback get shaderCallback => _shaderCallback; ShaderCallback _shaderCallback; @@ -969,9 +967,9 @@ class RenderTransform extends RenderProxyBox { } String debugDescribeSettings(String prefix) { - List result = _transform.toString().split('\n').map((s) => '$prefix $s\n').toList(); + List result = _transform.toString().split('\n').map((String s) => '$prefix $s\n').toList(); result.removeLast(); - return '${super.debugDescribeSettings(prefix)}${prefix}transform matrix:\n${result.join()}\n${prefix}origin: ${origin}\n'; + return '${super.debugDescribeSettings(prefix)}${prefix}transform matrix:\n${result.join()}\n${prefix}origin: $origin\n'; } } diff --git a/packages/flutter/lib/src/rendering/shifted_box.dart b/packages/flutter/lib/src/rendering/shifted_box.dart index 6cab77827b..89eacfb5ce 100644 --- a/packages/flutter/lib/src/rendering/shifted_box.dart +++ b/packages/flutter/lib/src/rendering/shifted_box.dart @@ -44,9 +44,9 @@ abstract class RenderShiftedBox extends RenderBox with RenderObjectWithChildMixi if (child != null) { assert(!needsLayout); result = child.getDistanceToActualBaseline(baseline); - assert(child.parentData is BoxParentData); + final BoxParentData childParentData = child.parentData; if (result != null) - result += child.parentData.position.y; + result += childParentData.position.y; } else { result = super.computeDistanceToActualBaseline(baseline); } @@ -54,15 +54,17 @@ abstract class RenderShiftedBox extends RenderBox with RenderObjectWithChildMixi } void paint(PaintingContext context, Offset offset) { - if (child != null) - context.paintChild(child, child.parentData.position + offset); + if (child != null) { + final BoxParentData childParentData = child.parentData; + context.paintChild(child, childParentData.position + offset); + } } void hitTestChildren(HitTestResult result, { Point position }) { if (child != null) { - assert(child.parentData is BoxParentData); - child.hitTest(result, position: new Point(position.x - child.parentData.position.x, - position.y - child.parentData.position.y)); + final BoxParentData childParentData = child.parentData; + child.hitTest(result, position: new Point(position.x - childParentData.position.x, + position.y - childParentData.position.y)); } } @@ -125,15 +127,15 @@ class RenderPadding extends RenderShiftedBox { } BoxConstraints innerConstraints = constraints.deflate(padding); child.layout(innerConstraints, parentUsesSize: true); - assert(child.parentData is BoxParentData); - child.parentData.position = new Point(padding.left, padding.top); + final BoxParentData childParentData = child.parentData; + childParentData.position = new Point(padding.left, padding.top); size = constraints.constrain(new Size( padding.left + child.size.width + padding.right, padding.top + child.size.height + padding.bottom )); } - String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}padding: ${padding}\n'; + String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}padding: $padding\n'; } enum ShrinkWrap { @@ -204,16 +206,16 @@ class RenderPositionedBox extends RenderShiftedBox { child.layout(constraints.loosen(), parentUsesSize: true); size = constraints.constrain(new Size(_shinkWrapWidth ? child.size.width : double.INFINITY, _shinkWrapHeight ? child.size.height : double.INFINITY)); - assert(child.parentData is BoxParentData); Offset delta = size - child.size; - child.parentData.position = (delta.scale(horizontal, vertical)).toPoint(); + final BoxParentData childParentData = child.parentData; + childParentData.position = (delta.scale(horizontal, vertical)).toPoint(); } else { size = constraints.constrain(new Size(_shinkWrapWidth ? 0.0 : double.INFINITY, _shinkWrapHeight ? 0.0 : double.INFINITY)); } } - String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}horizontal: ${horizontal}\n${prefix}vertical: ${vertical}\n'; + String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}horizontal: $horizontal\n${prefix}vertical: $vertical\n'; } class RenderBaseline extends RenderShiftedBox { @@ -253,13 +255,13 @@ class RenderBaseline extends RenderShiftedBox { if (child != null) { child.layout(constraints.loosen(), parentUsesSize: true); size = constraints.constrain(child.size); - assert(child.parentData is BoxParentData); double delta = baseline - child.getDistanceToBaseline(baselineType); - child.parentData.position = new Point(0.0, delta); + final BoxParentData childParentData = child.parentData; + childParentData.position = new Point(0.0, delta); } else { performResize(); } } - String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}baseline: ${baseline}\nbaselineType: ${baselineType}'; + String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}baseline: $baseline\nbaselineType: $baselineType'; } diff --git a/packages/flutter/lib/src/rendering/stack.dart b/packages/flutter/lib/src/rendering/stack.dart index 7d075f88b9..2382411e69 100644 --- a/packages/flutter/lib/src/rendering/stack.dart +++ b/packages/flutter/lib/src/rendering/stack.dart @@ -8,7 +8,7 @@ import 'box.dart'; import 'object.dart'; /// Parent data for use with [RenderStack] -class StackParentData extends BoxParentData with ContainerParentDataMixin { +class StackParentData extends ContainerBoxParentDataMixin { /// The offset of the child's top edge from the top of the stack double top; @@ -84,10 +84,11 @@ abstract class RenderStackBase extends RenderBox double width = constraints.minWidth; RenderBox child = firstChild; while (child != null) { - assert(child.parentData is StackParentData); - if (!child.parentData.isPositioned) + final StackParentData childParentData = child.parentData; + if (!childParentData.isPositioned) width = math.max(width, child.getMinIntrinsicWidth(constraints)); - child = child.parentData.nextSibling; + assert(child.parentData == childParentData); + child = childParentData.nextSibling; } assert(width == constraints.constrainWidth(width)); return width; @@ -98,12 +99,13 @@ abstract class RenderStackBase extends RenderBox double width = constraints.minWidth; RenderBox child = firstChild; while (child != null) { - assert(child.parentData is StackParentData); - if (!child.parentData.isPositioned) { + final StackParentData childParentData = child.parentData; + if (!childParentData.isPositioned) { hasNonPositionedChildren = true; width = math.max(width, child.getMaxIntrinsicWidth(constraints)); } - child = child.parentData.nextSibling; + assert(child.parentData == childParentData); + child = childParentData.nextSibling; } if (!hasNonPositionedChildren) return constraints.constrainWidth(); @@ -115,10 +117,11 @@ abstract class RenderStackBase extends RenderBox double height = constraints.minHeight; RenderBox child = firstChild; while (child != null) { - assert(child.parentData is StackParentData); - if (!child.parentData.isPositioned) + final StackParentData childParentData = child.parentData; + if (!childParentData.isPositioned) height = math.max(height, child.getMinIntrinsicHeight(constraints)); - child = child.parentData.nextSibling; + assert(child.parentData == childParentData); + child = childParentData.nextSibling; } assert(height == constraints.constrainHeight(height)); return height; @@ -129,12 +132,13 @@ abstract class RenderStackBase extends RenderBox double height = constraints.minHeight; RenderBox child = firstChild; while (child != null) { - assert(child.parentData is StackParentData); - if (!child.parentData.isPositioned) { + final StackParentData childParentData = child.parentData; + if (!childParentData.isPositioned) { hasNonPositionedChildren = true; height = math.max(height, child.getMaxIntrinsicHeight(constraints)); } - child = child.parentData.nextSibling; + assert(child.parentData == childParentData); + child = childParentData.nextSibling; } if (!hasNonPositionedChildren) return constraints.constrainHeight(); @@ -155,21 +159,20 @@ abstract class RenderStackBase extends RenderBox RenderBox child = firstChild; while (child != null) { - assert(child.parentData is StackParentData); - final StackParentData parentData = child.parentData; + final StackParentData childParentData = child.parentData; - if (!parentData.isPositioned) { + if (!childParentData.isPositioned) { hasNonPositionedChildren = true; child.layout(constraints, parentUsesSize: true); - parentData.position = Point.origin; + childParentData.position = Point.origin; final Size childSize = child.size; width = math.max(width, childSize.width); height = math.max(height, childSize.height); } - child = parentData.nextSibling; + child = childParentData.nextSibling; } if (hasNonPositionedChildren) { @@ -184,46 +187,46 @@ abstract class RenderStackBase extends RenderBox child = firstChild; while (child != null) { - assert(child.parentData is StackParentData); - final StackParentData childData = child.parentData; + final StackParentData childParentData = child.parentData; - if (!childData.isPositioned) { + if (!childParentData.isPositioned) { double x = (size.width - child.size.width) * horizontalAlignment; double y = (size.height - child.size.height) * verticalAlignment; - childData.position = new Point(x, y); + childParentData.position = new Point(x, y); } else { BoxConstraints childConstraints = const BoxConstraints(); - if (childData.left != null && childData.right != null) - childConstraints = childConstraints.tightenWidth(size.width - childData.right - childData.left); + if (childParentData.left != null && childParentData.right != null) + childConstraints = childConstraints.tightenWidth(size.width - childParentData.right - childParentData.left); - if (childData.top != null && childData.bottom != null) - childConstraints = childConstraints.tightenHeight(size.height - childData.bottom - childData.top); + if (childParentData.top != null && childParentData.bottom != null) + childConstraints = childConstraints.tightenHeight(size.height - childParentData.bottom - childParentData.top); child.layout(childConstraints, parentUsesSize: true); double x = 0.0; - if (childData.left != null) - x = childData.left; - else if (childData.right != null) - x = size.width - childData.right - child.size.width; + if (childParentData.left != null) + x = childParentData.left; + else if (childParentData.right != null) + x = size.width - childParentData.right - child.size.width; if (x < 0.0 || x + child.size.width > size.width) _hasVisualOverflow = true; double y = 0.0; - if (childData.top != null) - y = childData.top; - else if (childData.bottom != null) - y = size.height - childData.bottom - child.size.height; + if (childParentData.top != null) + y = childParentData.top; + else if (childParentData.bottom != null) + y = size.height - childParentData.bottom - child.size.height; if (y < 0.0 || y + child.size.height > size.height) _hasVisualOverflow = true; - childData.position = new Point(x, y); + childParentData.position = new Point(x, y); } - child = childData.nextSibling; + assert(child.parentData == childParentData); + child = childParentData.nextSibling; } } @@ -320,8 +323,8 @@ class RenderIndexedStack extends RenderStackBase { RenderBox child = firstChild; int i = 0; while (child != null && i < index) { - assert(child.parentData is StackParentData); - child = child.parentData.nextSibling; + final StackParentData childParentData = child.parentData; + child = childParentData.nextSibling; i += 1; } assert(i == index); @@ -334,8 +337,9 @@ class RenderIndexedStack extends RenderStackBase { return; assert(position != null); RenderBox child = _childAtIndex(); - Point transformed = new Point(position.x - child.parentData.position.x, - position.y - child.parentData.position.y); + final StackParentData childParentData = child.parentData; + Point transformed = new Point(position.x - childParentData.position.x, + position.y - childParentData.position.y); child.hitTest(result, position: transformed); } @@ -343,6 +347,7 @@ class RenderIndexedStack extends RenderStackBase { if (firstChild == null) return; RenderBox child = _childAtIndex(); - context.paintChild(child, child.parentData.position + offset); + final StackParentData childParentData = child.parentData; + context.paintChild(child, childParentData.position + offset); } } diff --git a/packages/flutter/lib/src/rendering/viewport.dart b/packages/flutter/lib/src/rendering/viewport.dart index eccce14a54..be961ea7fb 100644 --- a/packages/flutter/lib/src/rendering/viewport.dart +++ b/packages/flutter/lib/src/rendering/viewport.dart @@ -128,8 +128,8 @@ class RenderViewport extends RenderBox with RenderObjectWithChildMixin fetchUrl(String relativeUrl) async { UrlRequest request = new UrlRequest() ..url = url ..autoFollowRedirects = true; - return fetch(request); + return await fetch(request); } Future fetchBody(String relativeUrl) async { diff --git a/packages/flutter/lib/src/services/image_cache.dart b/packages/flutter/lib/src/services/image_cache.dart index f7076c82c8..8826477eab 100644 --- a/packages/flutter/lib/src/services/image_cache.dart +++ b/packages/flutter/lib/src/services/image_cache.dart @@ -3,7 +3,6 @@ // found in the LICENSE file. import 'dart:async'; -import 'dart:collection'; import 'dart:ui' as ui; import 'package:mojo/mojo/url_response.mojom.dart'; @@ -15,7 +14,7 @@ import 'image_resource.dart'; Future _fetchImage(String url) async { UrlResponse response = await fetchUrl(url); if (response.statusCode >= 400) { - print("Failed (${response.statusCode}) to load image ${url}"); + print("Failed (${response.statusCode}) to load image $url"); return null; } return await decodeImageFromDataPipe(response.body); @@ -24,7 +23,7 @@ Future _fetchImage(String url) async { class _ImageCache { _ImageCache._(); - final HashMap _cache = new Map(); + final Map _cache = new Map(); ImageResource load(String url) { return _cache.putIfAbsent(url, () { diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index 23f3576025..f4f3d1c4c0 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -770,7 +770,7 @@ class DefaultTextStyle extends InheritedWidget { } class Text extends StatelessComponent { - Text(this.data, { Key key, TextStyle this.style }) : super(key: key) { + Text(this.data, { Key key, this.style }) : super(key: key) { assert(data != null); } @@ -790,7 +790,7 @@ class Text extends StatelessComponent { combinedStyle = style; } if (combinedStyle != null) - text = new StyledTextSpan(combinedStyle, [text]); + text = new StyledTextSpan(combinedStyle, [text]); return new Paragraph(text: text); } diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index c2dc68b9f3..8698c69d12 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -11,22 +11,22 @@ import 'package:flutter/rendering.dart'; import 'basic.dart'; import 'framework.dart'; -const _kCursorBlinkPeriod = 500; // milliseconds +const _kCursorBlinkHalfPeriod = 500; // milliseconds typedef void StringUpdated(); class TextRange { + const TextRange({ this.start, this.end }); + const TextRange.collapsed(int position) + : start = position, + end = position; + const TextRange.empty() + : start = -1, + end = -1; + final int start; final int end; - TextRange({this.start, this.end}); - TextRange.collapsed(int position) - : start = position, - end = position; - const TextRange.empty() - : start = -1, - end = -1; - bool get isValid => start >= 0 && end >= 0; bool get isCollapsed => start == end; } @@ -155,12 +155,14 @@ class EditableTextState extends State { Timer _cursorTimer; bool _showCursor = false; - /// Whether the blinking cursor is visible (exposed for testing). - bool get test_showCursor => _showCursor; + /// Whether the blinking cursor is actually visible at this precise moment + /// (it's hidden half the time, since it blinks). + bool get cursorCurrentlyVisible => _showCursor; - /// The cursor blink interval (exposed for testing). - Duration get test_cursorBlinkPeriod => - new Duration(milliseconds: _kCursorBlinkPeriod); + /// The cursor blink interval (the amount of time the cursor is in the "on" + /// state or the "off" state). A complete cursor blink period is twice this + /// value (half on, half off). + Duration get cursorBlinkInterval => new Duration(milliseconds: _kCursorBlinkHalfPeriod); void _cursorTick(Timer timer) { setState(() { @@ -171,7 +173,9 @@ class EditableTextState extends State { void _startCursorTimer() { _showCursor = true; _cursorTimer = new Timer.periodic( - new Duration(milliseconds: _kCursorBlinkPeriod), _cursorTick); + new Duration(milliseconds: _kCursorBlinkHalfPeriod), + _cursorTick + ); } void dispose() { @@ -254,16 +258,16 @@ class _EditableTextWidget extends LeafRenderObjectWidget { const TextStyle(decoration: underline) ); - return new StyledTextSpan(style, [ + return new StyledTextSpan(style, [ new PlainTextSpan(value.textBefore(value.composing)), - new StyledTextSpan(composingStyle, [ + new StyledTextSpan(composingStyle, [ new PlainTextSpan(value.textInside(value.composing)) ]), new PlainTextSpan(value.textAfter(value.composing)) ]); } - return new StyledTextSpan(style, [ + return new StyledTextSpan(style, [ new PlainTextSpan(value.text) ]); } diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 6df59d33c6..5ff36a3ab8 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -30,9 +30,14 @@ abstract class Key { class ValueKey extends Key { const ValueKey(this.value) : super.constructor(); final T value; - String toString() => '[\'${value}\']'; - bool operator==(other) => other is ValueKey && other.value == value; + bool operator ==(dynamic other) { + if (other is! ValueKey) + return false; + final ValueKey typedOther = other; + return value == typedOther.value; + } int get hashCode => value.hashCode; + String toString() => '[\'$value\']'; } /// A kind of [Key] that takes its identity from the object used as its value. @@ -42,9 +47,14 @@ class ValueKey extends Key { class ObjectKey extends Key { const ObjectKey(this.value) : super.constructor(); final Object value; - String toString() => '[${value.runtimeType}(${value.hashCode})]'; - bool operator==(other) => other is ObjectKey && identical(other.value, value); + bool operator ==(dynamic other) { + if (other is! ObjectKey) + return false; + final ObjectKey typedOther = other; + return identical(value, typedOther.value); + } int get hashCode => identityHashCode(value); + String toString() => '[${value.runtimeType}(${value.hashCode})]'; } typedef void GlobalKeyRemoveListener(GlobalKey key); @@ -57,7 +67,7 @@ abstract class GlobalKey extends Key { /// Constructs a LabeledGlobalKey, which is a GlobalKey with a label used for debugging. /// The label is not used for comparing the identity of the key. - factory GlobalKey({ String label }) => new LabeledGlobalKey(label); // the label is purely for debugging purposes and is otherwise ignored + factory GlobalKey({ String label }) => new LabeledGlobalKey(label); // the label is purely for debugging purposes and is otherwise ignored static final Map _registry = new Map(); static final Map _debugDuplicates = new Map(); @@ -154,7 +164,7 @@ abstract class GlobalKey extends Key { /// Each LabeledGlobalKey instance is a unique key. /// The optional label can be used for documentary purposes. It does not affect /// the key's identity. -class LabeledGlobalKey extends GlobalKey { +class LabeledGlobalKey extends GlobalKey { const LabeledGlobalKey(this._label) : super.constructor(); final String _label; String toString() => '[GlobalKey ${_label != null ? _label : hashCode}]'; @@ -167,9 +177,14 @@ class LabeledGlobalKey extends GlobalKey { class GlobalObjectKey extends GlobalKey { const GlobalObjectKey(this.value) : super.constructor(); final Object value; - String toString() => '[GlobalKey ${value.runtimeType}(${value.hashCode})]'; - bool operator==(other) => other is GlobalObjectKey && identical(other.value, value); + bool operator ==(dynamic other) { + if (other is! GlobalObjectKey) + return false; + final GlobalObjectKey typedOther = other; + return identical(value, typedOther.value); + } int get hashCode => identityHashCode(value); + String toString() => '[GlobalKey ${value.runtimeType}(${value.hashCode})]'; } @@ -233,7 +248,7 @@ abstract class LeafRenderObjectWidget extends RenderObjectWidget { /// that have a single child slot. (This superclass only provides the storage /// for that child, it doesn't actually provide the updating logic.) abstract class OneChildRenderObjectWidget extends RenderObjectWidget { - const OneChildRenderObjectWidget({ Key key, Widget this.child }) : super(key: key); + const OneChildRenderObjectWidget({ Key key, this.child }) : super(key: key); final Widget child; @@ -245,7 +260,7 @@ abstract class OneChildRenderObjectWidget extends RenderObjectWidget { /// storage for that child list, it doesn't actually provide the updating /// logic.) abstract class MultiChildRenderObjectWidget extends RenderObjectWidget { - const MultiChildRenderObjectWidget({ Key key, List this.children }) + const MultiChildRenderObjectWidget({ Key key, this.children }) : super(key: key); final List children; @@ -812,7 +827,7 @@ abstract class Element implements BuildContext { } String toStringDeep([String prefixLineOne = '', String prefixOtherLines = '']) { - String result = '${prefixLineOne}$this\n'; + String result = '$prefixLineOne$this\n'; List children = []; visitChildren((Element child) { children.add(child); @@ -1007,7 +1022,7 @@ abstract class ComponentElement extends BuildableElement { built = _builder(this); assert(built != null); } catch (e, stack) { - _debugReportException('building ${_widget}', e, stack); + _debugReportException('building $_widget', e, stack); built = new ErrorWidget(); } finally { // We delay marking the element as clean until after calling _builder so @@ -1019,7 +1034,7 @@ abstract class ComponentElement extends BuildableElement { _child = updateChild(_child, built, slot); assert(_child != null); } catch (e, stack) { - _debugReportException('building ${_widget}', e, stack); + _debugReportException('building $_widget', e, stack); built = new ErrorWidget(); _child = updateChild(null, built, slot); } @@ -1251,7 +1266,7 @@ abstract class RenderObjectElement extends Buildab // dirty, e.g. if they have a builder callback. (Builder callbacks have a // 'BuildContext' argument which you can pass to Theme.of() and other // InheritedWidget APIs which eventually trigger a rebuild.) - print('${runtimeType} failed to implement reinvokeBuilders(), but got marked dirty'); + print('$runtimeType failed to implement reinvokeBuilders(), but got marked dirty'); assert(() { 'reinvokeBuilders() not implemented'; return false; @@ -1297,9 +1312,6 @@ abstract class RenderObjectElement extends Buildab // 6. Sync null with any items in the list of keys that are still // mounted. - final ContainerRenderObjectMixin renderObject = this.renderObject; // TODO(ianh): Remove this once the analyzer is cleverer - assert(renderObject is ContainerRenderObjectMixin); - int childrenTop = 0; int newChildrenBottom = newWidgets.length - 1; int oldChildrenBottom = oldChildren.length - 1; @@ -1401,7 +1413,6 @@ abstract class RenderObjectElement extends Buildab _deactivateChild(oldChild); } - assert(renderObject == this.renderObject); // TODO(ianh): Remove this once the analyzer is cleverer return newChildren; } @@ -1500,11 +1511,10 @@ class OneChildRenderObjectElement extends } void insertChildRenderObject(RenderObject child, dynamic slot) { - final renderObject = this.renderObject; // TODO(ianh): Remove this once the analyzer is cleverer - assert(renderObject is RenderObjectWithChildMixin); + final RenderObjectWithChildMixin renderObject = this.renderObject; assert(slot == null); renderObject.child = child; - assert(renderObject == this.renderObject); // TODO(ianh): Remove this once the analyzer is cleverer + assert(renderObject == this.renderObject); } void moveChildRenderObject(RenderObject child, dynamic slot) { @@ -1512,11 +1522,10 @@ class OneChildRenderObjectElement extends } void removeChildRenderObject(RenderObject child) { - final renderObject = this.renderObject; // TODO(ianh): Remove this once the analyzer is cleverer - assert(renderObject is RenderObjectWithChildMixin); + final RenderObjectWithChildMixin renderObject = this.renderObject; assert(renderObject.child == child); renderObject.child = null; - assert(renderObject == this.renderObject); // TODO(ianh): Remove this once the analyzer is cleverer + assert(renderObject == this.renderObject); } } @@ -1529,27 +1538,24 @@ class MultiChildRenderObjectElement exte List _children; void insertChildRenderObject(RenderObject child, Element slot) { - final renderObject = this.renderObject; // TODO(ianh): Remove this once the analyzer is cleverer - RenderObject nextSibling = slot?.renderObject; - assert(renderObject is ContainerRenderObjectMixin); + final ContainerRenderObjectMixin renderObject = this.renderObject; + final RenderObject nextSibling = slot?.renderObject; renderObject.add(child, before: nextSibling); - assert(renderObject == this.renderObject); // TODO(ianh): Remove this once the analyzer is cleverer + assert(renderObject == this.renderObject); } void moveChildRenderObject(RenderObject child, dynamic slot) { - final renderObject = this.renderObject; // TODO(ianh): Remove this once the analyzer is cleverer - RenderObject nextSibling = slot?.renderObject; - assert(renderObject is ContainerRenderObjectMixin); + final ContainerRenderObjectMixin renderObject = this.renderObject; + final RenderObject nextSibling = slot?.renderObject; renderObject.move(child, before: nextSibling); - assert(renderObject == this.renderObject); // TODO(ianh): Remove this once the analyzer is cleverer + assert(renderObject == this.renderObject); } void removeChildRenderObject(RenderObject child) { - final renderObject = this.renderObject; // TODO(ianh): Remove this once the analyzer is cleverer - assert(renderObject is ContainerRenderObjectMixin); + final ContainerRenderObjectMixin renderObject = this.renderObject; assert(child.parent == renderObject); renderObject.remove(child); - assert(renderObject == this.renderObject); // TODO(ianh): Remove this once the analyzer is cleverer + assert(renderObject == this.renderObject); } bool _debugHasDuplicateIds() { diff --git a/packages/flutter/lib/src/widgets/mixed_viewport.dart b/packages/flutter/lib/src/widgets/mixed_viewport.dart index 83a2bf6c3b..2965054988 100644 --- a/packages/flutter/lib/src/widgets/mixed_viewport.dart +++ b/packages/flutter/lib/src/widgets/mixed_viewport.dart @@ -56,7 +56,13 @@ class _ChildKey { factory _ChildKey.fromWidget(Widget widget) => new _ChildKey(widget.runtimeType, widget.key); final Type type; final Key key; - bool operator ==(other) => other is _ChildKey && other.type == type && other.key == key; + bool operator ==(dynamic other) { + if (other is! _ChildKey) + return false; + final _ChildKey typedOther = other; + return type == typedOther.type && + key == typedOther.key; + } int get hashCode => 373 * 37 * type.hashCode + key.hashCode; String toString() => "_ChildKey(type: $type, key: $key)"; } @@ -327,7 +333,7 @@ class _MixedViewportElement extends RenderObjectElement { double newExtent = _getElementExtent(element, innerConstraints); bool result = _childExtents[index] == newExtent; if (!result) - print("Element $element at index $index was size ${_childExtents[index]} but is now size ${newExtent} yet no invalidate() was received to that effect"); + print("Element $element at index $index was size ${_childExtents[index]} but is now size $newExtent yet no invalidate() was received to that effect"); return result; } diff --git a/packages/flutter/lib/src/widgets/scrollable.dart b/packages/flutter/lib/src/widgets/scrollable.dart index 310dd57a40..35ca49d92f 100644 --- a/packages/flutter/lib/src/widgets/scrollable.dart +++ b/packages/flutter/lib/src/widgets/scrollable.dart @@ -511,7 +511,7 @@ abstract class ScrollableWidgetListState extends List _buildItems(BuildContext context, int start, int count) { List result = buildItems(context, start, count); - assert(result.every((item) => item.key != null)); + assert(result.every((Widget item) => item.key != null)); return result; } @@ -603,7 +603,7 @@ class PageableList extends ScrollableList { final Curve curve; final PageChangedCallback onPageChanged; - PageableListState createState() => new PageableListState(); + PageableListState createState() => new PageableListState(); } class PageableListState extends ScrollableListState> { diff --git a/packages/flutter/lib/src/widgets/statistics_overlay.dart b/packages/flutter/lib/src/widgets/statistics_overlay.dart index 6784fa9c6b..090dbb4cc6 100644 --- a/packages/flutter/lib/src/widgets/statistics_overlay.dart +++ b/packages/flutter/lib/src/widgets/statistics_overlay.dart @@ -44,12 +44,14 @@ class StatisticsOverlay extends LeafRenderObjectWidget { StatisticsOverlay({ this.optionsMask, this.rasterizerThreshold: 0, Key key }) : super(key: key); /// Create a statistics overaly that displays all available statistics - StatisticsOverlay.allEnabled({ Key key, this.rasterizerThreshold: 0 }) : super(key: key), optionsMask = ( - 1 << StatisticsOption.displayRasterizerStatistics.index | - 1 << StatisticsOption.visualizeRasterizerStatistics.index | - 1 << StatisticsOption.displayEngineStatistics.index | - 1 << StatisticsOption.visualizeEngineStatistics.index - ); + StatisticsOverlay.allEnabled({ Key key, this.rasterizerThreshold: 0 }) + : optionsMask = ( + 1 << StatisticsOption.displayRasterizerStatistics.index | + 1 << StatisticsOption.visualizeRasterizerStatistics.index | + 1 << StatisticsOption.displayEngineStatistics.index | + 1 << StatisticsOption.visualizeEngineStatistics.index + ), + super(key: key); final int optionsMask; diff --git a/packages/unit/test/widget/input_test.dart b/packages/unit/test/widget/input_test.dart index 42a12123eb..8b1cef06be 100644 --- a/packages/unit/test/widget/input_test.dart +++ b/packages/unit/test/widget/input_test.dart @@ -77,11 +77,17 @@ void main() { // Check that the cursor visibility toggles after each blink interval. void checkCursorToggle() { - bool initialShowCursor = editableText.test_showCursor; - tester.async.elapse(editableText.test_cursorBlinkPeriod); - expect(editableText.test_showCursor, equals(!initialShowCursor)); - tester.async.elapse(editableText.test_cursorBlinkPeriod); - expect(editableText.test_showCursor, equals(initialShowCursor)); + bool initialShowCursor = editableText.cursorCurrentlyVisible; + tester.async.elapse(editableText.cursorBlinkInterval); + expect(editableText.cursorCurrentlyVisible, equals(!initialShowCursor)); + tester.async.elapse(editableText.cursorBlinkInterval); + expect(editableText.cursorCurrentlyVisible, equals(initialShowCursor)); + tester.async.elapse(editableText.cursorBlinkInterval ~/ 10); + expect(editableText.cursorCurrentlyVisible, equals(initialShowCursor)); + tester.async.elapse(editableText.cursorBlinkInterval); + expect(editableText.cursorCurrentlyVisible, equals(!initialShowCursor)); + tester.async.elapse(editableText.cursorBlinkInterval); + expect(editableText.cursorCurrentlyVisible, equals(initialShowCursor)); } checkCursorToggle();