7

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

Uncle Vector
  • 371
  • 1
  • 3
  • 12

1 Answers1

2

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.

Adrian Murray
  • 2,170
  • 1
  • 13
  • 15
  • 2
    There is also [WidgetsApp](https://api.flutter.dev/flutter/widgets/WidgetsApp-class.html) that is not bound by iOS or Android specific. It has routing navigation too. – Timur Bobrus Sep 10 '19 at 05:27
  • Correct, you can also create your own app wrapper. Which is all MaterialApp / CupertinoApp classes do. They simply build out a WidgetsApp but with specific options for those design concepts. – Adrian Murray Sep 10 '19 at 16:46