cover

Flutter Image #

There is possibly multiple ways of showing image in flutter app. If we see these closely then we will find there is 3 main way of doing

  • Network: When we load the image from internet
  • Assets: When we load the image from phone.
  • File: When image is stored in the form file object.

Flutter made this simple by make different widget for all of these and widget are somewhere making our like harder because it’s hard to memorize.

Flutter made the naming of widget very much generic which make us life easier. We need not not memorize everything we just need to memorize one other will similar.

  • Image.network - This will show the image form network.
  • Image.assets- This will show the image from assets.
  • Image.file- This will show the image from file.

All these widget have similar arguments, all of these have mainly one different argument.

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var title = 'Web Images';

    return MaterialApp(
      title: title,
      home: Scaffold(
        appBar: AppBar(
          title: Text(title),
        ),
        body: Image.network('https://picsum.photos/250?image=9'),
      ),
    );
  }
}
comments powered by Disqus