What is the difference between runApp(new MyApp()) and runApp(new MaterialApp()) in flutter?

后端 未结 3 1654
春和景丽
春和景丽 2020-12-19 12:56

In flutter we can pass a stateless widget that returns a MaterialApp instance to the runApp() function like this:

void main()=>r         


        
3条回答
  •  生来不讨喜
    2020-12-19 13:23

    There's no difference in visual behavior. What changes is how hot reload behaves.

    For example if you used runApp(MaterialApp()), changing from

    runApp(MaterialApp(title: 'Foo'))
    

    to

    runApp(MaterialApp(title: 'Bar'))
    

    then the hot reload wouldn't take changes into consideration.

    While if you had the following class :

    class MyApp {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Foo',
        );
      )
    }
    

    and used it like this :

    runApp(MyApp())
    

    then changing title of MyApp would be correctly hot reloaded.

提交回复
热议问题