flutter:显示网络图片

一,代码:

import 'package:flutter/material.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with AutomaticKeepAliveClientMixin {
  @override
  Widget build(BuildContext context) {
    double Width = MediaQuery.of(context).size.width;
    print("Home build");
    super.build(context);
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          "Home标题",
          style: TextStyle(color: Colors.white),
        ),
        centerTitle: true,
        backgroundColor: Colors.blue,
      ),
      body: Center(
        child:Container(
          child: Image.network(
            "http://img0.dili360.com/ga/M01/48/3C/wKgBy1kj49qAMVd7ADKmuZ9jug8377.tub.jpg",
            //alignment: Alignment.topCenter,
            repeat: ImageRepeat.noRepeat,
            fit: BoxFit.contain,
            color: Colors.red,
            colorBlendMode: BlendMode.colorDodge,
          ),
          width: Width,
          height: 300,
          color: Colors.black,
        ),
      ),
     // ),
    );
  }

  @override
  bool get wantKeepAlive => true;
}

 

二,效果:

posted @ 2025-03-22 10:32  刘宏缔的架构森林  阅读(23)  评论(0)    收藏  举报