How to expand all children of a Stack that includes a CustomPainter in Flutter

1.1k Views Asked by At

Let's say in Flutter we have a Stack that contains:

  1. A CustomPainter with size of Size.infinite
  2. Any other widget that is not a Custom Painter (that we also want to fill all available space exactly the same way that the custom painter does)

In this example, I'm using an Icon for item 2:

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Container(
        color: Colors.white,
        child: Stack(
          children: [
            Icon(Icons.star),
            CustomPaint(
                painter: MyCustomPainter(percentTimeElapsed: 0.5),
                size: Size.infinite)
          ],
        ),
      ),
    );
  }

Now, obviously, we don't get the desired result yet -- the custom painter is "expanded" but the icon is not.

But I have tried all the following with no luck:

  • Wrapping the Icon with Expanded (causes exception)
  • Wrapping the Stack widget with Expanded (causes exception)
  • Defining the size of the Icon to be Size.infinite (will not build because size param expects a double)
  • Using fit: StackFit.expand as a parameter for the Stack, but this just seems to center the Icon and doesn't change it's size.
0

There are 0 best solutions below