Reputation: 76
I'm creating a new flutter app, and i want a solution for the images disappearing problem after flutter hot reload.
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'),
)
],
),
)
],
),
),
);
}
}
Upvotes: 1
Views: 927
Reputation: 2485
You could pre-cache the image using preCacheImage
function inside you initState
methods
like so:
class HomeState extends State<Home> {
@override
void initState() {
precacheImage(new AssetImage('img/userlogin.png'));
super.initState();
}
@override
Widget build(BuildContext context) {
// Widgets...
}
}
Upvotes: 1