1

Consider the following code from the Flutter docs:

CustomPaint(
  painter: Sky(),
  child: const Center(
    child: Text(
      'Once upon a time...',
      style: TextStyle(
        fontSize: 40.0,
        fontWeight: FontWeight.w900,
        color: Color(0xFFFFFFFF),
      ),
    ),
  ),
)

I don't want a text widget.

I don't want the CustomPaint widget to be obscured by a child widget.

Also I want the CustomPaint widget to fill whatever space is available to it.

I presume the solution is to replace the Text widget with a BLANK widget like Expanded.

But, I've tried the Expanded, Container, Spacer, and Space widgets in various combinations but always either get an error or a zero size.

Thanks!

Nerdy Bunz
  • 6,040
  • 10
  • 41
  • 100

2 Answers2

1

Here how you do it:

Expanded(
  child: CustomPaint(
    painter: MyCustomPainter(),
    size: Size.infinite,

  ),
),
Nerdy Bunz
  • 6,040
  • 10
  • 41
  • 100
-2

You can get height and width of the screen by using MediaQuery and use them

final width = MediaQuery.of(context).size.width;
    final height = MediaQuery.of(context).size.height;
    return CustomPaint(
      size: Size(width,height),
      painter: Sky(),
      child: const Center(
        child: Text(
          'Once upon a time...',
          style: TextStyle(
            fontSize: 40.0,
            fontWeight: FontWeight.w900,
            color: Color(0xFFFFFFFF),
          ),
        ),
      ),
    );
Diwyansh
  • 2,961
  • 1
  • 7
  • 11