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.
; background-color: rgb(30, 30, 30); font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;](color: #569cd6;](import color: #ce9178;]('package:flutter/material.dart';
color: #569cd6;](void color: #dcdcaa;](main() => color: #dcdcaa;](runApp(color: #4ec9b0;](MyApp());
color: #569cd6;](class color: #4ec9b0;](MyApp color: #569cd6;](extends color: #4ec9b0;](StatefulWidget { color: #569cd6;](@override color: #4ec9b0;](_MyAppState color: #dcdcaa;](createState() => color: #4ec9b0;](_MyAppState();}
color: #569cd6;](class color: #4ec9b0;](_MyAppState color: #569cd6;](extends color: #4ec9b0;](State { color: #4ec9b0;](double padValue = color: #b5cea8;](0; color: #569cd6;](@override color: #4ec9b0;](Widget color: #dcdcaa;](build(color: #4ec9b0;](BuildContext context) {
color: #c586c0;](return color: #4ec9b0;](MaterialApp( home: color: #4ec9b0;](Scaffold( appBar: color: #4ec9b0;](AppBar( title: color: #4ec9b0;](Text(color: #ce9178;]("Image in a Container Example"), ), body: color: #4ec9b0;](Center( child: color: #4ec9b0;](Container( decoration: color: #4ec9b0;](BoxDecoration( image: color: #4ec9b0;](DecorationImage(image: color: #4ec9b0;](NetworkImage(color: #ce9178;]('https://fluttercentral.com/Images/Logo.png')), color: color: #4ec9b0;](Colors.black, ), ), ) ), ); }}
Since we are loading app from the internet, we don't have to add any references in pubspec.yaml.
Thanks,Srikanth