How to align a container in Flutter?

This Article is posted by seven.srikanth at 11/25/2022 5:14:53 AM



You can align a container by wrapping it inside an Align widget.
For example, the below code will set the container to topCenter.  

Align(
      alignment: FractionalOffset.topCenter,
      child: Container(
        height: 100,
        width: 100,
        decoration: const BoxDecoration(
          color: Colors.amber,
        ),
      ),
    )
You can set Alignment to topCenter, topRight, centerLeft, center, centerRight, bottomLeft, bottomCenter, or bottomRight.
Here is a simple example, that helps you to understand more about aligning the container.

import 'package:flutter/material.dart';
void main(List<String> args) {
  runApp(const MyApp());
}
class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @ override
  Widget build(BuildContext context) {
    return Align(
      alignment: FractionalOffset.,
      child: Container(
        height: 100,
        width: 100,
        decoration: const BoxDecoration(
          color: Colors.amber,
        ),
      ),
    );
  }
}
Thanks,
Srikanth

Tags:








0 Comments
Login to comment.
Recent Comments












© 2018 - Fluttercentral | Email to me - seven.srikanth@gmail.com