Description
Is your feature request related to a problem? Please describe.
Often I need to extract a bigger piece of widget tree to a widget that exposes a single child
property. This may not be entire subtree but some part of it e.g. from A->B->C->D
I want to get to A->B'->D
. To achieve that I create a new widget with child
property and copy and paste part of the tree that needs to wrap this child. For example starting with following:
import 'package:flutter/material.dart';
class ExampleParent extends StatelessWidget {
const ExampleParent({super.key});
@override
Widget build(BuildContext context) {
return const SizedBox(
width: 400,
height: 200,
child: ColoredBox(
color: Color(0xFF00AA00),
child: Text('Example'),
),
);
}
}
I end up with this structure:
import 'package:flutter/material.dart';
class ExampleParent extends StatelessWidget {
const ExampleParent({super.key});
@override
Widget build(BuildContext context) {
return const SizedColoredBox(
child: Text('Example'),
);
}
}
class SizedColoredBox extends StatelessWidget {
const SizedColoredBox({super.key, required this.child});
final Widget child;
@override
Widget build(BuildContext context) {
return SizedBox(
width: 400,
height: 200,
child: ColoredBox(
color: const Color(0xFF00AA00),
child: child,
),
);
}
}
Describe the solution you'd like
I would like to have ability to wrap any widget with a single child wrapper widget similarly as I can extract part of subtree to a new widget.
Describe alternatives you've considered
- Doing this manually
- Extracting entire subtree and reverting this change partially
Additional context
Copied from Dart-Code/Dart-Code#4566 as requested by @johnpryan