我一直在阅读有关颤振与热重装有关的一些问题。如果您在点击热重载按钮时(例如在Android Studio中)未执行您要修改的代码,则更改将不会发送到设备。
奇怪的是,为什么这段代码不强制热装:
导入“ package:flutter / material.dart”;
void main() {
runApp(new MaterialApp(
title: "My Flutter App",
home: new Scaffold(
appBar: new AppBar(
title: new Text("My Flutter App"),
backgroundColor: Colors.purple,
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text("Hello",textAlign: TextAlign.left),
new Text("Pepe",textAlign: TextAlign.left),
new Text("Antonio")
] ,
),
),
));
}
但此方法(相同的代码,只是将主页小部件移动到自定义小部件)有效:
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
title: "My Flutter App",
home: Home()
));
}
class Home extends StatelessWidget
{
@override
Widget build(BuildContext context)
{
return new Scaffold(
appBar: new AppBar(
title: new Text("My Flutter App"),
backgroundColor: Colors.purple,
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text("Hello",textAlign: TextAlign.left),
new Text("Pepe",textAlign: TextAlign.left),
new Text("Antonio")
] ,
),
);
}
}