返回介绍

Display images from the internet

发布于 2019-12-09 21:31:27 字数 2132 浏览 1084 评论 0 收藏 0

Displaying images is fundamental for most mobile apps. Flutter provides the Image Widget to display different types of images.

In order to work with images from a URL, use the Image.network constructor.

Image.network(
  'https://picsum.photos/250?image=9',
)

Bonus: Animated Gifs

One amazing thing about the Image Widget: It also supports animated gifs out of the box!

Image.network(
  'https://github.com/flutter/plugins/raw/master/packages/video_player/doc/demo_ipod.gif?raw=true',
);

Placeholders and Caching

The default Image.network constructor does not handle more advanced functionality, such as fading images in after loading or caching images to the device after they’re downloaded. To achieve these tasks, please see the following recipes:

Complete example

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',
        ),
      ),
    );
  }
}

Network Image Demo

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文