Skip to content

Commit

Permalink
make some widgets const (flutter#9477)
Browse files Browse the repository at this point in the history
  • Loading branch information
a14n committed Apr 20, 2017
1 parent cbb4917 commit 03c54ab
Show file tree
Hide file tree
Showing 23 changed files with 72 additions and 72 deletions.
6 changes: 3 additions & 3 deletions examples/flutter_gallery/lib/demo/contacts_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ class ContactsDemoState extends State<ContactsDemo> {
});
},
itemBuilder: (BuildContext context) => <PopupMenuItem<AppBarBehavior>>[
new PopupMenuItem<AppBarBehavior>(
const PopupMenuItem<AppBarBehavior>(
value: AppBarBehavior.normal,
child: const Text('App bar scrolls away')
),
new PopupMenuItem<AppBarBehavior>(
const PopupMenuItem<AppBarBehavior>(
value: AppBarBehavior.pinned,
child: const Text('App bar stays put')
),
new PopupMenuItem<AppBarBehavior>(
const PopupMenuItem<AppBarBehavior>(
value: AppBarBehavior.floating,
child: const Text('App bar floats')
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ class _BottomNavigationDemoState extends State<BottomNavigationDemo>
});
},
itemBuilder: (BuildContext context) => <PopupMenuItem<BottomNavigationBarType>>[
new PopupMenuItem<BottomNavigationBarType>(
const PopupMenuItem<BottomNavigationBarType>(
value: BottomNavigationBarType.fixed,
child: const Text('Fixed'),
),
new PopupMenuItem<BottomNavigationBarType>(
const PopupMenuItem<BottomNavigationBarType>(
value: BottomNavigationBarType.shifting,
child: const Text('Shifting'),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,15 @@ class GridListDemoState extends State<GridListDemo> {
new PopupMenuButton<GridDemoTileStyle>(
onSelected: changeTileStyle,
itemBuilder: (BuildContext context) => <PopupMenuItem<GridDemoTileStyle>>[
new PopupMenuItem<GridDemoTileStyle>(
const PopupMenuItem<GridDemoTileStyle>(
value: GridDemoTileStyle.imageOnly,
child: const Text('Image only'),
),
new PopupMenuItem<GridDemoTileStyle>(
const PopupMenuItem<GridDemoTileStyle>(
value: GridDemoTileStyle.oneLine,
child: const Text('One line'),
),
new PopupMenuItem<GridDemoTileStyle>(
const PopupMenuItem<GridDemoTileStyle>(
value: GridDemoTileStyle.twoLine,
child: const Text('Two line'),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> {
new PopupMenuButton<LeaveBehindDemoAction>(
onSelected: handleDemoAction,
itemBuilder: (BuildContext context) => <PopupMenuEntry<LeaveBehindDemoAction>>[
new PopupMenuItem<LeaveBehindDemoAction>(
const PopupMenuItem<LeaveBehindDemoAction>(
value: LeaveBehindDemoAction.reset,
child: const Text('Reset the list')
),
new PopupMenuDivider(), // ignore: list_element_type_not_assignable, https://github.com/flutter/flutter/issues/5771
const PopupMenuDivider(), // ignore: list_element_type_not_assignable, https://github.com/flutter/flutter/issues/5771
new CheckedPopupMenuItem<LeaveBehindDemoAction>(
value: LeaveBehindDemoAction.horizontalSwipe,
checked: _dismissDirection == DismissDirection.horizontal,
Expand Down
10 changes: 5 additions & 5 deletions examples/flutter_gallery/lib/demo/material/menu_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ class MenuDemoState extends State<MenuDemo> {
new PopupMenuButton<String>(
onSelected: showMenuSelection,
itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
new PopupMenuItem<String>(
const PopupMenuItem<String>(
value: 'Toolbar menu',
child: const Text('Toolbar menu')
),
new PopupMenuItem<String>(
const PopupMenuItem<String>(
value: 'Right here',
child: const Text('Right here')
),
new PopupMenuItem<String>(
const PopupMenuItem<String>(
value: 'Hooray!',
child: const Text('Hooray!')
),
Expand All @@ -99,7 +99,7 @@ class MenuDemoState extends State<MenuDemo> {
value: _simpleValue1,
child: const Text('Context menu item one')
),
new PopupMenuItem<String>(
const PopupMenuItem<String>(
enabled: false,
child: const Text('A disabled menu item')
),
Expand Down Expand Up @@ -140,7 +140,7 @@ class MenuDemoState extends State<MenuDemo> {
title: const Text('Get link')
)
),
new PopupMenuDivider(), // ignore: list_element_type_not_assignable, https://github.com/flutter/flutter/issues/5771
const PopupMenuDivider(), // ignore: list_element_type_not_assignable, https://github.com/flutter/flutter/issues/5771
new PopupMenuItem<String>(
value: 'Remove',
child: new ListTile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo> with Sing

Widget _buildIndicators(BuildContext context, Widget child) {
final List<Widget> indicators = <Widget>[
new SizedBox(
const SizedBox(
width: 200.0,
child: new LinearProgressIndicator()
child: const LinearProgressIndicator()
),
new LinearProgressIndicator(),
new LinearProgressIndicator(),
const LinearProgressIndicator(),
const LinearProgressIndicator(),
new LinearProgressIndicator(value: _animation.value),
new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
new CircularProgressIndicator(),
const CircularProgressIndicator(),
new SizedBox(
width: 20.0,
height: 20.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ class ScrollableTabsDemoState extends State<ScrollableTabsDemo> with SingleTicke
new PopupMenuButton<TabsDemoStyle>(
onSelected: changeDemoStyle,
itemBuilder: (BuildContext context) => <PopupMenuItem<TabsDemoStyle>>[
new PopupMenuItem<TabsDemoStyle>(
const PopupMenuItem<TabsDemoStyle>(
value: TabsDemoStyle.iconsAndText,
child: const Text('Icons and text')
),
new PopupMenuItem<TabsDemoStyle>(
const PopupMenuItem<TabsDemoStyle>(
value: TabsDemoStyle.iconsOnly,
child: const Text('Icons only')
),
new PopupMenuItem<TabsDemoStyle>(
const PopupMenuItem<TabsDemoStyle>(
value: TabsDemoStyle.textOnly,
child: const Text('Text only')
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ class _SelectionControlsDemoState extends State<SelectionControlsDemo> {
}
),
// Disabled switches
new Switch(value: true, onChanged: null),
new Switch(value: false, onChanged: null)
const Switch(value: true, onChanged: null),
const Switch(value: false, onChanged: null)
],
),
);
Expand Down
6 changes: 3 additions & 3 deletions examples/flutter_gallery/lib/demo/shrine/shrine_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ class ShrinePageState extends State<ShrinePage> {
),
new PopupMenuButton<ShrineAction>(
itemBuilder: (BuildContext context) => <PopupMenuItem<ShrineAction>>[
new PopupMenuItem<ShrineAction>(
const PopupMenuItem<ShrineAction>(
value: ShrineAction.sortByPrice,
child: const Text('Sort by price')
),
new PopupMenuItem<ShrineAction>(
const PopupMenuItem<ShrineAction>(
value: ShrineAction.sortByProduct,
child: const Text('Sort by product')
),
new PopupMenuItem<ShrineAction>(
const PopupMenuItem<ShrineAction>(
value: ShrineAction.emptyCart,
child: const Text('Empty shopping cart')
)
Expand Down
4 changes: 2 additions & 2 deletions examples/flutter_gallery/lib/gallery/demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ class FullScreenCodeDialogState extends State<FullScreenCodeDialog> {

Widget body;
if (_exampleCode == null) {
body = new Center(
child: new CircularProgressIndicator()
body = const Center(
child: const CircularProgressIndicator()
);
} else {
body = new SingleChildScrollView(
Expand Down
2 changes: 1 addition & 1 deletion examples/flutter_gallery/lib/gallery/example_code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ new Switch(
// Create a disabled switch.
// Switches are disabled when onChanged isn't
// specified or null.
new Switch(value: false, onChanged: null);
const Switch(value: false, onChanged: null);
// END
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/stocks/lib/stock_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ class StockHomeState extends State<StockHome> {
checked: _autorefresh,
child: const Text('Autorefresh'),
),
new PopupMenuItem<_StockMenuItem>(
const PopupMenuItem<_StockMenuItem>(
value: _StockMenuItem.refresh,
child: const Text('Refresh'),
),
new PopupMenuItem<_StockMenuItem>(
const PopupMenuItem<_StockMenuItem>(
value: _StockMenuItem.speedUp,
child: const Text('Increase animation speed'),
),
new PopupMenuItem<_StockMenuItem>(
const PopupMenuItem<_StockMenuItem>(
value: _StockMenuItem.speedDown,
child: const Text('Decrease animation speed'),
),
Expand Down
6 changes: 3 additions & 3 deletions packages/flutter/lib/src/material/about.dart
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,10 @@ class _LicensePageState extends State<LicensePage> {
];
contents.addAll(_licenses);
if (!_loaded) {
contents.add(new Padding(
contents.add(const Padding(
padding: const EdgeInsets.symmetric(vertical: 24.0),
child: new Center(
child: new CircularProgressIndicator()
child: const Center(
child: const CircularProgressIndicator()
)
));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/material/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ class _AppBarState extends State<AppBar> {
}

class _FloatingAppBar extends StatefulWidget {
_FloatingAppBar({ Key key, this.child }) : super(key: key);
const _FloatingAppBar({ Key key, this.child }) : super(key: key);

final Widget child;

Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/material/paginated_data_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ class PaginatedDataTableState extends State<PaginatedDataTable> {
final List<DataCell> cells = widget.columns.map<DataCell>((DataColumn column) {
if (!column.numeric) {
haveProgressIndicator = true;
return new DataCell(new CircularProgressIndicator());
return const DataCell(const CircularProgressIndicator());
}
return DataCell.empty;
}).toList();
if (!haveProgressIndicator) {
haveProgressIndicator = true;
cells[0] = new DataCell(new CircularProgressIndicator());
cells[0] = const DataCell(const CircularProgressIndicator());
}
return new DataRow.byIndex(
index: index,
Expand Down
8 changes: 4 additions & 4 deletions packages/flutter/lib/src/material/popup_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class PopupMenuDivider extends PopupMenuEntry<dynamic> {
/// Creates a horizontal divider for a popup menu.
///
/// By default, the divider has a height of 16.0 logical pixels.
PopupMenuDivider({ Key key, this.height: 16.0 }) : super(key: key);
const PopupMenuDivider({ Key key, this.height: 16.0 }) : super(key: key);

@override
final double height;
Expand Down Expand Up @@ -111,7 +111,7 @@ class PopupMenuItem<T> extends PopupMenuEntry<T> {
/// Creates an item for a popup menu.
///
/// By default, the item is enabled.
PopupMenuItem({
const PopupMenuItem({
Key key,
this.value,
this.enabled: true,
Expand Down Expand Up @@ -195,7 +195,7 @@ class CheckedPopupMenuItem<T> extends PopupMenuItem<T> {
/// Creates a popup menu item with a checkmark.
///
/// By default, the menu item is enabled but unchecked.
CheckedPopupMenuItem({
const CheckedPopupMenuItem({
Key key,
T value,
this.checked: false,
Expand Down Expand Up @@ -252,7 +252,7 @@ class _CheckedPopupMenuItemState<T> extends _PopupMenuItemState<CheckedPopupMenu
}

class _PopupMenu<T> extends StatelessWidget {
_PopupMenu({
const _PopupMenu({
Key key,
this.route
}) : super(key: key);
Expand Down
8 changes: 4 additions & 4 deletions packages/flutter/lib/src/material/progress_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class ProgressIndicator extends StatefulWidget {
/// The [value] argument can be either null (corresponding to an indeterminate
/// progress indcator) or non-null (corresponding to a determinate progress
/// indicator). See [value] for details.
ProgressIndicator({
const ProgressIndicator({
Key key,
this.value,
this.backgroundColor,
Expand Down Expand Up @@ -137,7 +137,7 @@ class LinearProgressIndicator extends ProgressIndicator {
/// The [value] argument can be either null (corresponding to an indeterminate
/// progress indcator) or non-null (corresponding to a determinate progress
/// indicator). See [value] for details.
LinearProgressIndicator({
const LinearProgressIndicator({
Key key,
double value
}) : super(key: key, value: value);
Expand Down Expand Up @@ -278,7 +278,7 @@ class CircularProgressIndicator extends ProgressIndicator {
/// The [value] argument can be either null (corresponding to an indeterminate
/// progress indcator) or non-null (corresponding to a determinate progress
/// indicator). See [value] for details.
CircularProgressIndicator({
const CircularProgressIndicator({
Key key,
double value,
Color backgroundColor,
Expand Down Expand Up @@ -438,7 +438,7 @@ class RefreshProgressIndicator extends CircularProgressIndicator {
///
/// Rather than creating a refresh progress indicator directly, consider using
/// a [RefreshIndicator] together with a [Scrollable] widget.
RefreshProgressIndicator({
const RefreshProgressIndicator({
Key key,
double value,
Color backgroundColor,
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/material/switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Switch extends StatefulWidget {
///
/// * [value] determines this switch is on or off.
/// * [onChanged] is called when the user toggles with switch on or off.
Switch({
const Switch({
Key key,
@required this.value,
@required this.onChanged,
Expand Down Expand Up @@ -137,7 +137,7 @@ class _SwitchState extends State<Switch> with TickerProviderStateMixin {
}

class _SwitchRenderObjectWidget extends LeafRenderObjectWidget {
_SwitchRenderObjectWidget({
const _SwitchRenderObjectWidget({
Key key,
this.value,
this.activeColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
import 'debug.dart';

class _AccountPictures extends StatelessWidget {
_AccountPictures({
const _AccountPictures({
Key key,
this.currentAccountPicture,
this.otherAccountsPictures,
Expand Down Expand Up @@ -49,7 +49,7 @@ class _AccountPictures extends StatelessWidget {
}

class _AccountDetails extends StatelessWidget {
_AccountDetails({
const _AccountDetails({
Key key,
@required this.accountName,
@required this.accountEmail,
Expand Down Expand Up @@ -132,7 +132,7 @@ class UserAccountsDrawerHeader extends StatefulWidget {
/// Creates a material design drawer header.
///
/// Requires one of its ancestors to be a [Material] widget.
UserAccountsDrawerHeader({
const UserAccountsDrawerHeader({
Key key,
this.decoration,
this.margin: const EdgeInsets.only(bottom: 8.0),
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/test/material/popup_menu_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main() {
},
itemBuilder: (BuildContext context) {
return <PopupMenuItem<int>>[
new PopupMenuItem<int>(
const PopupMenuItem<int>(
value: 1,
child: const Text('One')
)
Expand Down

0 comments on commit 03c54ab

Please sign in to comment.