Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 404
Uncle Vector Avatar asked Jun 02 '19 19:06

Uncle Vector


People also ask

What are the different ways to create navigation in Flutter?

Flutter provides two types of APIs for navigation: imperative and declarative.

How do you navigate between pages in Flutter?

The basic way — push and pop The Navigator behaves like a stack, so the most simple way is to push a new page onto it when you want to navigate to it and to pop a page if you want to go back.

What is the difference between material and MaterialApp in Flutter?

MaterialApp is a widget that introduces many interesting tools such as Navigator or Theme to help you develop your app. Material is, on the other hand, a widget used to define a UI element respecting Material rules. It defines what elevation is, shape, and stuff.


1 Answers

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.

like image 122
Adrian Murray Avatar answered Nov 12 '22 23:11

Adrian Murray