Use super.key instead of manually passing the Key parameter to the parent class (#147621)

*Use `super.key` instead of manually passing the `Key` parameter using super(key: key) in the constructors.*

Since if you create a widget the new default will use `super.key` instead of `Key? key : super(key: key)` this small change is to maintain the consistency, it has no semantic change

also there are some other places that might need to be updated:

![image](https://github.com/flutter/flutter/assets/73608287/898f62f5-10f9-4d76-a46c-6def328177cb)

this file for example generate l10n project and it has all the dart code as String, it might have tests that validate the output somewhere that I might miss, also there are some other places like the `_Segment` class where it require `ValueKey` instead if `Key` so I didn't update them (even though it's possible)
This commit is contained in:
Ellet
2024-05-14 01:12:49 +03:00
committed by GitHub
parent 3391ddf55d
commit 876aa48ea5
8 changed files with 13 additions and 16 deletions

View File

@@ -74,9 +74,9 @@ class _ListViewExampleState extends State<ListViewExample> {
class KeepAliveItem extends StatefulWidget {
const KeepAliveItem({
required Key key,
required Key super.key,
required this.data,
}) : super(key: key);
});
final String data;

View File

@@ -97,7 +97,7 @@ class Dismissible extends StatefulWidget {
/// dismissed item. Using keys causes the widgets to sync according to their
/// keys and avoids this pitfall.
const Dismissible({
required Key key,
required Key super.key,
required this.child,
this.background,
this.secondaryBackground,
@@ -112,8 +112,7 @@ class Dismissible extends StatefulWidget {
this.crossAxisEndOffset = 0.0,
this.dragStartBehavior = DragStartBehavior.start,
this.behavior = HitTestBehavior.opaque,
}) : assert(secondaryBackground == null || background != null),
super(key: key);
}) : assert(secondaryBackground == null || background != null);
/// The widget below this widget in the tree.
///

View File

@@ -273,11 +273,11 @@ class OverlayEntry implements Listenable {
class _OverlayEntryWidget extends StatefulWidget {
const _OverlayEntryWidget({
required Key key,
required Key super.key,
required this.entry,
required this.overlayState,
this.tickerEnabled = true,
}) : super(key: key);
});
final OverlayEntry entry;
final OverlayState overlayState;

View File

@@ -1050,11 +1050,11 @@ class SliverReorderableListState extends State<SliverReorderableList> with Ticke
class _ReorderableItem extends StatefulWidget {
const _ReorderableItem({
required Key key,
required Key super.key,
required this.index,
required this.child,
required this.capturedThemes,
}) : super(key: key);
});
final int index;
final Widget child;

View File

@@ -22,9 +22,7 @@ abstract class UniqueWidget<T extends State<StatefulWidget>> extends StatefulWid
///
/// The [key] argument is required because it identifies the unique inflated
/// instance of this widget.
const UniqueWidget({
required GlobalKey<T> key,
}) : super(key: key);
const UniqueWidget({required GlobalKey<T> super.key});
@override
T createState();

View File

@@ -9,7 +9,7 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
class Leaf extends StatefulWidget {
const Leaf({ required Key key, required this.child }) : super(key: key);
const Leaf({ required Key super.key, required this.child });
final Widget child;
@override
State<Leaf> createState() => _LeafState();
@@ -584,7 +584,7 @@ void main() {
}
class _AlwaysKeepAlive extends StatefulWidget {
const _AlwaysKeepAlive({ required Key key }) : super(key: key);
const _AlwaysKeepAlive({ required Key super.key });
@override
State<StatefulWidget> createState() => _AlwaysKeepAliveState();

View File

@@ -88,7 +88,7 @@ void main() {
}
class _DeferringWidget extends StatefulWidget {
const _DeferringWidget({required Key key, required this.loader}) : super(key: key);
const _DeferringWidget({required Key super.key, required this.loader});
final Future<void> loader;

View File

@@ -24,7 +24,7 @@ class StateMarkerState extends State<StateMarker> {
}
class DeactivateLogger extends StatefulWidget {
const DeactivateLogger({ required Key key, required this.log }) : super(key: key);
const DeactivateLogger({ required Key super.key, required this.log });
final List<String> log;