Use Internet Images in Flutter
Network Images
Network images are images that are fetched and displayed from the internet in real-time. They are important for applications that require constantly updated images, such as social media feeds, news apps, or e-commerce platforms.
How to Use Network Images
To display an image in Flutter, you need to use the Image widget. You can use the Image widget in two ways:
Image.network(
'https://picsum.photos/250?image=9',
width: 150,
height: 150,
)
Image(
image: NetworkImage('https://picsum.photos/250?image=9'),
width: 150,
height: 150,
)
Example 1: Profile App
In this example, we will create a profile app and add a network image to it.
import 'package:flutter/material.dart';
void main() {
runApp(const ProfileApp());
}
class ProfileApp extends StatelessWidget {
const ProfileApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Flutter Tutorial',
home: ProfileScreen(),
);
}
}
class ProfileScreen extends StatelessWidget {
const ProfileScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Learn App Development'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.network("https://flutter-tutorial.net/images/learn_flutter.jpg"),
const SizedBox(height: 10),
const Text(
'Flutter Tutorial',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
const Text(
'https://flutter-tutorial.net',
style: TextStyle(
fontSize: 16,
color: Colors.blue,
),
),
],
),
),
);
}
}