make @immutable const classes (#9532)

* make @immutable const

* fix build
This commit is contained in:
Alexandre Ardhuin
2017-04-21 23:09:42 +02:00
committed by GitHub
parent 1abb6f5d74
commit 9541848272
166 changed files with 397 additions and 403 deletions

View File

@@ -366,7 +366,7 @@ class _AllSectionsView extends AnimatedWidget {
}
class AnimationDemoHome extends StatefulWidget {
AnimationDemoHome({ Key key }) : super(key: key);
const AnimationDemoHome({ Key key }) : super(key: key);
static const String routeName = '/animation';

View File

@@ -100,7 +100,7 @@ class SectionTitle extends StatelessWidget {
// Small horizontal bar that indicates the selected section.
class SectionIndicator extends StatelessWidget {
SectionIndicator({ Key key, this.opacity: 1.0 }) : super(key: key);
const SectionIndicator({ Key key, this.opacity: 1.0 }) : super(key: key);
final double opacity;

View File

@@ -7,10 +7,10 @@ import 'package:flutter/material.dart';
import 'animation/home.dart';
class AnimationDemo extends StatelessWidget {
AnimationDemo({Key key}) : super(key: key);
const AnimationDemo({Key key}) : super(key: key);
static const String routeName = '/animation';
@override
Widget build(BuildContext context) => new AnimationDemoHome();
Widget build(BuildContext context) => const AnimationDemoHome();
}

View File

@@ -7,7 +7,7 @@ import 'package:flutter/material.dart';
import 'logic.dart';
class Calculator extends StatefulWidget {
Calculator({Key key}) : super(key: key);
const Calculator({Key key}) : super(key: key);
@override
_CalculatorState createState() => new _CalculatorState();
@@ -138,7 +138,7 @@ class _CalculatorState extends State<Calculator> {
}
class CalcDisplay extends StatelessWidget {
CalcDisplay({ this.content });
const CalcDisplay({ this.content });
final String content;
@@ -154,7 +154,7 @@ class CalcDisplay extends StatelessWidget {
}
class KeyPad extends StatelessWidget {
KeyPad({ this.calcState });
const KeyPad({ this.calcState });
final _CalculatorState calcState;
@@ -222,7 +222,7 @@ class KeyPad extends StatelessWidget {
}
class KeyRow extends StatelessWidget {
KeyRow(this.keys);
const KeyRow(this.keys);
final List<Widget> keys;
@@ -238,7 +238,7 @@ class KeyRow extends StatelessWidget {
}
class CalcKey extends StatelessWidget {
CalcKey(this.text, this.onTap);
const CalcKey(this.text, this.onTap);
final String text;
final GestureTapCallback onTap;

View File

@@ -7,10 +7,10 @@ import 'package:flutter/material.dart';
import 'calculator/home.dart';
class CalculatorDemo extends StatelessWidget {
CalculatorDemo({Key key}) : super(key: key);
const CalculatorDemo({Key key}) : super(key: key);
static const String routeName = '/calculator';
@override
Widget build(BuildContext context) => new Calculator();
Widget build(BuildContext context) => const Calculator();
}

View File

@@ -5,7 +5,7 @@
import 'package:flutter/material.dart';
class _ContactCategory extends StatelessWidget {
_ContactCategory({ Key key, this.icon, this.children }) : super(key: key);
const _ContactCategory({ Key key, this.icon, this.children }) : super(key: key);
final IconData icon;
final List<Widget> children;

View File

@@ -100,7 +100,7 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
// Perform some action
},
),
new RaisedButton(
const RaisedButton(
child: const Text('DISABLED'),
onPressed: null,
)

View File

@@ -26,8 +26,8 @@ class _ChipDemoState extends State<ChipDemo> {
const Chip(
label: const Text('Apple')
),
new Chip(
avatar: new CircleAvatar(child: const Text('B')),
const Chip(
avatar: const CircleAvatar(child: const Text('B')),
label: const Text('Blueberry')
),
];

View File

@@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class _InputDropdown extends StatelessWidget {
_InputDropdown({
const _InputDropdown({
Key key,
this.child,
this.labelText,
@@ -47,7 +47,7 @@ class _InputDropdown extends StatelessWidget {
}
class _DateTimePicker extends StatelessWidget {
_DateTimePicker({
const _DateTimePicker({
Key key,
this.labelText,
this.selectedDate,

View File

@@ -20,7 +20,7 @@ const String _alertWithTitleText =
"data to Google, even when no apps are running.";
class DialogDemoItem extends StatelessWidget {
DialogDemoItem({ Key key, this.icon, this.color, this.text, this.onPressed }) : super(key: key);
const DialogDemoItem({ Key key, this.icon, this.color, this.text, this.onPressed }) : super(key: key);
final IconData icon;
final Color color;

View File

@@ -14,7 +14,7 @@ typedef Widget DemoItemBodyBuilder<T>(DemoItem<T> item);
typedef String ValueToString<T>(T value);
class DualHeaderWithHint extends StatelessWidget {
DualHeaderWithHint({
const DualHeaderWithHint({
this.name,
this.value,
this.hint,
@@ -76,7 +76,7 @@ class DualHeaderWithHint extends StatelessWidget {
}
class CollapsibleBody extends StatelessWidget {
CollapsibleBody({
const CollapsibleBody({
this.margin: EdgeInsets.zero,
this.child,
this.onSave,

View File

@@ -29,7 +29,7 @@ class Photo {
}
class GridPhotoViewer extends StatefulWidget {
GridPhotoViewer({ Key key, this.photo }) : super(key: key);
const GridPhotoViewer({ Key key, this.photo }) : super(key: key);
final Photo photo;
@@ -38,7 +38,7 @@ class GridPhotoViewer extends StatefulWidget {
}
class _GridTitleText extends StatelessWidget {
_GridTitleText(this.text);
const _GridTitleText(this.text);
final String text;
@@ -227,7 +227,7 @@ class GridDemoPhotoItem extends StatelessWidget {
}
class GridListDemo extends StatefulWidget {
GridListDemo({ Key key }) : super(key: key);
const GridListDemo({ Key key }) : super(key: key);
static const String routeName = '/material/grid-list';

View File

@@ -29,7 +29,7 @@ class LeaveBehindItem implements Comparable<LeaveBehindItem> {
}
class LeaveBehindDemo extends StatefulWidget {
LeaveBehindDemo({ Key key }) : super(key: key);
const LeaveBehindDemo({ Key key }) : super(key: key);
static const String routeName = '/material/leave-behind';

View File

@@ -5,7 +5,7 @@
import 'package:flutter/material.dart';
class ListDemo extends StatefulWidget {
ListDemo({ Key key }) : super(key: key);
const ListDemo({ Key key }) : super(key: key);
static const String routeName = '/material/list';

View File

@@ -5,7 +5,7 @@
import 'package:flutter/material.dart';
class MenuDemo extends StatefulWidget {
MenuDemo({ Key key }) : super(key: key);
const MenuDemo({ Key key }) : super(key: key);
static const String routeName = '/material/menu';

View File

@@ -9,7 +9,7 @@ import 'package:flutter/material.dart';
enum IndicatorType { overscroll, refresh }
class OverscrollDemo extends StatefulWidget {
OverscrollDemo({ Key key }) : super(key: key);
const OverscrollDemo({ Key key }) : super(key: key);
static const String routeName = '/material/overscroll';

View File

@@ -5,7 +5,7 @@
import 'package:flutter/material.dart';
class _PageSelector extends StatelessWidget {
_PageSelector({ this.icons });
const _PageSelector({ this.icons });
final List<IconData> icons;

View File

@@ -98,8 +98,8 @@ class _SelectionControlsDemoState extends State<SelectionControlsDemo> {
mainAxisSize: MainAxisSize.min,
children: <Widget>[
// Disabled checkboxes
new Checkbox(value: true, onChanged: null),
new Checkbox(value: false, onChanged: null)
const Checkbox(value: true, onChanged: null),
const Checkbox(value: false, onChanged: null)
]
)
]
@@ -137,17 +137,17 @@ class _SelectionControlsDemoState extends State<SelectionControlsDemo> {
new Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Radio<int>(
const Radio<int>(
value: 0,
groupValue: 0,
onChanged: null
),
new Radio<int>(
const Radio<int>(
value: 1,
groupValue: 0,
onChanged: null
),
new Radio<int>(
const Radio<int>(
value: 2,
groupValue: 0,
onChanged: null

View File

@@ -17,7 +17,7 @@ const String _text3 =
"By default snackbars automatically disappear after a few seconds ";
class SnackBarDemo extends StatefulWidget {
SnackBarDemo({ Key key }) : super(key: key);
const SnackBarDemo({ Key key }) : super(key: key);
static const String routeName = '/material/snack-bar';

View File

@@ -75,7 +75,7 @@ final Map<_Page, List<_CardData>> _allPages = <_Page, List<_CardData>>{
};
class _CardDataItem extends StatelessWidget {
_CardDataItem({ this.page, this.data });
const _CardDataItem({ this.page, this.data });
static final double height = 272.0;
final _Page page;

View File

@@ -7,7 +7,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
class TextFormFieldDemo extends StatefulWidget {
TextFormFieldDemo({ Key key }) : super(key: key);
const TextFormFieldDemo({ Key key }) : super(key: key);
static const String routeName = '/material/text-form-field';

View File

@@ -6,7 +6,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class PestoDemo extends StatelessWidget {
PestoDemo({ Key key }) : super(key: key);
const PestoDemo({ Key key }) : super(key: key);
static const String routeName = '/pesto';
@@ -31,7 +31,7 @@ final ThemeData _kTheme = new ThemeData(
class PestoHome extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new RecipeGridPage(recipes: kPestoRecipes);
return const RecipeGridPage(recipes: kPestoRecipes);
}
}
@@ -63,7 +63,7 @@ class PestoStyle extends TextStyle {
// Displays a grid of recipe cards.
class RecipeGridPage extends StatefulWidget {
RecipeGridPage({ Key key, this.recipes }) : super(key: key);
const RecipeGridPage({ Key key, this.recipes }) : super(key: key);
final List<Recipe> recipes;
@@ -180,7 +180,7 @@ class _RecipeGridPageState extends State<RecipeGridPage> {
}
class PestoLogo extends StatefulWidget {
PestoLogo({this.height, this.t});
const PestoLogo({this.height, this.t});
final double height;
final double t;
@@ -239,7 +239,7 @@ class RecipeCard extends StatelessWidget {
final TextStyle titleStyle = const PestoStyle(fontSize: 24.0, fontWeight: FontWeight.w600);
final TextStyle authorStyle = const PestoStyle(fontWeight: FontWeight.w500, color: Colors.black54);
RecipeCard({ Key key, this.recipe, this.onTap }) : super(key: key);
const RecipeCard({ Key key, this.recipe, this.onTap }) : super(key: key);
final Recipe recipe;
final VoidCallback onTap;
@@ -289,7 +289,7 @@ class RecipeCard extends StatelessWidget {
// Displays one recipe. Includes the recipe sheet with a background image.
class RecipePage extends StatefulWidget {
RecipePage({ Key key, this.recipe }) : super(key: key);
const RecipePage({ Key key, this.recipe }) : super(key: key);
final Recipe recipe;

View File

@@ -148,9 +148,9 @@ class _VendorItem extends StatelessWidget {
// Displays the product's price. If the product is in the shopping cart then the
// background is highlighted.
abstract class _PriceItem extends StatelessWidget {
_PriceItem({ Key key, @required this.product }) : super(key: key) {
assert(product != null);
}
const _PriceItem({ Key key, @required this.product })
: assert(product != null),
super(key: key);
final Product product;
@@ -168,7 +168,7 @@ abstract class _PriceItem extends StatelessWidget {
}
class _ProductPriceItem extends _PriceItem {
_ProductPriceItem({ Key key, Product product }) : super(key: key, product: product);
const _ProductPriceItem({ Key key, Product product }) : super(key: key, product: product);
@override
Widget build(BuildContext context) {
@@ -181,7 +181,7 @@ class _ProductPriceItem extends _PriceItem {
}
class _FeaturePriceItem extends _PriceItem {
_FeaturePriceItem({ Key key, Product product }) : super(key: key, product: product);
const _FeaturePriceItem({ Key key, Product product }) : super(key: key, product: product);
@override
Widget build(BuildContext context) {

View File

@@ -32,7 +32,7 @@ final ThemeData _kGalleryDarkTheme = new ThemeData(
);
class GalleryApp extends StatefulWidget {
GalleryApp({
const GalleryApp({
this.updateUrlFetcher,
this.enablePerformanceOverlay: true,
this.checkerboardRasterCacheImages: true,

View File

@@ -33,7 +33,7 @@ class ComponentDemoTabData {
}
class TabbedComponentDemoScaffold extends StatelessWidget {
TabbedComponentDemoScaffold({
const TabbedComponentDemoScaffold({
this.title,
this.demos
});
@@ -96,7 +96,7 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
}
class FullScreenCodeDialog extends StatefulWidget {
FullScreenCodeDialog({ this.exampleCodeTag });
const FullScreenCodeDialog({ this.exampleCodeTag });
final String exampleCodeTag;

View File

@@ -25,7 +25,7 @@ new RaisedButton(
// Create a disabled button.
// Buttons are disabled when onPressed isn't
// specified or is null.
new RaisedButton(
const RaisedButton(
child: const Text('BUTTON TITLE'),
onPressed: null
);
@@ -130,7 +130,7 @@ new Checkbox(
// Create a disabled checkbox.
// Checkboxes are disabled when onChanged isn't
// specified or null.
new Checkbox(value: false, onChanged: null);
const Checkbox(value: false, onChanged: null);
// END
@@ -167,7 +167,7 @@ new Row(
);
// Creates a disabled radio button.
new Radio<int>(
const Radio<int>(
value: 0,
groupValue: 0,
onChanged: null

View File

@@ -36,7 +36,7 @@ final List<_BackgroundLayer> _kBackgroundLayers = <_BackgroundLayer>[
];
class _AppBarBackground extends StatelessWidget {
_AppBarBackground({ Key key, this.animation }) : super(key: key);
const _AppBarBackground({ Key key, this.animation }) : super(key: key);
final Animation<double> animation;

View File

@@ -73,7 +73,7 @@ List<GalleryItem> _buildGalleryItems() {
subtitle: 'Section organizer',
category: 'Demos',
routeName: AnimationDemo.routeName,
buildRoute: (BuildContext context) => new AnimationDemo(),
buildRoute: (BuildContext context) => const AnimationDemo(),
),
// Material Components
new GalleryItem(
@@ -151,7 +151,7 @@ List<GalleryItem> _buildGalleryItems() {
subtitle: 'Row and column layout',
category: 'Material Components',
routeName: GridListDemo.routeName,
buildRoute: (BuildContext context) => new GridListDemo(),
buildRoute: (BuildContext context) => const GridListDemo(),
),
new GalleryItem(
title: 'Icons',
@@ -165,21 +165,21 @@ List<GalleryItem> _buildGalleryItems() {
subtitle: 'List items with hidden actions',
category: 'Material Components',
routeName: LeaveBehindDemo.routeName,
buildRoute: (BuildContext context) => new LeaveBehindDemo(),
buildRoute: (BuildContext context) => const LeaveBehindDemo(),
),
new GalleryItem(
title: 'List',
subtitle: 'Layout variations for scrollable lists',
category: 'Material Components',
routeName: ListDemo.routeName,
buildRoute: (BuildContext context) => new ListDemo(),
buildRoute: (BuildContext context) => const ListDemo(),
),
new GalleryItem(
title: 'Menus',
subtitle: 'Menu buttons and simple menus',
category: 'Material Components',
routeName: MenuDemo.routeName,
buildRoute: (BuildContext context) => new MenuDemo(),
buildRoute: (BuildContext context) => const MenuDemo(),
),
new GalleryItem(
title: 'Modal bottom sheet',
@@ -214,7 +214,7 @@ List<GalleryItem> _buildGalleryItems() {
subtitle: 'Refresh indicators',
category: 'Material Components',
routeName: OverscrollDemo.routeName,
buildRoute: (BuildContext context) => new OverscrollDemo(),
buildRoute: (BuildContext context) => const OverscrollDemo(),
),
new GalleryItem(
title: 'Scrollable tabs',
@@ -242,7 +242,7 @@ List<GalleryItem> _buildGalleryItems() {
subtitle: 'Temporary message that appears at the bottom',
category: 'Material Components',
routeName: SnackBarDemo.routeName,
buildRoute: (BuildContext context) => new SnackBarDemo(),
buildRoute: (BuildContext context) => const SnackBarDemo(),
),
new GalleryItem(
title: 'Tabs',
@@ -256,7 +256,7 @@ List<GalleryItem> _buildGalleryItems() {
subtitle: 'Single line of editable text and numbers',
category: 'Material Components',
routeName: TextFormFieldDemo.routeName,
buildRoute: (BuildContext context) => new TextFormFieldDemo(),
buildRoute: (BuildContext context) => const TextFormFieldDemo(),
),
new GalleryItem(
title: 'Tooltips',
@@ -327,7 +327,7 @@ List<GalleryItem> _buildGalleryItems() {
subtitle: 'Simple recipe browser',
category: 'Demos',
routeName: PestoDemo.routeName,
buildRoute: (BuildContext context) => new PestoDemo(),
buildRoute: (BuildContext context) => const PestoDemo(),
),
);
return true;

View File

@@ -10,5 +10,5 @@ import 'package:flutter/widgets.dart';
import 'gallery/app.dart';
void main() {
runApp(new GalleryApp());
runApp(const GalleryApp());
}

View File

@@ -14,7 +14,7 @@ void main() {
// We press the "1" and the "2" buttons and check that the display
// reads "12".
testWidgets('Flutter calculator app smoke test', (WidgetTester tester) async {
await tester.pumpWidget(new CalculatorDemo());
await tester.pumpWidget(const CalculatorDemo());
final Finder oneButton = find.widgetWithText(InkResponse, '1');
expect(oneButton, findsOneWidget);

View File

@@ -14,7 +14,7 @@ void main() {
testWidgets('Flutter gallery button example code displays', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/6147
await tester.pumpWidget(new GalleryApp());
await tester.pumpWidget(const GalleryApp());
await tester.pump(); // see https://github.com/flutter/flutter/issues/1865
await tester.pump(); // triggers a frame

View File

@@ -15,11 +15,11 @@ void main() {
testWidgets('Pesto appbar heroics', (WidgetTester tester) async {
await tester.pumpWidget(
// The bug only manifests itself when the screen's orientation is portrait
new Center(
child: new SizedBox(
const Center(
child: const SizedBox(
width: 400.0,
height: 800.0,
child: new GalleryApp()
child: const GalleryApp()
)
)
);
@@ -43,7 +43,7 @@ void main() {
});
testWidgets('Pesto can be scrolled all the way down', (WidgetTester tester) async {
await tester.pumpWidget(new GalleryApp());
await tester.pumpWidget(const GalleryApp());
await tester.pump(); // see https://github.com/flutter/flutter/issues/1865
await tester.tap(find.text('Pesto'));

View File

@@ -17,7 +17,7 @@ void main() {
// Regression test for https://github.com/flutter/flutter/pull/5168
testWidgets('update dialog', (WidgetTester tester) async {
await tester.pumpWidget(new GalleryApp(updateUrlFetcher: mockUpdateUrlFetcher));
await tester.pumpWidget(const GalleryApp(updateUrlFetcher: mockUpdateUrlFetcher));
await tester.pump(); // see https://github.com/flutter/flutter/issues/1865
await tester.pump(); // triggers a frame

View File

@@ -39,12 +39,12 @@ class RenderDots extends RenderConstrainedBox {
}
class Dots extends SingleChildRenderObjectWidget {
Dots({ Key key, Widget child }) : super(key: key, child: child);
const Dots({ Key key, Widget child }) : super(key: key, child: child);
@override
RenderDots createRenderObject(BuildContext context) => new RenderDots();
}
void main() {
runApp(new Dots(child: const Center(child: const Text('Touch me!'))));
runApp(const Dots(child: const Center(child: const Text('Touch me!'))));
}

View File

@@ -5,7 +5,7 @@
import 'package:flutter/material.dart';
class AdaptedListItem extends StatelessWidget {
AdaptedListItem({ Key key, this.name }) : super(key: key);
const AdaptedListItem({ Key key, this.name }) : super(key: key);
final String name;
@@ -28,7 +28,7 @@ class AdaptedListItem extends StatelessWidget {
}
class AdaptedGridItem extends StatelessWidget {
AdaptedGridItem({ Key key, this.name }) : super(key: key);
const AdaptedGridItem({ Key key, this.name }) : super(key: key);
final String name;
@@ -69,7 +69,7 @@ const double _kMaxTileWidth = 150.0;
const double _kGridViewBreakpoint = 450.0;
class AdaptiveContainer extends StatelessWidget {
AdaptiveContainer({ Key key, this.names }) : super(key: key);
const AdaptiveContainer({ Key key, this.names }) : super(key: key);
final List<String> names;

View File

@@ -17,7 +17,7 @@ void addFlexChildSolidColor(RenderFlex parent, Color backgroundColor, { int flex
// Solid colour, Widget version
class Rectangle extends StatelessWidget {
Rectangle(this.color, { Key key }) : super(key: key);
const Rectangle(this.color, { Key key }) : super(key: key);
final Color color;
@@ -41,7 +41,7 @@ void attachWidgetTreeToRenderTree(RenderProxyBox container) {
height: 300.0,
child: new Column(
children: <Widget>[
new Rectangle(const Color(0xFF00FFFF)),
const Rectangle(const Color(0xFF00FFFF)),
new Material(
child: new Container(
padding: const EdgeInsets.all(10.0),
@@ -66,7 +66,7 @@ void attachWidgetTreeToRenderTree(RenderProxyBox container) {
)
)
),
new Rectangle(const Color(0xFFFFFF00)),
const Rectangle(const Color(0xFFFFFF00)),
],
mainAxisAlignment: MainAxisAlignment.spaceBetween
)

View File

@@ -53,7 +53,7 @@ class StockArrowPainter extends CustomPainter {
}
class StockArrow extends StatelessWidget {
StockArrow({ Key key, this.percentChange }) : super(key: key);
const StockArrow({ Key key, this.percentChange }) : super(key: key);
final double percentChange;

View File

@@ -345,7 +345,7 @@ class _CreateCompanySheet extends StatelessWidget {
// TODO(ianh): Fill this out.
return new Column(
children: <Widget>[
new TextField(
const TextField(
autofocus: true,
decoration: const InputDecoration(
hintText: 'Company Name',

View File

@@ -8,7 +8,7 @@ import 'stock_data.dart';
import 'stock_row.dart';
class StockList extends StatelessWidget {
StockList({ Key key, this.stocks, this.onOpen, this.onShow, this.onAction }) : super(key: key);
const StockList({ Key key, this.stocks, this.onOpen, this.onShow, this.onAction }) : super(key: key);
final List<Stock> stocks;
final StockRowActionCallback onOpen;

View File

@@ -8,7 +8,7 @@ import 'stock_arrow.dart';
import 'stock_data.dart';
class _StockSymbolView extends StatelessWidget {
_StockSymbolView({ this.stock, this.arrow });
const _StockSymbolView({ this.stock, this.arrow });
final Stock stock;
final Widget arrow;
@@ -63,7 +63,7 @@ class _StockSymbolView extends StatelessWidget {
}
class StockSymbolPage extends StatelessWidget {
StockSymbolPage({ this.stock });
const StockSymbolPage({ this.stock });
final Stock stock;
@@ -92,7 +92,7 @@ class StockSymbolPage extends StatelessWidget {
}
class StockSymbolBottomSheet extends StatelessWidget {
StockSymbolBottomSheet({ this.stock });
const StockSymbolBottomSheet({ this.stock });
final Stock stock;