by @kodeazy

flutter How to add the image at the center of the widget?

Home » flutter » flutter How to add the image at the center of the widget?

In this blog we will discuss on how to center an image using flutter.
To center an image using flutter we use Center() widget.

we have a property called child to be added inside the Center() widget

Below is the example syntax

Center(child: widgetname);

with the help of child property we can add desired image widget as shown in the above syntax

Below is an example program of adding image at the center of the page using Center() widget.

import 'package:flutter/material.dart';
void main() {
  runApp(MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(title: Text("Image Center Example"),backgroundColor: Colors.black87,),
        backgroundColor : Colors.amber,
        body: Center(child: Image(
          image: NetworkImage('https://kodeazy.com/static/23b855fcc95b96fe6293092655cef51a/d48f1/flutter-elements-space.png'),
        ),),
  ),
  ));
}

Output: Image