flutter中的runApp(new MyApp())和runApp(new MaterialApp())有什么区别?

编程入门 行业动态 更新时间:2024-10-27 00:31:40
本文介绍了flutter中的runApp(new MyApp())和runApp(new MaterialApp())有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在波动中,我们可以传递一个无状态小部件,该小部件将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())有什么区别?

本文发布于:2023-11-07 04:12:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565547.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么区别   runApp   flutter   MaterialApp   MyApp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!