如何将Home.dart的home属性正确添加到main.dart?

I'd like to add home.dart and splashscreen.dart to main dart but I don't know how to do that correctly.

我使用以下方法做到了:

主镖

void main() =>runApp(MaterialApp(


    initialRoute:'/',
    routes:{
      '/': (context) => Splash(),
      '/home':(context) => Home(storage:Storage()),
    },
    ));

splashscreen.dart works perfectly but home.dart is still not working correctly. But when I run the home.dart as a single file without main.dart it works perfectly.

void main() => runApp(MaterialApp(
home:Home(storage:Storage()),

));

How can I add home property of home.dart to main.dart correctly?

评论
DJHongKong
DJHongKong

替换下面的代码,它可以正常工作:

void main() =>runApp(MaterialApp(


  initialRoute:'/',
  routes:{
    '/': (context) => Splash(),
    '/home':(context) => Home(),
  },
));

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

我希望这回答了你的问题。

点赞
评论