More const immutable classes (#9544)
* more widget const constructors * prefer const constructors * address review comments
This commit is contained in:
committed by
GitHub
parent
054c937917
commit
83fce211a3
@@ -525,7 +525,7 @@ class _AnimationDemoHomeState extends State<AnimationDemoHome> {
|
||||
new Positioned(
|
||||
top: statusBarHeight,
|
||||
left: 0.0,
|
||||
child: new IconTheme(
|
||||
child: const IconTheme(
|
||||
data: const IconThemeData(color: Colors.white),
|
||||
child: const BackButton(),
|
||||
),
|
||||
|
||||
@@ -126,7 +126,7 @@ class _CalculatorState extends State<Calculator> {
|
||||
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)
|
||||
|
||||
@@ -116,7 +116,7 @@ class ContactsDemoState extends State<ContactsDemo> {
|
||||
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 @@ class ContactsDemoState extends State<ContactsDemo> {
|
||||
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 @@ class ContactsDemoState extends State<ContactsDemo> {
|
||||
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 @@ class ContactsDemoState extends State<ContactsDemo> {
|
||||
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 @@ class ContactsDemoState extends State<ContactsDemo> {
|
||||
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 @@ class ContactsDemoState extends State<ContactsDemo> {
|
||||
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 @@ class ContactsDemoState extends State<ContactsDemo> {
|
||||
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 @@ class ContactsDemoState extends State<ContactsDemo> {
|
||||
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 @@ class ContactsDemoState extends State<ContactsDemo> {
|
||||
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.')
|
||||
));
|
||||
},
|
||||
|
||||
@@ -14,8 +14,8 @@ class CupertinoProgressIndicatorDemo extends StatelessWidget {
|
||||
appBar: new AppBar(
|
||||
title: const Text('Cupertino Activity Indicator'),
|
||||
),
|
||||
body: new Center(
|
||||
child: new CupertinoActivityIndicator(),
|
||||
body: const Center(
|
||||
child: const CupertinoActivityIndicator(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class _CupertinoButtonDemoState extends State<CupertinoButtonsDemo> {
|
||||
setState(() {_pressedCount++;});
|
||||
}
|
||||
),
|
||||
new CupertinoButton(
|
||||
const CupertinoButton(
|
||||
child: const Text('Disabled'),
|
||||
onPressed: null,
|
||||
),
|
||||
@@ -65,7 +65,7 @@ class _CupertinoButtonDemoState extends State<CupertinoButtonsDemo> {
|
||||
}
|
||||
),
|
||||
const Padding(padding: const EdgeInsets.all(12.0)),
|
||||
new CupertinoButton(
|
||||
const CupertinoButton(
|
||||
child: const Text('Disabled'),
|
||||
color: _kBlue,
|
||||
onPressed: null,
|
||||
|
||||
@@ -121,7 +121,7 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
|
||||
// Perform some action
|
||||
},
|
||||
),
|
||||
new FlatButton(
|
||||
const FlatButton(
|
||||
child: const Text('DISABLED'),
|
||||
onPressed: null,
|
||||
)
|
||||
|
||||
@@ -67,7 +67,7 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
|
||||
|
||||
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")
|
||||
));
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class CollapsibleBody extends StatelessWidget {
|
||||
)
|
||||
)
|
||||
),
|
||||
new Divider(height: 1.0),
|
||||
const Divider(height: 1.0),
|
||||
new Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||||
child: new Row(
|
||||
|
||||
@@ -103,13 +103,13 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> {
|
||||
},
|
||||
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)
|
||||
)
|
||||
),
|
||||
|
||||
@@ -119,31 +119,31 @@ class MenuDemoState extends State<MenuDemo> {
|
||||
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')
|
||||
)
|
||||
|
||||
@@ -43,7 +43,7 @@ class _SliderDemoState extends State<SliderDemo> {
|
||||
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'),
|
||||
]
|
||||
),
|
||||
|
||||
@@ -46,7 +46,7 @@ class TooltipDemo extends StatelessWidget {
|
||||
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.')
|
||||
));
|
||||
}
|
||||
|
||||
@@ -14,19 +14,19 @@ class TwoLevelListDemo extends StatelessWidget {
|
||||
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'))
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
@@ -84,7 +84,7 @@ class _RecipeGridPageState extends State<RecipeGridPage> {
|
||||
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 @@ class _RecipeGridPageState extends State<RecipeGridPage> {
|
||||
icon: const Icon(Icons.search),
|
||||
tooltip: 'Search',
|
||||
onPressed: () {
|
||||
scaffoldKey.currentState.showSnackBar(new SnackBar(
|
||||
scaffoldKey.currentState.showSnackBar(const SnackBar(
|
||||
content: const Text('Not supported.'),
|
||||
));
|
||||
},
|
||||
|
||||
@@ -82,7 +82,7 @@ class ShrinePageState extends State<ShrinePage> {
|
||||
|
||||
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
|
||||
|
||||
@@ -254,10 +254,10 @@ class GalleryDrawer extends StatelessWidget {
|
||||
new GalleryDrawerHeader(light: useLightTheme),
|
||||
lightThemeItem,
|
||||
darkThemeItem,
|
||||
new Divider(),
|
||||
const Divider(),
|
||||
mountainViewItem,
|
||||
cupertinoItem,
|
||||
new Divider(),
|
||||
const Divider(),
|
||||
animateSlowlyItem,
|
||||
// index 8, optional: Performance Overlay
|
||||
sendFeedbackItem,
|
||||
|
||||
@@ -44,7 +44,7 @@ new FlatButton(
|
||||
// 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
|
||||
);
|
||||
|
||||
@@ -132,7 +132,7 @@ class GalleryHomeState extends State<GalleryHome> with SingleTickerProviderState
|
||||
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 @@ class GalleryHomeState extends State<GalleryHome> with SingleTickerProviderState
|
||||
),
|
||||
body: new CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
new SliverAppBar(
|
||||
const SliverAppBar(
|
||||
pinned: true,
|
||||
expandedHeight: _kFlexibleSpaceMaxHeight,
|
||||
flexibleSpace: const FlexibleSpaceBar(
|
||||
|
||||
@@ -118,12 +118,12 @@ class StockHomeState extends State<StockHome> {
|
||||
child: new ListView(
|
||||
children: <Widget>[
|
||||
const DrawerHeader(child: const Center(child: const Text('Stocks'))),
|
||||
new ListTile(
|
||||
const ListTile(
|
||||
leading: const Icon(Icons.assessment),
|
||||
title: const Text('Stock List'),
|
||||
selected: true,
|
||||
),
|
||||
new ListTile(
|
||||
const ListTile(
|
||||
leading: const Icon(Icons.account_balance),
|
||||
title: const Text('Account Balance'),
|
||||
enabled: false,
|
||||
@@ -142,7 +142,7 @@ class StockHomeState extends State<StockHome> {
|
||||
}
|
||||
},
|
||||
),
|
||||
new Divider(),
|
||||
const Divider(),
|
||||
new ListTile(
|
||||
leading: const Icon(Icons.thumb_up),
|
||||
title: const Text('Optimistic'),
|
||||
@@ -167,7 +167,7 @@ class StockHomeState extends State<StockHome> {
|
||||
_handleStockModeChange(StockMode.pessimistic);
|
||||
},
|
||||
),
|
||||
new Divider(),
|
||||
const Divider(),
|
||||
new ListTile(
|
||||
leading: const Icon(Icons.settings),
|
||||
title: const Text('Settings'),
|
||||
|
||||
Reference in New Issue
Block a user