1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] How to load images with image.file

Discussão em 'Mobile' iniciado por Stack, Outubro 17, 2024 às 21:52.

  1. Stack

    Stack Membro Participativo

    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. Image seems to require a stream, so I don't think that is what I am looking for.

    import 'package:flutter/material.dart';
    import 'dart:io';

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

    class MyApp extends StatelessWidget {
    File file = new File("Someimage.jpeg");
    @override
    Widget build(BuildContext context) {
    return new MaterialApp(
    home: new Image.file(file), //doesn't work, but no errors
    );
    }
    }


    I added Someimage to the pubspec.yaml file, but that doesn't work either:

    assets:
    - Someimage.jpeg


    Can someone give me an example of how this is done? Thanks.

    Continue reading...

Compartilhe esta Página