How To Add Apply Margin To Image Widget In Flutter Android App

admin_img Posted By Bajarangi soft , Posted On 12-10-2020

Image widget did not support margin property directly but using the Container widget we can easily apply Margin property on Image widget for all 4 Left, Right, Top and Bottom side.

How To Add Apply Margin To Image Widget In Flutter Android App

 Apply Margin To Image Widget
Complete Code For  Apply Margin To Image Widget In Flutter
Main.dart

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
        home: Scaffold(
          backgroundColor: Colors.black,
            appBar: AppBar(
              backgroundColor: Color(0xFF4527A0),
              title: Text('Apply Margin To Image Widget'),
            ),
            body: Center(
              child:  Row(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  Container(
                      margin: const EdgeInsets.fromLTRB(15, 0, 15, 20),
                      child:
                      Image.asset('assets/img1.jpg',
                        width: 130, height: 200, fit: BoxFit.contain,)
                  ),
                  Container(
                      margin: const EdgeInsets.fromLTRB(15, 0, 15, 20),
                      child:
                      Image.asset('assets/img2.jpg',
                        width: 130, height: 200, fit: BoxFit.contain,)
                  ),
                ],
              ),
            )));
  }
}

Related Post