在波动中,我们可以传递一个无状态小部件,该小部件将MaterialApp实例返回给runApp()函数,如下所示:
In flutter we can pass a stateless widget that returns a MaterialApp instance to the runApp() function like this:
void main()=>runApp(new MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( ... ); } }或者我们可以将MaterialApp的实例直接传递给runApp()函数,如下所示:
or we can pass the instance of MaterialApp directly to the runApp() function like so:
void main()=>runApp( new MaterialApp( ... ); );这些方式之间有什么区别?谢谢.
What is the difference between these to ways? Thanks.
推荐答案视觉行为没有区别. 变化的是热重装的行为方式.
There's no difference in visual behavior. What changes is how hot reload behaves.
例如,如果您使用的是runApp(MaterialApp()),则从
For example if you used runApp(MaterialApp()), changing from
runApp(MaterialApp(title: 'Foo'))到
runApp(MaterialApp(title: 'Bar'))然后热重载将不会考虑更改.
then the hot reload wouldn't take changes into consideration.
如果您有以下课程:
class MyApp { @override Widget build(BuildContext context) { return MaterialApp( title: 'Foo', ); ) }并像这样使用它:
runApp(MyApp())然后将title中的title更改为正确的热加载.
then changing title of MyApp would be correctly hot reloaded.
更多推荐
flutter中的runApp(new MyApp())和runApp(new MaterialApp())有什么区别?
发布评论