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:
- 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
......
......@@ -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
......
......@@ -172,7 +172,7 @@ class _CupertinoTabScaffoldState extends State<CupertinoTabScaffold> {
/// 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,
......
......@@ -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,
......
......@@ -158,7 +158,7 @@ class _DatePickerHeader extends StatelessWidget {
}
class _DateHeaderButton extends StatelessWidget {
_DateHeaderButton({
const _DateHeaderButton({
Key key,
this.onTap,
this.color,
......
......@@ -617,7 +617,7 @@ class _MergeableMaterialState extends State<MergeableMaterial> 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;
......
......@@ -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,
......
......@@ -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,
......
......@@ -110,6 +110,7 @@ class _TypeLiteral<T> { 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<T extends State<StatefulWidget>> extends Key {
///
/// The label is purely for debugging and not used for comparing the identity
/// of the key.
factory GlobalKey({ String debugLabel }) = LabeledGlobalKey<T>._;
factory GlobalKey({ String debugLabel }) => new LabeledGlobalKey<T>(debugLabel);
/// Creates a global key without a label.
///
......@@ -323,11 +324,9 @@ class LabeledGlobalKey<T extends State<StatefulWidget>> extends GlobalKey<T> {
/// 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
......
......@@ -902,7 +902,7 @@ class KeepAlive extends ParentDataWidget<SliverMultiBoxAdaptorWidget> {
/// 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,
......
......@@ -139,7 +139,7 @@ void main () {
class TestWidget extends StatelessWidget {
TestWidget({
const TestWidget({
this.tapHandler: nullHandler,
this.longPressHandler: nullHandler,
});
......
......@@ -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: <Widget>[
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: <Widget>[
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: <Widget>[
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: <Widget>[
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: <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() {
child: new Container(
height: 400.0,
child: new Stack(children: <Widget>[
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: <Widget>[
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: <Widget>[
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: <Widget>[
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()),
]),
),
),
......
......@@ -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();
......
......@@ -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 <Tab>[
const Tab(text: 'AA'),
const Tab(text: 'BB'),
......
......@@ -11,11 +11,11 @@ void main() {
await tester.pumpWidget(new MaterialApp( // Creates the outer Localizations widget.
home: new ListView(
children: <Widget>[
new LocalizationTracker(key: const ValueKey<String>('outer')),
const LocalizationTracker(key: const ValueKey<String>('outer')),
new Localizations(
locale: const Locale('zh', 'CN'),
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
class DummyLocalizations {}
class LocalizationTracker extends StatefulWidget {
LocalizationTracker({Key key}) : super(key: key);
const LocalizationTracker({Key key}) : super(key: key);
@override
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