Flutter 热重载无法显示更改 [英] Flutter hot reloading is not working to display changes
问题描述
我有两个文件,main.dart
和 sections.dart
.
I have two files, main.dart
and 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',
);
在sections.dart
中,或者与main函数有关的东西.
in sections.dart
, or something to do with main function.
更新:
我在 main.dart 文件中移动了sections.dart 文件的内容,但热重载仍然无法正常工作.
i moved content of sections.dart file in main.dart file still hot reload is not working.
推荐答案
将文件移动到另一个目录后,Android Studio 将我的导入更改为绝对路径.
After moving a file to another directory, Android Studio changed my imports to absolute paths.
import 'file:///C:/Users/svenv/AndroidStudioProjects/sample_screen_collection/lib/welcome/reading_list_card.dart';
我不得不把它改成这个
import 'package:samplescreencollection/components/reading_list_card.dart';
这篇关于Flutter 热重载无法显示更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!