flutter image code example
Example 1: flutter image asset
// pubspec.yaml
flutter:
assets:
- graphics/
// Inside your widget
Image(image: AssetImage('graphics/background.png'))
Example 2: flutter asset image not showing
flutter:
uses-material-design: true
assets:
- assets/
class _UserLoginState extends State<UserLogin> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
Image(image: AssetImage("assets/christmas.jpeg"),
fit: BoxFit.cover,
],
)
);
}
}
Example 3: flutter image load
Image.asset(name) is essentially Image(image: AssetImage(name)),
Image.file(path) is essentially Image(image: FileImage(File(path))),
Image.network(url) is essentially Image(image: NetworkImage(url)),
Image.memory(list) is essentially Image(image: MemoryImage(list))
Example 4: image in flutter
const Image(
image: NetworkImage('https://flutter.github.io/assets-for-api-docs/assets/widgets/owl.jpg'),
)