我有两个文件,main.dart
和sections.dart
。
我在section.dart
中定义了一些小部件,并在main.dart
文件中使用了它们,当我运行flutter run
时,命令更改会显示在屏幕上,但是当我按R
进行热重装时,屏幕上没有任何变化。
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
中,或与主要功能有关。
有时抖动会与大量更改混淆,您需要执行重新启动,尤其是在与整个App
或main
函数进行交互时。
您可以按Ctrl+C
取消flutter run
进程,然后尝试再次启动它。另外,如果您通过IntelliJ或Android Studio运行Flutter,则flutter插件将包含“热重启”功能,可以完成相同的操作。