diff --git a/analysis_options.yaml b/analysis_options.yaml index 35b9e47300..3c2c466e20 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -113,7 +113,7 @@ linter: - prefer_collection_literals - prefer_conditional_assignment - prefer_const_constructors - # - prefer_const_constructors_in_immutables # not yet tested + - prefer_const_constructors_in_immutables # - prefer_constructors_over_static_methods # not yet tested - prefer_contains # - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods diff --git a/analysis_options_repo.yaml b/analysis_options_repo.yaml index eacdb1a510..29dbefb14b 100644 --- a/analysis_options_repo.yaml +++ b/analysis_options_repo.yaml @@ -107,7 +107,7 @@ linter: - prefer_collection_literals - prefer_conditional_assignment - prefer_const_constructors - # - prefer_const_constructors_in_immutables # not yet tested + - prefer_const_constructors_in_immutables # - prefer_constructors_over_static_methods # not yet tested - prefer_contains # - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods diff --git a/packages/flutter/lib/src/cupertino/tab_scaffold.dart b/packages/flutter/lib/src/cupertino/tab_scaffold.dart index 63e1fb2300..53d3c5db7b 100644 --- a/packages/flutter/lib/src/cupertino/tab_scaffold.dart +++ b/packages/flutter/lib/src/cupertino/tab_scaffold.dart @@ -172,7 +172,7 @@ class _CupertinoTabScaffoldState extends State { /// An widget laying out multiple tabs with only one active tab being built /// at a time and on stage. Off stage tabs' animations are stopped. class _TabView extends StatefulWidget { - _TabView({ + const _TabView({ @required this.currentTabIndex, @required this.tabNumber, @required this.tabBuilder, diff --git a/packages/flutter/lib/src/material/bottom_navigation_bar.dart b/packages/flutter/lib/src/material/bottom_navigation_bar.dart index efa1e0dc07..5fd565b404 100644 --- a/packages/flutter/lib/src/material/bottom_navigation_bar.dart +++ b/packages/flutter/lib/src/material/bottom_navigation_bar.dart @@ -124,7 +124,7 @@ class BottomNavigationBar extends StatefulWidget { // This represents a single tile in the bottom navigation bar. It is intended // to go into a flex container. class _BottomNavigationTile extends StatelessWidget { - _BottomNavigationTile( + const _BottomNavigationTile( this.type, this.item, this.animation, diff --git a/packages/flutter/lib/src/material/date_picker.dart b/packages/flutter/lib/src/material/date_picker.dart index 60616e00c5..dff94601e1 100644 --- a/packages/flutter/lib/src/material/date_picker.dart +++ b/packages/flutter/lib/src/material/date_picker.dart @@ -158,7 +158,7 @@ class _DatePickerHeader extends StatelessWidget { } class _DateHeaderButton extends StatelessWidget { - _DateHeaderButton({ + const _DateHeaderButton({ Key key, this.onTap, this.color, diff --git a/packages/flutter/lib/src/material/mergeable_material.dart b/packages/flutter/lib/src/material/mergeable_material.dart index fa3a4aae69..822a14490e 100644 --- a/packages/flutter/lib/src/material/mergeable_material.dart +++ b/packages/flutter/lib/src/material/mergeable_material.dart @@ -617,7 +617,7 @@ class _MergeableMaterialState extends State with TickerProvid // The parent hierarchy can change and lead to the slice being // rebuilt. Using a global key solves the issue. class _MergeableMaterialSliceKey extends GlobalKey { - _MergeableMaterialSliceKey(this.value) : super.constructor(); + const _MergeableMaterialSliceKey(this.value) : super.constructor(); final LocalKey value; diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index c1be60ffa3..f5861b7012 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -433,7 +433,7 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget { /// The [indicatorWeight] parameter defaults to 2, and must not be null. /// /// The [indicatorPadding] parameter defaults to [EdgeInsets.zero], and must not be null. - TabBar({ + const TabBar({ Key key, @required this.tabs, this.controller, @@ -812,7 +812,7 @@ class TabBarView extends StatefulWidget { /// Creates a page view with one child per tab. /// /// The length of [children] must be the same as the [controller]'s length. - TabBarView({ + const TabBarView({ Key key, @required this.children, this.controller, diff --git a/packages/flutter/lib/src/painting/rounded_rectangle_border.dart b/packages/flutter/lib/src/painting/rounded_rectangle_border.dart index 2ade008afa..03213075b8 100644 --- a/packages/flutter/lib/src/painting/rounded_rectangle_border.dart +++ b/packages/flutter/lib/src/painting/rounded_rectangle_border.dart @@ -139,7 +139,7 @@ class RoundedRectangleBorder extends ShapeBorder { } class _RoundedRectangleToCircleBorder extends ShapeBorder { - _RoundedRectangleToCircleBorder({ + const _RoundedRectangleToCircleBorder({ this.side: BorderSide.none, this.borderRadius: BorderRadius.zero, @required this.circleness, diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 6a41ceb20b..b53577b0e5 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -110,6 +110,7 @@ class _TypeLiteral { Type get type => T; } /// A key that is only equal to itself. class UniqueKey extends LocalKey { /// Creates a key that is equal only to itself. + // ignore: prefer_const_constructors_in_immutables , never use const for this class UniqueKey(); @override @@ -175,7 +176,7 @@ abstract class GlobalKey> extends Key { /// /// The label is purely for debugging and not used for comparing the identity /// of the key. - factory GlobalKey({ String debugLabel }) = LabeledGlobalKey._; + factory GlobalKey({ String debugLabel }) => new LabeledGlobalKey(debugLabel); /// Creates a global key without a label. /// @@ -323,11 +324,9 @@ class LabeledGlobalKey> extends GlobalKey { /// Creates a global key with a debugging label. /// /// The label does not affect the key's identity. + // ignore: prefer_const_constructors_in_immutables , never use const for this class LabeledGlobalKey(this._debugLabel) : super.constructor(); - // Used for forwarding the constructor from GlobalKey. - LabeledGlobalKey._({ String debugLabel }) : _debugLabel = debugLabel, super.constructor(); - final String _debugLabel; @override diff --git a/packages/flutter/lib/src/widgets/sliver.dart b/packages/flutter/lib/src/widgets/sliver.dart index 3989656be2..52f66d04c4 100644 --- a/packages/flutter/lib/src/widgets/sliver.dart +++ b/packages/flutter/lib/src/widgets/sliver.dart @@ -902,7 +902,7 @@ class KeepAlive extends ParentDataWidget { /// Marks a child as needing to remain alive. /// /// The [child] and [keepAlive] arguments must not be null. - KeepAlive({ + const KeepAlive({ Key key, @required this.keepAlive, @required Widget child, diff --git a/packages/flutter/test/material/feedback_test.dart b/packages/flutter/test/material/feedback_test.dart index 9977316443..c741ab78c0 100644 --- a/packages/flutter/test/material/feedback_test.dart +++ b/packages/flutter/test/material/feedback_test.dart @@ -139,7 +139,7 @@ void main () { class TestWidget extends StatelessWidget { - TestWidget({ + const TestWidget({ this.tapHandler: nullHandler, this.longPressHandler: nullHandler, }); diff --git a/packages/flutter/test/widgets/automatic_keep_alive_test.dart b/packages/flutter/test/widgets/automatic_keep_alive_test.dart index a82e093bd0..17b9626a27 100644 --- a/packages/flutter/test/widgets/automatic_keep_alive_test.dart +++ b/packages/flutter/test/widgets/automatic_keep_alive_test.dart @@ -7,7 +7,7 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; class Leaf extends StatefulWidget { - Leaf({ Key key, this.child }) : super(key: key); + const Leaf({ Key key, this.child }) : super(key: key); final Widget child; @override _LeafState createState() => new _LeafState(); @@ -222,8 +222,8 @@ void main() { child: new Container( height: 400.0, child: new Stack(children: [ - new Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()), - new Leaf(key: const GlobalObjectKey<_LeafState>(1), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(1), child: const Placeholder()), ]), ), ), @@ -298,8 +298,8 @@ void main() { child: new Container( height: 400.0, child: new Stack(children: [ - new Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()), - new Leaf(key: const GlobalObjectKey<_LeafState>(1), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(1), child: const Placeholder()), ]), ), ), @@ -307,8 +307,8 @@ void main() { child: new Container( height: 400.0, child: new Stack(children: [ - new Leaf(key: const GlobalObjectKey<_LeafState>(2), child: const Placeholder()), - new Leaf(key: const GlobalObjectKey<_LeafState>(3), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(2), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(3), child: const Placeholder()), ]), ), ), @@ -316,8 +316,8 @@ void main() { child: new Container( height: 400.0, child: new Stack(children: [ - new Leaf(key: const GlobalObjectKey<_LeafState>(4), child: const Placeholder()), - new Leaf(key: const GlobalObjectKey<_LeafState>(5), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(4), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(5), child: const Placeholder()), ]), ), ), @@ -350,7 +350,7 @@ void main() { child: new Container( height: 400.0, child: new Stack(children: [ - new Leaf(key: const GlobalObjectKey<_LeafState>(1), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(1), child: const Placeholder()), ]), ), ), @@ -358,8 +358,8 @@ void main() { child: new Container( height: 400.0, child: new Stack(children: [ - new Leaf(key: const GlobalObjectKey<_LeafState>(2), child: const Placeholder()), - new Leaf(key: const GlobalObjectKey<_LeafState>(3), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(2), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(3), child: const Placeholder()), ]), ), ), @@ -367,9 +367,9 @@ void main() { child: new Container( height: 400.0, child: new Stack(children: [ - new Leaf(key: const GlobalObjectKey<_LeafState>(4), child: const Placeholder()), - new Leaf(key: const GlobalObjectKey<_LeafState>(5), child: const Placeholder()), - new Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(4), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(5), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()), ]), ), ), @@ -409,8 +409,8 @@ void main() { child: new Container( height: 400.0, child: new Stack(children: [ - new Leaf(key: const GlobalObjectKey<_LeafState>(1), child: const Placeholder()), - new Leaf(key: const GlobalObjectKey<_LeafState>(2), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(1), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(2), child: const Placeholder()), ]), ), ), @@ -425,10 +425,10 @@ void main() { child: new Container( height: 400.0, child: new Stack(children: [ - new Leaf(key: const GlobalObjectKey<_LeafState>(3), child: const Placeholder()), - new Leaf(key: const GlobalObjectKey<_LeafState>(4), child: const Placeholder()), - new Leaf(key: const GlobalObjectKey<_LeafState>(5), child: const Placeholder()), - new Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(3), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(4), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(5), child: const Placeholder()), + const Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()), ]), ), ), diff --git a/packages/flutter/test/widgets/keep_alive_test.dart b/packages/flutter/test/widgets/keep_alive_test.dart index baf455d8a9..6dbdc732a1 100644 --- a/packages/flutter/test/widgets/keep_alive_test.dart +++ b/packages/flutter/test/widgets/keep_alive_test.dart @@ -8,7 +8,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/widgets.dart'; class Leaf extends StatefulWidget { - Leaf({ Key key, this.child }) : super(key: key); + const Leaf({ Key key, this.child }) : super(key: key); final Widget child; @override _LeafState createState() => new _LeafState(); diff --git a/packages/flutter/test/widgets/nested_scroll_view_test.dart b/packages/flutter/test/widgets/nested_scroll_view_test.dart index 0d528fe18d..ec4fe92cc2 100644 --- a/packages/flutter/test/widgets/nested_scroll_view_test.dart +++ b/packages/flutter/test/widgets/nested_scroll_view_test.dart @@ -37,7 +37,7 @@ Widget buildTest({ ScrollController controller, String title:'TTTTTTTT' }) { pinned: true, expandedHeight: 200.0, forceElevated: innerBoxIsScrolled, - bottom: new TabBar( + bottom: const TabBar( tabs: const [ const Tab(text: 'AA'), const Tab(text: 'BB'), diff --git a/packages/flutter_localizations/test/basics_test.dart b/packages/flutter_localizations/test/basics_test.dart index 52d3c2b485..da81575e9c 100644 --- a/packages/flutter_localizations/test/basics_test.dart +++ b/packages/flutter_localizations/test/basics_test.dart @@ -11,11 +11,11 @@ void main() { await tester.pumpWidget(new MaterialApp( // Creates the outer Localizations widget. home: new ListView( children: [ - new LocalizationTracker(key: const ValueKey('outer')), + const LocalizationTracker(key: const ValueKey('outer')), new Localizations( locale: const Locale('zh', 'CN'), delegates: GlobalMaterialLocalizations.delegates, - child: new LocalizationTracker(key: const ValueKey('inner')), + child: const LocalizationTracker(key: const ValueKey('inner')), ), ], ), @@ -65,7 +65,7 @@ class _DummyLocalizationsDelegate extends LocalizationsDelegate createState() => new LocalizationTrackerState();