Skip to content

Remove rebuild that looked unnecessary #174302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/flutter/lib/src/widgets/framework.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6016,7 +6016,6 @@ class StatefulElement extends ComponentElement {
// resources allocated in the build method, we have to rebuild the widget
// so that its State can reallocate its resources.
assert(_lifecycleState == _ElementLifecycle.active); // otherwise markNeedsBuild is a no-op
markNeedsBuild();
}

@override
Expand Down
41 changes: 0 additions & 41 deletions packages/flutter/test/widgets/reparent_state_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,6 @@ class StateMarkerState extends State<StateMarker> {
}
}

class DeactivateLogger extends StatefulWidget {
const DeactivateLogger({required Key super.key, required this.log});

final List<String> log;

@override
DeactivateLoggerState createState() => DeactivateLoggerState();
}

class DeactivateLoggerState extends State<DeactivateLogger> {
@override
void deactivate() {
widget.log.add('deactivate');
super.deactivate();
}

@override
Widget build(BuildContext context) {
widget.log.add('build');
return Container();
}
}

void main() {
testWidgets('can reparent state', (WidgetTester tester) async {
final GlobalKey left = GlobalKey();
Expand Down Expand Up @@ -325,24 +302,6 @@ void main() {
expect(keyState.marker, equals('marked'));
});

testWidgets('Deactivate implies build', (WidgetTester tester) async {
final GlobalKey key = GlobalKey();
final List<String> log = <String>[];
final DeactivateLogger logger = DeactivateLogger(key: key, log: log);

await tester.pumpWidget(Container(key: UniqueKey(), child: logger));

expect(log, equals(<String>['build']));

await tester.pumpWidget(Container(key: UniqueKey(), child: logger));

expect(log, equals(<String>['build', 'deactivate', 'build']));
log.clear();

await tester.pump();
expect(log, isEmpty);
});

testWidgets('Reparenting with multiple moves', (WidgetTester tester) async {
final GlobalKey key1 = GlobalKey();
final GlobalKey key2 = GlobalKey();
Expand Down