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