一,代码:
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;
}
二,效果:
![]()