【第二天】flutter加载图片的几种方法

这只是其中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 {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Text("这是什么"),
    );
  }
}

你可能感兴趣的:(【第二天】flutter加载图片的几种方法)