这只是其中2种简单的方法,后续会补充,请持续关注
这是完整dome代码,直接复制放入main.dart就可以了
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
debugPaintSizeEnabled = true;
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("image实例dome"),
),
body: Center(
child: Column(
children: [
//加载网络图片
Image.network(
"https://b1.sbimg.org/file/chevereto-jia/2020/12/14/Qct2l.png",
width: 300,
),
//加载asset图片
// Image.asset("assets/image/..png"),
MemoryImageWidget()
],
),
),
));
}
}
class MemoryImageWidget extends StatefulWidget {
@override
_MemoryImageWidgetState createState() => _MemoryImageWidgetState();
}
class _MemoryImageWidgetState extends State<MemoryImageWidget> {
@override
Widget build(BuildContext context) {
return Container(
child: Text("这是什么"),
);
}
}