【发布时间】:2018-04-14 19:58:53
【问题描述】:
我似乎无法简单地将图像从硬盘加载到屏幕上。 Image.network 看起来很简单。但我不知道如何使用 Image 或 Image.file。图像似乎需要一个流,所以我认为这不是我想要的。
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
);
}
}
我将 Someimage 添加到 pubspec.yaml 文件中,但这也不起作用:
assets:
- Someimage.jpeg
谁能给我一个例子来说明这是如何做到的?谢谢。
【问题讨论】: