Search code examples
flutterflutter-layoutmargin

Why Right Margin in FLutter is not applied from Right edge of the screen?


I have some doubt regrading right margin in flutter.If you see that left margin is calculated from left edge of screen and it not too far from the left edge.But,the right margin is too far from the right edge of the screen.I have applied same left and right margins

So,why is the right margin not calculated properly from right edge of the screen?I have attached code and screenshot of app.

[![import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.white,
        body: SafeArea(
          child: Container(
            height: 150.0,
            width: 100.0,
            // margin: EdgeInsets.all(90.0),
            margin: const EdgeInsets.only(left: 30.0, right: 30.0),

            color: Colors.blue,
            child: Text("Hello"),
          ),
        ),
      ),
    );
  }
}][1]][1]

Screenshot of App


Solution

  • Change the width of the container to width: double.infinity then you can see the margin. You are unable to see the margin since the container is left aligned and the container is not filling the entire width.