Skip to content

Commit

Permalink
Use super.key instead of manually passing the Key parameter to the pa…
Browse files Browse the repository at this point in the history
…rent 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)
  • Loading branch information
EchoEllet authored May 13, 2024
1 parent 3391ddf commit 876aa48
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions examples/api/lib/widgets/scroll_view/list_view.1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 2 additions & 3 deletions packages/flutter/lib/src/widgets/dismissible.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
///
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/widgets/overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/widgets/reorderable_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions packages/flutter/lib/src/widgets/unique_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/test/widgets/automatic_keep_alive_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/test/widgets/reparent_state_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 876aa48

Please sign in to comment.