How to add an Image to a Container in Flutter?

This Article is posted by seven.srikanth at 9/21/2019 6:20:26 AM



In this article, I'm going to show you, How to add an Image to a Container in Flutter.

Here is how the final output is going to look like, I'm loading a Logo from FlutterCentral.com to this app.



Here is the code form main.dart file.

import 'package:flutter/material.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  double padValue = 0;
  @override
  Widget build(BuildContext context) {

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("Image in a Container Example"),
        ),
        body: Center(
          child: Container(
            decoration: BoxDecoration(
              image: DecorationImage(image: NetworkImage('https://fluttercentral.com/Images/Logo.png')),
              color: Colors.black,
            ),
          ),
        )
      ),
    );
  }
}

Since we are loading app from the internet, we don't have to add any references in pubspec.yaml.

Thanks,
Srikanth

Tags: DecorationImage








0 Comments
Login to comment.
Recent Comments












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