Learn How to Use Flutter Align Widget with Example Code



Are you looking for a powerful and flexible way to align your widgets in a Flutter application? Look no further than the Align widget! In this article, we’ll dive into the Align widget and provide a real-world example of how to use it in your Flutter code.

The Align widget is a flexible and powerful tool for positioning widgets within a parent widget. It allows you to specify the alignment of a child widget within the parent, using properties such as alignment, widthFactor, heightFactor, and more.

Flutter Align Widget example

Let’s take a look at an example of how to use the Align widget in a real-world scenario. Suppose you’re building a login screen for your Flutter app, and you want to align the login button at the bottom of the screen, centered horizontally. learn about also image carousel slider flutter.

To achieve this layout, you can use the Align widget as follows:

Flutter Align Widget To align a child widget.

Align(
          alignment: Alignment.center,
          child: Text(
            "ALIGN WIDGET",
            style: TextStyle(fontSize: 35, fontWeight: FontWeight.bold),
          )),

    Alignment.topLeft
    Alignment.topCenter
    Alignment.topRight
    Alignment.centerLeft
    Alignment.center
    Alignment.centerRight
    Alignment.bottomLeft
    Alignment.bottomCenter
    Alignment.bottomRight

Align widget flutter

Flutter Align Widget

Flutter tutorial source Code:

import 'package:flutter/material.dart';

main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: FirstPage(),
    );
  }
}

class FirstPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: const Text("Instructive Tech"), backgroundColor: Colors.green),
      body: const Align(
          alignment: Alignment(-0.7, 0.8 ),
          child: Text(
            "ALIGN WIDGET",
            style: TextStyle(fontSize: 35, fontWeight: FontWeight.bold),
          )),
    );
  }
}

In this example code, we use the Align widget to position the login button at the bottom center of the screen. We set the alignment property to Alignment.bottomCenter, which aligns the child widget at the bottom center of the parent. We also use a SizedBox widget to set the width and height of the button, and an ElevatedButton widget to create the button with a raised appearance.

  • Boost WooCommerce Security: Set Up OTP Login in WordPress
    Passwords, while essential for security, can be vulnerable to hacking and breaches. To add an extra layer of protection for your WooCommerce store, consider implementing an OTP (One-Time Password) login. This guide walks you through the process of setting up an OTP login in WordPress for enhanced security. Why Use OTP Login? Enhanced Security: OTPs …

    Read more …

  • How to Create Woocommerce Flutter App for WordPress free
    Absolutely! Let’s break down how to create a WooCommerce Flutter app for your WordPress store. Here’s a comprehensive outline of the process and essential considerations: 1. Setup Your Development Environment 2. Project Structure 3. Dependencies 4. Core Functionality 5. User Interface (UI) and User Experience 6. Additional Features (Optional) Example Code Snippet (Fetching Products) Important …

    Read more …

  • How to Add a Link to Your Facebook Story in 2024
    Facebook Stories have become an integral part of our social media experience, allowing us to share moments and updates with our friends and followers. But did you know that you can also add links to your Facebook Stories? Adding a link to your story can be a powerful way to drive traffic to your website, …

    Read more …

  • Troubleshooting “Failed to download Laravel from dist” Error
    If you encounter the “Failed to download Laravel from dist” error while working with Laravel 10, it is likely due to the absence of the zip extension and unzip/7z commands on your system. This error prevents the successful download of Laravel from the distribution (dist) repository. What causes this error? The error occurs when the …

    Read more …

  • Solutions for “The file is too large for the destination file system” Error on Pendrive
    If you have ever encountered the frustrating error message “The file is too large for the destination file system” when trying to transfer files to your pendrive, don’t worry! There are a few solutions you can try to resolve this issue. 1. Format the Pendrive: One of the easiest ways to fix this error is …

    Read more …

Learn also, flutter interactive widget.

Conclusion

In conclusion, the Align widget is a powerful and flexible way to position widgets within a Flutter app. By using the alignment, widthFactor, heightFactor, and other properties, you can achieve any layout you need. Try using the Align widget in your next Flutter project and see how it can help you create beautiful, functional user interfaces.

Leave a Comment