More const immutable classes (#9544)
* more widget const constructors
* prefer const constructors
* address review comments
diff --git a/examples/flutter_gallery/lib/demo/animation/home.dart b/examples/flutter_gallery/lib/demo/animation/home.dart
index 721f740..e86c693 100644
--- a/examples/flutter_gallery/lib/demo/animation/home.dart
+++ b/examples/flutter_gallery/lib/demo/animation/home.dart
@@ -525,7 +525,7 @@
new Positioned(
top: statusBarHeight,
left: 0.0,
- child: new IconTheme(
+ child: const IconTheme(
data: const IconThemeData(color: Colors.white),
child: const BackButton(),
),
diff --git a/examples/flutter_gallery/lib/demo/calculator/home.dart b/examples/flutter_gallery/lib/demo/calculator/home.dart
index 6ace8b9..093804b 100644
--- a/examples/flutter_gallery/lib/demo/calculator/home.dart
+++ b/examples/flutter_gallery/lib/demo/calculator/home.dart
@@ -126,7 +126,7 @@
flex: 2,
child: new CalcDisplay(content: _expression.toString())
),
- new Divider(height: 1.0),
+ const Divider(height: 1.0),
new Expanded(
flex: 3,
child: new KeyPad(calcState: this)
diff --git a/examples/flutter_gallery/lib/demo/contacts_demo.dart b/examples/flutter_gallery/lib/demo/contacts_demo.dart
index fdc5550..95daa37 100644
--- a/examples/flutter_gallery/lib/demo/contacts_demo.dart
+++ b/examples/flutter_gallery/lib/demo/contacts_demo.dart
@@ -116,7 +116,7 @@
icon: const Icon(Icons.create),
tooltip: 'Edit',
onPressed: () {
- _scaffoldKey.currentState.showSnackBar(new SnackBar(
+ _scaffoldKey.currentState.showSnackBar(const SnackBar(
content: const Text('This is actually just a demo. Editing isn\'t supported.')
));
},
@@ -176,7 +176,7 @@
icon: Icons.message,
tooltip: 'Send message',
onPressed: () {
- _scaffoldKey.currentState.showSnackBar(new SnackBar(
+ _scaffoldKey.currentState.showSnackBar(const SnackBar(
content: const Text('Pretend that this opened your SMS application.')
));
},
@@ -189,7 +189,7 @@
icon: Icons.message,
tooltip: 'Send message',
onPressed: () {
- _scaffoldKey.currentState.showSnackBar(new SnackBar(
+ _scaffoldKey.currentState.showSnackBar(const SnackBar(
content: const Text('In this demo, this button doesn\'t do anything.')
));
},
@@ -202,7 +202,7 @@
icon: Icons.message,
tooltip: 'Send message',
onPressed: () {
- _scaffoldKey.currentState.showSnackBar(new SnackBar(
+ _scaffoldKey.currentState.showSnackBar(const SnackBar(
content: const Text('Imagine if you will, a messaging application.')
));
},
@@ -220,7 +220,7 @@
icon: Icons.email,
tooltip: 'Send personal e-mail',
onPressed: () {
- _scaffoldKey.currentState.showSnackBar(new SnackBar(
+ _scaffoldKey.currentState.showSnackBar(const SnackBar(
content: const Text('Here, your e-mail application would open.')
));
},
@@ -233,7 +233,7 @@
icon: Icons.email,
tooltip: 'Send work e-mail',
onPressed: () {
- _scaffoldKey.currentState.showSnackBar(new SnackBar(
+ _scaffoldKey.currentState.showSnackBar(const SnackBar(
content: const Text('This is a demo, so this button does not actually work.')
));
},
@@ -251,7 +251,7 @@
icon: Icons.map,
tooltip: 'Open map',
onPressed: () {
- _scaffoldKey.currentState.showSnackBar(new SnackBar(
+ _scaffoldKey.currentState.showSnackBar(const SnackBar(
content: const Text('This would show a map of San Francisco.')
));
},
@@ -265,7 +265,7 @@
icon: Icons.map,
tooltip: 'Open map',
onPressed: () {
- _scaffoldKey.currentState.showSnackBar(new SnackBar(
+ _scaffoldKey.currentState.showSnackBar(const SnackBar(
content: const Text('This would show a map of Mountain View.')
));
},
@@ -279,7 +279,7 @@
icon: Icons.map,
tooltip: 'Open map',
onPressed: () {
- _scaffoldKey.currentState.showSnackBar(new SnackBar(
+ _scaffoldKey.currentState.showSnackBar(const SnackBar(
content: const Text('This would also show a map, if this was not a demo.')
));
},
diff --git a/examples/flutter_gallery/lib/demo/cupertino/cupertino_activity_indicator_demo.dart b/examples/flutter_gallery/lib/demo/cupertino/cupertino_activity_indicator_demo.dart
index bcd717f..57b100c 100644
--- a/examples/flutter_gallery/lib/demo/cupertino/cupertino_activity_indicator_demo.dart
+++ b/examples/flutter_gallery/lib/demo/cupertino/cupertino_activity_indicator_demo.dart
@@ -14,8 +14,8 @@
appBar: new AppBar(
title: const Text('Cupertino Activity Indicator'),
),
- body: new Center(
- child: new CupertinoActivityIndicator(),
+ body: const Center(
+ child: const CupertinoActivityIndicator(),
),
);
}
diff --git a/examples/flutter_gallery/lib/demo/cupertino/cupertino_buttons_demo.dart b/examples/flutter_gallery/lib/demo/cupertino/cupertino_buttons_demo.dart
index 79685ec..cbc6d7b 100644
--- a/examples/flutter_gallery/lib/demo/cupertino/cupertino_buttons_demo.dart
+++ b/examples/flutter_gallery/lib/demo/cupertino/cupertino_buttons_demo.dart
@@ -49,7 +49,7 @@
setState(() {_pressedCount++;});
}
),
- new CupertinoButton(
+ const CupertinoButton(
child: const Text('Disabled'),
onPressed: null,
),
@@ -65,7 +65,7 @@
}
),
const Padding(padding: const EdgeInsets.all(12.0)),
- new CupertinoButton(
+ const CupertinoButton(
child: const Text('Disabled'),
color: _kBlue,
onPressed: null,
diff --git a/examples/flutter_gallery/lib/demo/material/buttons_demo.dart b/examples/flutter_gallery/lib/demo/material/buttons_demo.dart
index 92fdadc..249b245 100644
--- a/examples/flutter_gallery/lib/demo/material/buttons_demo.dart
+++ b/examples/flutter_gallery/lib/demo/material/buttons_demo.dart
@@ -121,7 +121,7 @@
// Perform some action
},
),
- new FlatButton(
+ const FlatButton(
child: const Text('DISABLED'),
onPressed: null,
)
diff --git a/examples/flutter_gallery/lib/demo/material/drawer_demo.dart b/examples/flutter_gallery/lib/demo/material/drawer_demo.dart
index b922355..2647c77 100644
--- a/examples/flutter_gallery/lib/demo/material/drawer_demo.dart
+++ b/examples/flutter_gallery/lib/demo/material/drawer_demo.dart
@@ -67,7 +67,7 @@
void _showNotImplementedMessage() {
Navigator.of(context).pop(); // Dismiss the drawer.
- _scaffoldKey.currentState.showSnackBar(new SnackBar(
+ _scaffoldKey.currentState.showSnackBar(const SnackBar(
content: const Text("The drawer's items don't do anything")
));
}
diff --git a/examples/flutter_gallery/lib/demo/material/expansion_panels_demo.dart b/examples/flutter_gallery/lib/demo/material/expansion_panels_demo.dart
index e08d2da..2a0e339 100644
--- a/examples/flutter_gallery/lib/demo/material/expansion_panels_demo.dart
+++ b/examples/flutter_gallery/lib/demo/material/expansion_panels_demo.dart
@@ -108,7 +108,7 @@
)
)
),
- new Divider(height: 1.0),
+ const Divider(height: 1.0),
new Container(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: new Row(
diff --git a/examples/flutter_gallery/lib/demo/material/leave_behind_demo.dart b/examples/flutter_gallery/lib/demo/material/leave_behind_demo.dart
index d616a06..925ce96 100644
--- a/examples/flutter_gallery/lib/demo/material/leave_behind_demo.dart
+++ b/examples/flutter_gallery/lib/demo/material/leave_behind_demo.dart
@@ -103,13 +103,13 @@
},
background: new Container(
color: theme.primaryColor,
- child: new ListTile(
+ child: const ListTile(
leading: const Icon(Icons.delete, color: Colors.white, size: 36.0)
)
),
secondaryBackground: new Container(
color: theme.primaryColor,
- child: new ListTile(
+ child: const ListTile(
trailing: const Icon(Icons.archive, color: Colors.white, size: 36.0)
)
),
diff --git a/examples/flutter_gallery/lib/demo/material/menu_demo.dart b/examples/flutter_gallery/lib/demo/material/menu_demo.dart
index 44035fc..6c49b84 100644
--- a/examples/flutter_gallery/lib/demo/material/menu_demo.dart
+++ b/examples/flutter_gallery/lib/demo/material/menu_demo.dart
@@ -119,31 +119,31 @@
padding: EdgeInsets.zero,
onSelected: showMenuSelection,
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
- new PopupMenuItem<String>(
+ const PopupMenuItem<String>(
value: 'Preview',
- child: new ListTile(
+ child: const ListTile(
leading: const Icon(Icons.visibility),
title: const Text('Preview')
)
),
- new PopupMenuItem<String>(
+ const PopupMenuItem<String>(
value: 'Share',
- child: new ListTile(
+ child: const ListTile(
leading: const Icon(Icons.person_add),
title: const Text('Share')
)
),
- new PopupMenuItem<String>(
+ const PopupMenuItem<String>(
value: 'Get Link',
- child: new ListTile(
+ child: const ListTile(
leading: const Icon(Icons.link),
title: const Text('Get link')
)
),
const PopupMenuDivider(), // ignore: list_element_type_not_assignable, https://github.com/flutter/flutter/issues/5771
- new PopupMenuItem<String>(
+ const PopupMenuItem<String>(
value: 'Remove',
- child: new ListTile(
+ child: const ListTile(
leading: const Icon(Icons.delete),
title: const Text('Remove')
)
diff --git a/examples/flutter_gallery/lib/demo/material/slider_demo.dart b/examples/flutter_gallery/lib/demo/material/slider_demo.dart
index acd8d00..7441d67 100644
--- a/examples/flutter_gallery/lib/demo/material/slider_demo.dart
+++ b/examples/flutter_gallery/lib/demo/material/slider_demo.dart
@@ -43,7 +43,7 @@
new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget> [
- new Slider(value: 0.25, thumbOpenAtMin: true, onChanged: null),
+ const Slider(value: 0.25, thumbOpenAtMin: true, onChanged: null),
const Text('Disabled'),
]
),
diff --git a/examples/flutter_gallery/lib/demo/material/tooltip_demo.dart b/examples/flutter_gallery/lib/demo/material/tooltip_demo.dart
index a6d025d..c7bd7f3 100644
--- a/examples/flutter_gallery/lib/demo/material/tooltip_demo.dart
+++ b/examples/flutter_gallery/lib/demo/material/tooltip_demo.dart
@@ -46,7 +46,7 @@
color: theme.iconTheme.color,
tooltip: 'Place a phone call',
onPressed: () {
- Scaffold.of(context).showSnackBar(new SnackBar(
+ Scaffold.of(context).showSnackBar(const SnackBar(
content: const Text('That was an ordinary tap.')
));
}
diff --git a/examples/flutter_gallery/lib/demo/material/two_level_list_demo.dart b/examples/flutter_gallery/lib/demo/material/two_level_list_demo.dart
index d152173..cc22f96 100644
--- a/examples/flutter_gallery/lib/demo/material/two_level_list_demo.dart
+++ b/examples/flutter_gallery/lib/demo/material/two_level_list_demo.dart
@@ -14,19 +14,19 @@
body: new TwoLevelList(
type: MaterialListType.oneLine,
children: <Widget>[
- new TwoLevelListItem(title: const Text('Top')),
+ const TwoLevelListItem(title: const Text('Top')),
new TwoLevelSublist(
title: const Text('Sublist'),
backgroundColor: Theme.of(context).accentColor.withOpacity(0.025),
children: <Widget>[
- new TwoLevelListItem(title: const Text('One')),
- new TwoLevelListItem(title: const Text('Two')),
+ const TwoLevelListItem(title: const Text('One')),
+ const TwoLevelListItem(title: const Text('Two')),
// https://en.wikipedia.org/wiki/Free_Four
- new TwoLevelListItem(title: const Text('Free')),
- new TwoLevelListItem(title: const Text('Four'))
+ const TwoLevelListItem(title: const Text('Free')),
+ const TwoLevelListItem(title: const Text('Four'))
]
),
- new TwoLevelListItem(title: const Text('Bottom'))
+ const TwoLevelListItem(title: const Text('Bottom'))
]
)
);
diff --git a/examples/flutter_gallery/lib/demo/pesto_demo.dart b/examples/flutter_gallery/lib/demo/pesto_demo.dart
index ab4d4e3..b56232a 100644
--- a/examples/flutter_gallery/lib/demo/pesto_demo.dart
+++ b/examples/flutter_gallery/lib/demo/pesto_demo.dart
@@ -84,7 +84,7 @@
floatingActionButton: new FloatingActionButton(
child: const Icon(Icons.edit),
onPressed: () {
- scaffoldKey.currentState.showSnackBar(new SnackBar(
+ scaffoldKey.currentState.showSnackBar(const SnackBar(
content: const Text('Not supported.'),
));
},
@@ -108,7 +108,7 @@
icon: const Icon(Icons.search),
tooltip: 'Search',
onPressed: () {
- scaffoldKey.currentState.showSnackBar(new SnackBar(
+ scaffoldKey.currentState.showSnackBar(const SnackBar(
content: const Text('Not supported.'),
));
},
diff --git a/examples/flutter_gallery/lib/demo/shrine/shrine_page.dart b/examples/flutter_gallery/lib/demo/shrine/shrine_page.dart
index d6842cb..6a45a1a 100644
--- a/examples/flutter_gallery/lib/demo/shrine/shrine_page.dart
+++ b/examples/flutter_gallery/lib/demo/shrine/shrine_page.dart
@@ -82,7 +82,7 @@
void _emptyCart() {
widget.shoppingCart.clear();
- widget.scaffoldKey.currentState.showSnackBar(new SnackBar(content: const Text('Shopping cart is empty')));
+ widget.scaffoldKey.currentState.showSnackBar(const SnackBar(content: const Text('Shopping cart is empty')));
}
@override
diff --git a/examples/flutter_gallery/lib/gallery/drawer.dart b/examples/flutter_gallery/lib/gallery/drawer.dart
index 1070df9..92f765b 100644
--- a/examples/flutter_gallery/lib/gallery/drawer.dart
+++ b/examples/flutter_gallery/lib/gallery/drawer.dart
@@ -254,10 +254,10 @@
new GalleryDrawerHeader(light: useLightTheme),
lightThemeItem,
darkThemeItem,
- new Divider(),
+ const Divider(),
mountainViewItem,
cupertinoItem,
- new Divider(),
+ const Divider(),
animateSlowlyItem,
// index 8, optional: Performance Overlay
sendFeedbackItem,
diff --git a/examples/flutter_gallery/lib/gallery/example_code.dart b/examples/flutter_gallery/lib/gallery/example_code.dart
index 1070cd4..97d22eb 100644
--- a/examples/flutter_gallery/lib/gallery/example_code.dart
+++ b/examples/flutter_gallery/lib/gallery/example_code.dart
@@ -44,7 +44,7 @@
// Create a disabled button.
// Buttons are disabled when onPressed isn't
// specified or is null.
-new FlatButton(
+const FlatButton(
child: const Text('BUTTON TITLE'),
onPressed: null
);
diff --git a/examples/flutter_gallery/lib/gallery/home.dart b/examples/flutter_gallery/lib/gallery/home.dart
index 5dd6d5c..a2a4e41 100644
--- a/examples/flutter_gallery/lib/gallery/home.dart
+++ b/examples/flutter_gallery/lib/gallery/home.dart
@@ -132,7 +132,7 @@
for (GalleryItem galleryItem in kAllGalleryItems) {
if (category != galleryItem.category) {
if (category != null)
- listItems.add(new Divider());
+ listItems.add(const Divider());
listItems.add(
new Container(
height: 48.0,
@@ -166,7 +166,7 @@
),
body: new CustomScrollView(
slivers: <Widget>[
- new SliverAppBar(
+ const SliverAppBar(
pinned: true,
expandedHeight: _kFlexibleSpaceMaxHeight,
flexibleSpace: const FlexibleSpaceBar(