make some widgets const (#9477)

This commit is contained in:
Alexandre Ardhuin
2017-04-20 08:59:05 +02:00
committed by GitHub
parent cbb49179c9
commit 03c54abd5f
23 changed files with 72 additions and 72 deletions

View File

@@ -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()
)
));
}

View File

@@ -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;

View File

@@ -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,

View File

@@ -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);

View File

@@ -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,

View File

@@ -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,

View File

@@ -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),

View File

@@ -26,7 +26,7 @@ void main() {
},
itemBuilder: (BuildContext context) {
return <PopupMenuItem<int>>[
new PopupMenuItem<int>(
const PopupMenuItem<int>(
value: 1,
child: const Text('One')
)

View File

@@ -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)));
});

View File

@@ -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'))
];
}
),

View File

@@ -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'),
},