Skip to content

Feature Request - Extract and wrap with a single child widget #52567

Open
@orestesgaolin

Description

@orestesgaolin

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.

CleanShot 2023-05-30 at 16 02 05

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-refactoringIssues with analysis server refactoringsdevexp-serverIssues related to some aspect of the analysis servertype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions