Search code examples
flutterflutter-navigation

Flutter - How to handle Navigation without using MaterialApp?


In flutter creating named routes is easy and logical, but only when returning a MaterialApp.

class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        initialRoute: "/";

        return MaterialApp( //gives errors when I return a Container
            routes: {
                "/" : (context) => FirstRoute(),
                "/second route" : (context) => SecondRoute()
            }
        );
    } 
}

I am not that big a fan of Material Design and want to create a UI from my own design.

But when I apply the same pattern when returning a container I get an error.

So my qustion is how do I have named route setup with a vanilla Flutter App or am I being forced to use MaterialApp for my project?

Thanks in advance


Solution

  • MaterialApp is just a collection of commonly used components such as a navigator. You could also use a CupertinoApp. Material uses iOS navigation animations on iOS and Android animations on android. Though you’re not stuck to the UI design because you’re using a MaterialApp as a foundation. You are able to build whatever UI you want with a material app or even use Cupertino widgets. It’s all up to you.