Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Hot Reload and Hot Restart not working

I am trying to work on a project that I just started and while editing the app I realized that neither hot reload nor hot restart are working even though I have changed the design multiple times. The only time that I would see a change in the screen is when I uninstall the app and run again,

I am testing the app on an emulator and I am using Android Studio.

I searched for a solution before typing this question and this is what I have tried:

  • flutter clean
  • flutter doctor -v then flutter upgrade
  • deleting the emulator and trying on another emulator
  • invalidate cache and restart

It used to work really well and now it is not, here's an example:

import 'package:gradient_app_bar/gradient_app_bar.dart';

import '../constants.dart';

class PlantScreen extends StatefulWidget {
  @override
  _PlantScreenState createState() => _PlantScreenState();
}

class _PlantScreenState extends State<PlantScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: GradientAppBar(
        centerTitle: true,
        title: Text('plant A'),
        gradient: LinearGradient(
            colors: Constants.primaryGradient,
            begin: Alignment.topLeft,
            end: Alignment.bottomRight),
      ),
      body: Container(
        constraints: BoxConstraints.expand(),
        decoration: BoxDecoration(
          gradient: LinearGradient(
              colors: Constants.primaryVariantGradient,
              begin: Alignment.topLeft,
              end: Alignment.bottomRight),
        ),
        child: Column(
          children: <Widget>[
            Card(
              child: Column(
                children: <Widget>[

                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

enter image description here

like image 412
Nayef Radwi Avatar asked Feb 11 '20 11:02

Nayef Radwi


People also ask

What is the difference between hot restart and hot reload in Flutter?

Hot Reload allows us to see the reflected change after bug fixes, building User interfaces and even adding certain features to the app without running your application afresh over and over again. Hot restart destroys the preserved State value and set them to their default.

How hot does Flutter reload work?

One of Flutter's great features is hot reload. You press r on your keyboard, and moments later the impact of your changes can be seen on the device. In your terminal (or maybe at the bottom of your IDE) you can read something like Reloaded 1 of 553 libraries in 297ms .


1 Answers

I figured the issue was with my import statement

it was :

import 'file:///E:/SelfProjects2/water_my_plants/lib/screens/plantScreen.dart';

I have changed it to

import 'package:water_my_plants/screens/plantScreen.dart';

in my main dart file that had the route to the PlantScreen()

like image 78
Nayef Radwi Avatar answered Oct 06 '22 19:10

Nayef Radwi