Flutter 热重载和热重启不起作用 [英] Flutter Hot Reload and Hot Restart not working

查看:35
本文介绍了Flutter 热重载和热重启不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试处理一个我刚刚开始的项目,在编辑应用程序时,我意识到热重载和热重启都不起作用,即使我多次更改了设计.我唯一会在屏幕上看到变化的时间是我卸载应用程序并再次运行

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,

我正在模拟器上测试应用程序,我使用的是 Android Studio.

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 doctor -v then flutter upgrade
  • 删除模拟器并尝试另一个模拟器
  • 使缓存无效并重新启动
  • 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>[

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

推荐答案

我认为问题在于我的导入语句

I figured the issue was with my import statement

原来是:

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

我已经改成

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

在我的主要飞镖文件中有到 PlantScreen() 的路径

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

这篇关于Flutter 热重载和热重启不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆