UI issues are beautiful.....

BackerLeader posted 1 min read

Ever had your Flutter screen layout shift or break when your text changes length?

The Problem

In my music player screen, long song titles caused the UI to push down — shifting the seek bar & controls, or worse, throwing an overflow error.

Here’s how the screen was built without LayoutBuilder:

// Problematic layout
return Padding(
  padding: const EdgeInsets.all(20),
  child: Column(
    children: [
      const SizedBox(height: 80),
      AnimatedBeatCircle(size: 300, isPlaying: true),

      // Title (may be 1 or 2 lines)
      Text(
        mediaItem.title,
        maxLines: 2,
        overflow: TextOverflow.ellipsis,
      ),

      const SizedBox(height: 10),
      // Seek bar + playback controls follow
      ...
    ],
  ),
);

Issue:

  • If the title is short → empty space.

  • If it’s long → seek bar/control buttons shift or overflow.

  • UI feels unstable between different songs.

The Fix: Use LayoutBuilder + Expanded

By wrapping the layout in a LayoutBuilder and explicitly splitting the screen into:

Top (flexible): Beat circle, title, artist

Bottom (fixed): Seek bar, playback controls

We pin the bottom UI and allow the top to adapt safely.

// Fixed layout
return LayoutBuilder(
  builder: (context, constraints) {
    return Column(
      children: [
        Expanded(
          child: Padding(
            padding: const EdgeInsets.all(20),
            child: Column(
              children: [
                AnimatedBeatCircle(size: 300, isPlaying: true),
                const SizedBox(height: 20),
                Text(
                  mediaItem.title,
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                ),
                Text(mediaItem.artist ?? ''),
              ],
            ),
          ),
        ),

        // Bottom stays pinned no matter what
        Padding(
          padding: const EdgeInsets.symmetric(horizontal: 20.0),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Slider(...),
              Row(...), // duration labels
              Row(...), // controls
            ],
          ),
        ),
      ],
    );
  },
);

Result:

  • Layout is predictable
  • Playback controls stay pinned
  • UI looks great no matter how long the song title is!
If you read this far, tweet to the author to show them you care. Tweet a Thanks
0 votes

More Posts

After facing weird permission issues, I built my own music app in 6 hours.

yogirahul - Jul 14

One wrong activity caused me 10+ hours of debugging

yogirahul - Jul 22

Why I Started Creating Models in My Flutter Project

yogirahul - Aug 20

How I Paid Off a Little Technical Debt in My Flutter Music App

yogirahul - Aug 15

When to Use setState, Provider, and Consumer in Flutter

yogirahul - Aug 11
chevron_left