xxxxxxxxxx
Image(
image: AssetImage("location/of/image"),
)
xxxxxxxxxx
// Update the pubspec.yaml file.
assets:
- assets/tablet.png
- assets/background.png
Image.asset('assets/tablet.png'),
// Display images from the internet
Image.network(
'https://picsum.photos/250?image=9',
)
xxxxxxxxxx
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Image from assets"),
),
body: Image.asset('assets/images/lake.jpg'), // <--- image
),
);
}
}
xxxxxxxxxx
import 'package:flutter/material.dart';
class MyImageApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Image Widget Example',
home: Scaffold(
appBar: AppBar(
title: Text('Image Widget'),
),
body: Center(
child: Container(
child: Image.network(
'https://example.com/path/to/image.jpg',
// Additional properties
fit: BoxFit.contain,
width: 200,
height: 200,
),
),
),
),
);
}
}
void main() {
runApp(MyImageApp());
}