0

I am using a CustomScrollView and tried to limit its children's size by using BoxConstraints but they are simply ignored. My text expands to the width of the screen and I don't understand why.

This is my code:

  SliverToBoxAdapter(
    child: ConstrainedBox(
      constraints: maxWidthConstraint,
      child: Center(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              widget.project.description,
            ),
          ],
        ),
      ),
    ),
  ),

What am I missing here? Let me know if you need any more info!

Chris
  • 1,828
  • 6
  • 40
  • 108

1 Answers1

2

The parent forces it to be the full width so you can wrap it with UnconstrainedBox or Align or Center widget to get rid of that behavior.

SliverToBoxAdapter(
  child: UnconstrainedBox( // this should allow it to have its own constraints
    child: ConstrainedBox(
      constraints: maxWidthConstraint,
      child: Center(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              widget.project.description,
            ),
          ],
        ),
      ),
    ),
  ),
)
Ante Bule
  • 1,834
  • 1
  • 2
  • 8
  • I wrapped the `Column` with a `Center` instead of the `ConstrainedBox`. Working now, thank you :) – Chris Jan 28 '23 at 09:21