我正在创建一个新的flutter应用程序,我想要解决在flutter热重新加载后图像消失的问题。
import 'package:flutter/material.dart';
class Home extends StatefulWidget {
@override
State <StatefulWidget> createState() {
return HomeState();
}
}
class HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: Colors.redAccent,
title: Text('Login Page '),
),
body: Container(
padding: EdgeInsets.all(33.0),
alignment: Alignment.center,
child: Column(
children: <Widget>[
Image.asset('img/userlogin.png'),
Container(
child: Column(
children: <Widget>[
TextField(
controller: null,
decoration: InputDecoration(
icon: Icon(Icons.person), hintText: 'Yor Name'),
)
],
),
)
],
),
),
);
}
}
答案 0 :(得分:0)
您可以使用preCacheImage
方法内部的initState
函数预先缓存图像
像这样:
class HomeState extends State<Home> {
@override
void initState() {
precacheImage(new AssetImage('img/userlogin.png'));
super.initState();
}
@override
Widget build(BuildContext context) {
// Widgets...
}
}