Flutter : Vertically center column

Cover Image for Flutter : Vertically center column
Matheus Mello
Matheus Mello
published a few days ago. updated a few hours ago

Flutter : Vertically center column

šŸš€ Hey there Flutter enthusiasts! Are you trying to vertically center a column in Flutter but facing some issues? Don't worry, I'm here to help! šŸ˜Š In this blog post, I will guide you through the process of vertically centering a column in Flutter and provide some easy solutions to common problems faced by developers. So let's dive in and get your column centered in no time!

šŸŽÆ The Problem: The code snippet provided includes a new Center widget wrapping a new Column widget. However, for some reason, the column is not being vertically centered as expected. The goal is to have the entire column centered vertically on the screen.

āœ… The Solution: To vertically center a column in Flutter, we can make use of additional widgets and properties. Here's how you can achieve the desired result:

  1. Replace the new Center widget with a new Align widget. The Align widget provides more control over alignment in Flutter.

  2. Set the alignment property of Align widget to Alignment.center. This will ensure that the column is centered vertically.

  3. Wrap the Align widget with a Container widget and set its constraints property to BoxConstraints.expand(). This is necessary to allow the column to take up the full height of the screen.

Here's the modified code snippet:

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text("Thank you"),
    ),
    body: Container(
      constraints: BoxConstraints.expand(),
      child: Align(
        alignment: Alignment.center,
        child: Column(
          children: <Widget>[
            Padding(
              padding: EdgeInsets.all(25.0),
              child: AnimatedBuilder(
                animation: animationController,
                child: Container(
                  height: 175.0,
                  width: 175.0,
                  child: Image.asset('assets/angry_face.png'),
                ),
                builder: (BuildContext context, Widget _widget) {
                  return Transform.rotate(
                    angle: animationController.value * 6.3,
                    child: _widget,
                  );
                },
              ),
            ),
            Text(
              'We are glad we could serve you...',
              style: TextStyle(
                fontSize: 16.0,
                fontWeight: FontWeight.w600,
                color: Colors.black87,
              ),
            ),
            Padding(padding: EdgeInsets.symmetric(vertical: 5.0, horizontal: 0.0)),
            Text(
              'We appreciate your feedback!',
              style: TextStyle(
                fontSize: 13.0,
                fontWeight: FontWeight.w200,
                color: Colors.black87,
              ),
            ),
          ],
        ),
      ),
    ),
  );
}

šŸŒŸ Now, when you run your updated code, the column should be perfectly centered vertically on the screen. šŸŽ‰

šŸ“£ Call-to-Action: I hope this blog post has helped you understand how to vertically center a column in Flutter. If you found this information useful, feel free to share it with your fellow Flutter developers! Also, don't forget to let me know your thoughts or share any other Flutter-related questions or topics you'd like me to cover in future blog posts. Leave a comment below and keep the Flutter community buzzing with excitement! šŸ˜


More Stories

Cover Image for How can I echo a newline in a batch file?

How can I echo a newline in a batch file?

updated a few hours ago
batch-filenewlinewindows

šŸ”„ šŸ’» šŸ†’ Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Matheus Mello
Matheus Mello
Cover Image for How do I run Redis on Windows?

How do I run Redis on Windows?

updated a few hours ago
rediswindows

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! šŸš€ Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Matheus Mello
Matheus Mello
Cover Image for Best way to strip punctuation from a string

Best way to strip punctuation from a string

updated a few hours ago
punctuationpythonstring

# The Art of Stripping Punctuation: Simplifying Your Strings šŸ’„āœ‚ļø Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Matheus Mello
Matheus Mello
Cover Image for Purge or recreate a Ruby on Rails database

Purge or recreate a Ruby on Rails database

updated a few hours ago
rakeruby-on-railsruby-on-rails-3

# Purge or Recreate a Ruby on Rails Database: A Simple Guide šŸš€ So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? šŸ¤” Well, my

Matheus Mello
Matheus Mello