Commit c9b94e14 authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

enable lint prefer_const_constructors_in_immutables (#12693)

* enable lint prefer_const_constructors_in_immutables

* remove LabeledGlobalKey._
parent 28366002
...@@ -113,7 +113,7 @@ linter: ...@@ -113,7 +113,7 @@ linter:
- prefer_collection_literals - prefer_collection_literals
- prefer_conditional_assignment - prefer_conditional_assignment
- prefer_const_constructors - 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_constructors_over_static_methods # not yet tested
- prefer_contains - 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 # - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
......
...@@ -107,7 +107,7 @@ linter: ...@@ -107,7 +107,7 @@ linter:
- prefer_collection_literals - prefer_collection_literals
- prefer_conditional_assignment - prefer_conditional_assignment
- prefer_const_constructors - 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_constructors_over_static_methods # not yet tested
- prefer_contains - 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 # - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
......
...@@ -172,7 +172,7 @@ class _CupertinoTabScaffoldState extends State<CupertinoTabScaffold> { ...@@ -172,7 +172,7 @@ class _CupertinoTabScaffoldState extends State<CupertinoTabScaffold> {
/// An widget laying out multiple tabs with only one active tab being built /// 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. /// at a time and on stage. Off stage tabs' animations are stopped.
class _TabView extends StatefulWidget { class _TabView extends StatefulWidget {
_TabView({ const _TabView({
@required this.currentTabIndex, @required this.currentTabIndex,
@required this.tabNumber, @required this.tabNumber,
@required this.tabBuilder, @required this.tabBuilder,
......
...@@ -124,7 +124,7 @@ class BottomNavigationBar extends StatefulWidget { ...@@ -124,7 +124,7 @@ class BottomNavigationBar extends StatefulWidget {
// This represents a single tile in the bottom navigation bar. It is intended // This represents a single tile in the bottom navigation bar. It is intended
// to go into a flex container. // to go into a flex container.
class _BottomNavigationTile extends StatelessWidget { class _BottomNavigationTile extends StatelessWidget {
_BottomNavigationTile( const _BottomNavigationTile(
this.type, this.type,
this.item, this.item,
this.animation, this.animation,
......
...@@ -158,7 +158,7 @@ class _DatePickerHeader extends StatelessWidget { ...@@ -158,7 +158,7 @@ class _DatePickerHeader extends StatelessWidget {
} }
class _DateHeaderButton extends StatelessWidget { class _DateHeaderButton extends StatelessWidget {
_DateHeaderButton({ const _DateHeaderButton({
Key key, Key key,
this.onTap, this.onTap,
this.color, this.color,
......
...@@ -617,7 +617,7 @@ class _MergeableMaterialState extends State<MergeableMaterial> with TickerProvid ...@@ -617,7 +617,7 @@ class _MergeableMaterialState extends State<MergeableMaterial> with TickerProvid
// The parent hierarchy can change and lead to the slice being // The parent hierarchy can change and lead to the slice being
// rebuilt. Using a global key solves the issue. // rebuilt. Using a global key solves the issue.
class _MergeableMaterialSliceKey extends GlobalKey { class _MergeableMaterialSliceKey extends GlobalKey {
_MergeableMaterialSliceKey(this.value) : super.constructor(); const _MergeableMaterialSliceKey(this.value) : super.constructor();
final LocalKey value; final LocalKey value;
......
...@@ -433,7 +433,7 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget { ...@@ -433,7 +433,7 @@ class TabBar extends StatefulWidget implements PreferredSizeWidget {
/// The [indicatorWeight] parameter defaults to 2, and must not be null. /// The [indicatorWeight] parameter defaults to 2, and must not be null.
/// ///
/// The [indicatorPadding] parameter defaults to [EdgeInsets.zero], and must not be null. /// The [indicatorPadding] parameter defaults to [EdgeInsets.zero], and must not be null.
TabBar({ const TabBar({
Key key, Key key,
@required this.tabs, @required this.tabs,
this.controller, this.controller,
...@@ -812,7 +812,7 @@ class TabBarView extends StatefulWidget { ...@@ -812,7 +812,7 @@ class TabBarView extends StatefulWidget {
/// Creates a page view with one child per tab. /// Creates a page view with one child per tab.
/// ///
/// The length of [children] must be the same as the [controller]'s length. /// The length of [children] must be the same as the [controller]'s length.
TabBarView({ const TabBarView({
Key key, Key key,
@required this.children, @required this.children,
this.controller, this.controller,
......
...@@ -139,7 +139,7 @@ class RoundedRectangleBorder extends ShapeBorder { ...@@ -139,7 +139,7 @@ class RoundedRectangleBorder extends ShapeBorder {
} }
class _RoundedRectangleToCircleBorder extends ShapeBorder { class _RoundedRectangleToCircleBorder extends ShapeBorder {
_RoundedRectangleToCircleBorder({ const _RoundedRectangleToCircleBorder({
this.side: BorderSide.none, this.side: BorderSide.none,
this.borderRadius: BorderRadius.zero, this.borderRadius: BorderRadius.zero,
@required this.circleness, @required this.circleness,
......
...@@ -110,6 +110,7 @@ class _TypeLiteral<T> { Type get type => T; } ...@@ -110,6 +110,7 @@ class _TypeLiteral<T> { Type get type => T; }
/// A key that is only equal to itself. /// A key that is only equal to itself.
class UniqueKey extends LocalKey { class UniqueKey extends LocalKey {
/// Creates a key that is equal only to itself. /// Creates a key that is equal only to itself.
// ignore: prefer_const_constructors_in_immutables , never use const for this class
UniqueKey(); UniqueKey();
@override @override
...@@ -175,7 +176,7 @@ abstract class GlobalKey<T extends State<StatefulWidget>> extends Key { ...@@ -175,7 +176,7 @@ abstract class GlobalKey<T extends State<StatefulWidget>> extends Key {
/// ///
/// The label is purely for debugging and not used for comparing the identity /// The label is purely for debugging and not used for comparing the identity
/// of the key. /// of the key.
factory GlobalKey({ String debugLabel }) = LabeledGlobalKey<T>._; factory GlobalKey({ String debugLabel }) => new LabeledGlobalKey<T>(debugLabel);
/// Creates a global key without a label. /// Creates a global key without a label.
/// ///
...@@ -323,11 +324,9 @@ class LabeledGlobalKey<T extends State<StatefulWidget>> extends GlobalKey<T> { ...@@ -323,11 +324,9 @@ class LabeledGlobalKey<T extends State<StatefulWidget>> extends GlobalKey<T> {
/// Creates a global key with a debugging label. /// Creates a global key with a debugging label.
/// ///
/// The label does not affect the key's identity. /// 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(); LabeledGlobalKey(this._debugLabel) : super.constructor();
// Used for forwarding the constructor from GlobalKey.
LabeledGlobalKey._({ String debugLabel }) : _debugLabel = debugLabel, super.constructor();
final String _debugLabel; final String _debugLabel;
@override @override
......
...@@ -902,7 +902,7 @@ class KeepAlive extends ParentDataWidget<SliverMultiBoxAdaptorWidget> { ...@@ -902,7 +902,7 @@ class KeepAlive extends ParentDataWidget<SliverMultiBoxAdaptorWidget> {
/// Marks a child as needing to remain alive. /// Marks a child as needing to remain alive.
/// ///
/// The [child] and [keepAlive] arguments must not be null. /// The [child] and [keepAlive] arguments must not be null.
KeepAlive({ const KeepAlive({
Key key, Key key,
@required this.keepAlive, @required this.keepAlive,
@required Widget child, @required Widget child,
......
...@@ -139,7 +139,7 @@ void main () { ...@@ -139,7 +139,7 @@ void main () {
class TestWidget extends StatelessWidget { class TestWidget extends StatelessWidget {
TestWidget({ const TestWidget({
this.tapHandler: nullHandler, this.tapHandler: nullHandler,
this.longPressHandler: nullHandler, this.longPressHandler: nullHandler,
}); });
......
...@@ -7,7 +7,7 @@ import 'package:flutter/widgets.dart'; ...@@ -7,7 +7,7 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
class Leaf extends StatefulWidget { class Leaf extends StatefulWidget {
Leaf({ Key key, this.child }) : super(key: key); const Leaf({ Key key, this.child }) : super(key: key);
final Widget child; final Widget child;
@override @override
_LeafState createState() => new _LeafState(); _LeafState createState() => new _LeafState();
...@@ -222,8 +222,8 @@ void main() { ...@@ -222,8 +222,8 @@ void main() {
child: new Container( child: new Container(
height: 400.0, height: 400.0,
child: new Stack(children: <Widget>[ child: new Stack(children: <Widget>[
new Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()), const 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>(1), child: const Placeholder()),
]), ]),
), ),
), ),
...@@ -298,8 +298,8 @@ void main() { ...@@ -298,8 +298,8 @@ void main() {
child: new Container( child: new Container(
height: 400.0, height: 400.0,
child: new Stack(children: <Widget>[ child: new Stack(children: <Widget>[
new Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()), const 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>(1), child: const Placeholder()),
]), ]),
), ),
), ),
...@@ -307,8 +307,8 @@ void main() { ...@@ -307,8 +307,8 @@ void main() {
child: new Container( child: new Container(
height: 400.0, height: 400.0,
child: new Stack(children: <Widget>[ child: new Stack(children: <Widget>[
new Leaf(key: const GlobalObjectKey<_LeafState>(2), child: const Placeholder()), const 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>(3), child: const Placeholder()),
]), ]),
), ),
), ),
...@@ -316,8 +316,8 @@ void main() { ...@@ -316,8 +316,8 @@ void main() {
child: new Container( child: new Container(
height: 400.0, height: 400.0,
child: new Stack(children: <Widget>[ child: new Stack(children: <Widget>[
new Leaf(key: const GlobalObjectKey<_LeafState>(4), child: const Placeholder()), const 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>(5), child: const Placeholder()),
]), ]),
), ),
), ),
...@@ -350,7 +350,7 @@ void main() { ...@@ -350,7 +350,7 @@ void main() {
child: new Container( child: new Container(
height: 400.0, height: 400.0,
child: new Stack(children: <Widget>[ child: new Stack(children: <Widget>[
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() { ...@@ -358,8 +358,8 @@ void main() {
child: new Container( child: new Container(
height: 400.0, height: 400.0,
child: new Stack(children: <Widget>[ child: new Stack(children: <Widget>[
new Leaf(key: const GlobalObjectKey<_LeafState>(2), child: const Placeholder()), const 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>(3), child: const Placeholder()),
]), ]),
), ),
), ),
...@@ -367,9 +367,9 @@ void main() { ...@@ -367,9 +367,9 @@ void main() {
child: new Container( child: new Container(
height: 400.0, height: 400.0,
child: new Stack(children: <Widget>[ child: new Stack(children: <Widget>[
new Leaf(key: const GlobalObjectKey<_LeafState>(4), child: const Placeholder()), const 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>(5), child: const Placeholder()),
new Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()), const Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()),
]), ]),
), ),
), ),
...@@ -409,8 +409,8 @@ void main() { ...@@ -409,8 +409,8 @@ void main() {
child: new Container( child: new Container(
height: 400.0, height: 400.0,
child: new Stack(children: <Widget>[ child: new Stack(children: <Widget>[
new Leaf(key: const GlobalObjectKey<_LeafState>(1), child: const Placeholder()), const 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>(2), child: const Placeholder()),
]), ]),
), ),
), ),
...@@ -425,10 +425,10 @@ void main() { ...@@ -425,10 +425,10 @@ void main() {
child: new Container( child: new Container(
height: 400.0, height: 400.0,
child: new Stack(children: <Widget>[ child: new Stack(children: <Widget>[
new Leaf(key: const GlobalObjectKey<_LeafState>(3), child: const Placeholder()), const Leaf(key: const GlobalObjectKey<_LeafState>(3), child: const Placeholder()),
new Leaf(key: const GlobalObjectKey<_LeafState>(4), child: const Placeholder()), const 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>(5), child: const Placeholder()),
new Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()), const Leaf(key: const GlobalObjectKey<_LeafState>(0), child: const Placeholder()),
]), ]),
), ),
), ),
......
...@@ -8,7 +8,7 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -8,7 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
class Leaf extends StatefulWidget { class Leaf extends StatefulWidget {
Leaf({ Key key, this.child }) : super(key: key); const Leaf({ Key key, this.child }) : super(key: key);
final Widget child; final Widget child;
@override @override
_LeafState createState() => new _LeafState(); _LeafState createState() => new _LeafState();
......
...@@ -37,7 +37,7 @@ Widget buildTest({ ScrollController controller, String title:'TTTTTTTT' }) { ...@@ -37,7 +37,7 @@ Widget buildTest({ ScrollController controller, String title:'TTTTTTTT' }) {
pinned: true, pinned: true,
expandedHeight: 200.0, expandedHeight: 200.0,
forceElevated: innerBoxIsScrolled, forceElevated: innerBoxIsScrolled,
bottom: new TabBar( bottom: const TabBar(
tabs: const <Tab>[ tabs: const <Tab>[
const Tab(text: 'AA'), const Tab(text: 'AA'),
const Tab(text: 'BB'), const Tab(text: 'BB'),
......
...@@ -11,11 +11,11 @@ void main() { ...@@ -11,11 +11,11 @@ void main() {
await tester.pumpWidget(new MaterialApp( // Creates the outer Localizations widget. await tester.pumpWidget(new MaterialApp( // Creates the outer Localizations widget.
home: new ListView( home: new ListView(
children: <Widget>[ children: <Widget>[
new LocalizationTracker(key: const ValueKey<String>('outer')), const LocalizationTracker(key: const ValueKey<String>('outer')),
new Localizations( new Localizations(
locale: const Locale('zh', 'CN'), locale: const Locale('zh', 'CN'),
delegates: GlobalMaterialLocalizations.delegates, delegates: GlobalMaterialLocalizations.delegates,
child: new LocalizationTracker(key: const ValueKey<String>('inner')), child: const LocalizationTracker(key: const ValueKey<String>('inner')),
), ),
], ],
), ),
...@@ -65,7 +65,7 @@ class _DummyLocalizationsDelegate extends LocalizationsDelegate<DummyLocalizatio ...@@ -65,7 +65,7 @@ class _DummyLocalizationsDelegate extends LocalizationsDelegate<DummyLocalizatio
class DummyLocalizations {} class DummyLocalizations {}
class LocalizationTracker extends StatefulWidget { class LocalizationTracker extends StatefulWidget {
LocalizationTracker({Key key}) : super(key: key); const LocalizationTracker({Key key}) : super(key: key);
@override @override
State<StatefulWidget> createState() => new LocalizationTrackerState(); State<StatefulWidget> createState() => new LocalizationTrackerState();
......
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