Commit 03c54abd authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

make some widgets const (#9477)

parent cbb49179
......@@ -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')
),
......
......@@ -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'),
)
......
......@@ -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'),
),
......
......@@ -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,
......
......@@ -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!')
),
......@@ -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')
),
......@@ -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(
......
......@@ -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,
......
......@@ -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')
),
......
......@@ -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)
],
),
);
......
......@@ -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')
)
......
......@@ -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(
......
......@@ -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
}
}
......
......@@ -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'),
),
......
......@@ -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()
)
));
}
......
......@@ -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;
......
......@@ -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,
......
......@@ -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;
......@@ -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,
......@@ -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,
......@@ -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);
......
......@@ -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,
......@@ -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);
......@@ -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,
......@@ -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,
......
......@@ -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,
......@@ -137,7 +137,7 @@ class _SwitchState extends State<Switch> with TickerProviderStateMixin {
}
class _SwitchRenderObjectWidget extends LeafRenderObjectWidget {
_SwitchRenderObjectWidget({
const _SwitchRenderObjectWidget({
Key key,
this.value,
this.activeColor,
......
......@@ -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,
......@@ -49,7 +49,7 @@ class _AccountPictures extends StatelessWidget {
}
class _AccountDetails extends StatelessWidget {
_AccountDetails({
const _AccountDetails({
Key key,
@required this.accountName,
@required this.accountEmail,
......@@ -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),
......
......@@ -26,7 +26,7 @@ void main() {
},
itemBuilder: (BuildContext context) {
return <PopupMenuItem<int>>[
new PopupMenuItem<int>(
const PopupMenuItem<int>(
value: 1,
child: const Text('One')
)
......
......@@ -13,10 +13,10 @@ void main() {
testWidgets('LinearProgressIndicator(value: 0.0) can be constructed', (WidgetTester tester) async {
await tester.pumpWidget(
new Center(
child: new SizedBox(
const Center(
child: const SizedBox(
width: 200.0,
child: new LinearProgressIndicator(value: 0.0)
child: const LinearProgressIndicator(value: 0.0)
)
)
);
......@@ -24,10 +24,10 @@ void main() {
testWidgets('LinearProgressIndicator(value: null) can be constructed', (WidgetTester tester) async {
await tester.pumpWidget(
new Center(
child: new SizedBox(
const Center(
child: const SizedBox(
width: 200.0,
child: new LinearProgressIndicator(value: null)
child: const LinearProgressIndicator(value: null)
)
)
);
......@@ -35,24 +35,24 @@ void main() {
testWidgets('CircularProgressIndicator(value: 0.0) can be constructed', (WidgetTester tester) async {
await tester.pumpWidget(
new Center(
child: new CircularProgressIndicator(value: 0.0)
const Center(
child: const CircularProgressIndicator(value: 0.0)
)
);
});
testWidgets('CircularProgressIndicator(value: null) can be constructed', (WidgetTester tester) async {
await tester.pumpWidget(
new Center(
child: new CircularProgressIndicator(value: null)
const Center(
child: const CircularProgressIndicator(value: null)
)
);
});
testWidgets('LinearProgressIndicator causes a repaint when it changes', (WidgetTester tester) async {
await tester.pumpWidget(new ListView(children: <Widget>[new LinearProgressIndicator(value: 0.0)]));
await tester.pumpWidget(new ListView(children: <Widget>[const LinearProgressIndicator(value: 0.0)]));
final List<Layer> layers1 = tester.layers;
await tester.pumpWidget(new ListView(children: <Widget>[new LinearProgressIndicator(value: 0.5)]));
await tester.pumpWidget(new ListView(children: <Widget>[const LinearProgressIndicator(value: 0.5)]));
final List<Layer> layers2 = tester.layers;
expect(layers1, isNot(equals(layers2)));
});
......
......@@ -25,7 +25,7 @@ void main() {
key: popupMenuButtonKey,
itemBuilder: (BuildContext context) {
return <PopupMenuItem<String>>[
new PopupMenuItem<String>(child: const Text('menuItem'))
const PopupMenuItem<String>(child: const Text('menuItem'))
];
}
),
......@@ -71,7 +71,7 @@ void main() {
key: popupMenuButtonKey,
itemBuilder: (BuildContext context) {
return <PopupMenuItem<String>>[
new PopupMenuItem<String>(child: const Text('menuItem'))
const PopupMenuItem<String>(child: const Text('menuItem'))
];
}
),
......
......@@ -9,7 +9,7 @@ void main() {
testWidgets('TickerMode', (WidgetTester tester) async {
final Widget widget = new TickerMode(
enabled: false,
child: new LinearProgressIndicator()
child: const LinearProgressIndicator()
);
expect(widget.toString, isNot(throwsException));
......@@ -19,14 +19,14 @@ void main() {
await tester.pumpWidget(new TickerMode(
enabled: true,
child: new LinearProgressIndicator()
child: const LinearProgressIndicator()
));
expect(tester.binding.transientCallbackCount, 1);
await tester.pumpWidget(new TickerMode(
enabled: false,
child: new LinearProgressIndicator()
child: const LinearProgressIndicator()
));
expect(tester.binding.transientCallbackCount, 0);
......@@ -34,7 +34,7 @@ void main() {
testWidgets('Navigation with TickerMode', (WidgetTester tester) async {
await tester.pumpWidget(new MaterialApp(
home: new LinearProgressIndicator(),
home: const LinearProgressIndicator(),
routes: <String, WidgetBuilder>{
'/test': (BuildContext context) => const Text('hello'),
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment