Flutter Images with example

Flutter tutorial

In Flutter, you can display images using the Image widget. There are different ways to load and display images, such as loading from the network, assets, or the device’s file system. Some examples are:

Loading Image from Network

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('Flutter Image Example'),
        ),
        body: Center(
          child: Image.network(
            'https://example.com/your_image_url.jpg',
            width: 200.0,
            height: 200.0,
          ),
        ),
      ),
    );
  }
}

Loading Image from Assets

flutter:
  assets:
    - assets/your_image_asset.jpg

After Declare in pubspec.yaml file

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('Flutter Image Example'),
        ),
        body: Center(
          child: Image.asset(
            'assets/your_image_asset.jpg',
            width: 200.0,
            height: 200.0,
          ),
        ),
      ),
    );
  }
}

Loading Image from File

import 'dart:io';
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('Flutter Image Example'),
        ),
        body: Center(
          child: Image.file(
            File('/path/to/your/image.jpg'),
            width: 200.0,
            height: 200.0,
          ),
        ),
      ),
    );
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

web_horizontal
About Us ♢ Disclaimer ♢ Privacy Policy ♢ Terms & Conditions ♢ Contact Us

Copyright © 2023 ResearchThinker.com. All rights reserved.