Flutter热重装无法显示更改 [英] Flutter hot reloading is not working to display changes
问题描述
我有两个文件,main.dart
和sections.dart
.
我在section.dart
中定义了一些小部件,并在main.dart
文件中使用了它们,当我运行flutter run
时,命令更改会显示在屏幕上,但是当我按下R
进行热重装时,屏幕上没有任何变化
I have defined a few widgets in section.dart
and used them in main.dart
file, when I run flutter run
command changes are displayed on screen, but when I press R
to hot reload, nothing changes on screen.
main.dart:
import 'package:flutter/material.dart';
import 'sections.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Share IDEASS',
home: Scaffold(
appBar: AppBar(
title: Text('IDEASs'),
),
body: ListView(
children: [
labelsSection,
],
),
),
);
}
}
Sections.dart:
import 'package:flutter/material.dart';
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Share IDEAS',
);
}
}
Column labelSectionMethod(color,IconData icon, String label,String numbers){
return Column(
children: <Widget>[
Icon(icon, color:color),
Container(
child: Text(label,
style: TextStyle(color: color
),
),
),
Container(
child:Text(numbers,
style:TextStyle(color:color
),
),
),
],
);
}
Widget labelsSection=Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
labelSectionMethod(Colors.red,Icons.supervised_user_circle,"IDEASS","35"),
labelSectionMethod(Colors.red,Icons.favorite,"LIKE","22"),
labelSectionMethod(Colors.red,Icons.data_usage,"STREAK","12"),
],
),
);
也许是因为我在重复:
return MaterialApp(
title: 'Share IDEAS',
);
或与主要功能有关. in 更新: 我将main.dart文件中的sections.dart文件的内容移动了,但仍然无法进行热重装. i moved content of sections.dart file in main.dart file still hot reload is not working. 通常,当您更改了很多代码,添加了状态,将小部件从无状态更改为已满状态等时,通常会发生这种情况. F5)将解决此问题.
如果仍然无法解决问题,请尝试从手机/模拟器/模拟器中删除该应用程序(关闭该应用程序,然后将其删除),然后再次运行调试/flutter.这应该可以解决您的问题 This usually happens when you have change a lot of code, added states, changed a widget from stateless to state full, etc. Preforming a hot restart (ctrl +F5) will fix this issue.
If this seems to not work still, try removing the app from your phone/simulator/emulator (closing the app, and deleting it) and running debug/flutter run again. This should fix your issue 这篇关于Flutter热重装无法显示更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!sections.dart
, or something to do with main function.
推荐答案