[英]Flutter beta hot reload in VSCode works for web but not iOS and Android (which works in Android studio)
I'm running Mac Catalina and have both Android Studio and VSCode installed我正在运行 Mac Catalina 并安装了 Android Studio 和 VSCode
❯ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, 1.19.0-4.3.pre, on Mac OS X 10.15.5 19F101, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.47.0)
[✓] Connected device (3 available)
• No issues found!
I have a very simple app我有一个非常简单的应用程序
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Center(
child: Text("Hello World!"),
),
),
);
}
If I run the app from Android Studio then hot reload works just fine, eg changing the text and saving will update the text on any of the devices (iOS, Android or Chrome).如果我从 Android Studio 运行应用程序,那么热重载就可以正常工作,例如更改文本并保存将更新任何设备(iOS、Android 或 Chrome)上的文本。
But if I do the same in VSCode, ie F5 ( Debug: Start debugging
), then hot reload only works for web.但是如果我在 VSCode 中做同样的事情,即 F5( Debug: Start debugging
),那么热重载仅适用于 web。 Looking in the debug console I see the following each time I make a change and save.每次进行更改并保存时,在调试控制台中都会看到以下内容。
Reloaded 1 of 502 libraries in 167ms.
But no updates on the screen (except when running Chrome where output in the debug console looks the same as with the others.).但是屏幕上没有更新(除了运行 Chrome 时,调试控制台中的 output 看起来与其他的相同。)。 I find this very odd!我觉得这很奇怪!
I've opened a bug report at dart-code
.我在dart-code
打开了一个错误报告。
Oh my.天啊。 I forgot to put the app inside a stateless app.我忘记将应用程序放入无状态应用程序中。 My mistake!我的错!
import 'package:flutter/material.dart';
void main() {
runApp(
MyApp(),
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Center(
child: Text("Hello World!"),
),
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.