Ezzeddine Essam
Ezzeddine Essam

Reputation: 76

Is there solution for images disapearing in flutter after hot reload?

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

Answers (1)

fayeed
fayeed

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

Related Questions