Skip to main content

Flutter Load Image From Network

Network images can decrease the app size by calling all the large scale images over the network. In flutter to load image from network Image.network() widget is present. It can load images from network when rendered by Image Stream.

Flutter Load Image From Web HTTP URL:

1. Defining a final string variable with online image URL. This is a flower image.
final String imageURL =
      'https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqulsBzAJFu9AOO1BOdDW26gGWmVpnTgInl_H9YEtDxCnuHva7o3Z6EGqTjoSJxFgVkpo1fYbPR6h-B4X5kkwc7lJyymDQGoRX3RdSfxIezLhLt9pVuNGusnG-CI9DAldqAoGLZw44ybQL5tw6cw-6oW3ULCVr4lu-wMMTxe_RU4VfWaZtD5dT2d00xyDf/s1280/rose.jpg';

2. Defining Image.network() widget and pass the image URL as first argument, the we are defining image width and height.
Image.network(imageURL,
          width: 300, height: 200, fit: BoxFit.fitWidth),
Source code for main.dart file:
import 'package:flutter/material.dart';

void main() => runApp(const App());

class App extends StatelessWidget {
  const App({super.key});

  final String imageURL =
      'https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqulsBzAJFu9AOO1BOdDW26gGWmVpnTgInl_H9YEtDxCnuHva7o3Z6EGqTjoSJxFgVkpo1fYbPR6h-B4X5kkwc7lJyymDQGoRX3RdSfxIezLhLt9pVuNGusnG-CI9DAldqAoGLZw44ybQL5tw6cw-6oW3ULCVr4lu-wMMTxe_RU4VfWaZtD5dT2d00xyDf/s1280/rose.jpg';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            body: SafeArea(
                child: Center(
      child: Image.network(imageURL,
          width: 300, height: 200, fit: BoxFit.fitWidth),
    ))));
  }
}
Screenshot:
Flutter Load Image From Network

Comments