I can\'t seem to simply load an image from the hard drive to the screen. Image.network seems straightforward. But I can\'t figure out how to use Image or Image.file. Imag
Flutter contains assert section inside pubspec.yaml
where it contains asserts of your application.
eg:
assets:
- data_repo/img/ic_launcher.png
1. With pubspec.yaml:
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(home: LoadLocalImage()));
}
class LoadLocalImage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Load Local Image"),
),
body: new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage('data_repo/img/ic_launcher.png'), fit: BoxFit.cover)),
),
);
}
}
2. With Image.asset:
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(home: LoadLocalImage()));
}
class LoadLocalImage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Load Local Image"),
),
body: Image.asset(
'data_repo/img/ic_launcher.png',
fit: BoxFit.cover,
));
}
}
Folder Structure: Output:
Please refer below link for more description:
https://flutter.dev/docs/cookbook/images/network-image