> For the complete documentation index, see [llms.txt](https://haluk-hackali.gitbook.io/flutter-dart-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://haluk-hackali.gitbook.io/flutter-dart-notes/flutter/navigation/navigation-ongenerateroute.md).

# Navigation: onGenerateRoute

## if 'li yapı :&#x20;

```dart
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(accentColor: Colors.grey),
      //home: HomePage(),
      
//         initialRoute: HomePage.routeName,
//         routes: {
//           HomePage.routeName: (context) => HomePage(),
//           RoutePink.routeName: (context) => RoutePink(),
//           RouteGreen.routeName: (context) => RouteGreen(),
//           RouteGrey.routeName: (context) => RouteGrey(),
//         },

      onGenerateRoute: (settings) {
        if (settings.name == HomePage.routeName) {
          return MaterialPageRoute(builder: (context) => HomePage());}
        if (settings.name == RoutePink.routeName) {
          return MaterialPageRoute(builder: (context) => RoutePink());}
        if (settings.name == RouteGreen.routeName) {
          return MaterialPageRoute(builder: (context) => RouteGreen());}
        if (settings.name == RouteGrey.routeName) {
          return MaterialPageRoute(builder: (context) => RouteGrey());}
           
        return null;
        
      },
    );
  }
}

class Kullanici {
  String ad;
  int yas;
  String adres;

  Kullanici({this.ad, this.yas, this.adres});
}

class HomePage extends StatelessWidget {
  final Kullanici kullanici_1 =
      Kullanici(ad: 'Metin', adres: 'Beşiktaş', yas: 40);

  static String routeName = '/';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.yellow,
      appBar: AppBar(title: Text('Sayfalar Arası Geçiş / Navigation')),
      body: Center(
          child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
        Text('HomePage'),
        SizedBox(height: 15.0),
        RaisedButton(
            child: Text('Git -> Route Pink'),
            onPressed: () {
              Navigator.pushNamed(context, RoutePink.routeName,
                  arguments: kullanici_1);
            })
      ])),
    );
  }
}

///////////////////////////////////////////////
///   ROUTE PINK
///////////////////////////////////////////////

class RoutePink extends StatelessWidget {
  static String routeName = '/routePink';

  //Kullanici yerelKullanici = ModalRoute.of(context).settings.arguments;

  @override
  Widget build(BuildContext context) {
    Kullanici yerelKullanici = ModalRoute.of(context).settings.arguments;

    return Scaffold(
      backgroundColor: Colors.pink,
      appBar: AppBar(title: Text('Route Pink')),
      body: Center(
          child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
//         Text('Kullacıcı adı: ${yerelKullanici.ad}, Yaş : //${yerelKullanici.yas}, Adres : ${yerelKullanici.adres}'),
        Text('Pink Sayfası'),
        RaisedButton(
            child: Text('Git -> Route Green'),
            onPressed: () {
              Navigator.pushNamed(context, RouteGreen.routeName);
            }),
        RaisedButton(
            child: Text('Geri Dön'),
            onPressed: () {
              Navigator.pop(context);
            }),
      ])),
    );
  }
}

///////////////////////////////////////////////
///   ROUTE GREEN
///////////////////////////////////////////////
class RouteGreen extends StatelessWidget {
  static String routeName = '/routeGreen';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.green,
      appBar: AppBar(title: Text('Route Green')),
      body: Center(
          child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
        Text('Şu an RouteGreen en üstte'),
        SizedBox(height: 35.0),
        RaisedButton(
            child: Text('Git -> Route Grey'),
            onPressed: () {
              Navigator.pushNamed(context, RouteGrey.routeName);
            }),
        SizedBox(height: 15.0),
        RaisedButton(
            child: Text('Geri Dön'),
            onPressed: () {
              Navigator.pop(context);
            }),
      ])),
    );
  }
}

///////////////////////////////////////////////
///   ROUTE GREY
///////////////////////////////////////////////
class RouteGrey extends StatelessWidget {
  static String routeName = '/routeGrey';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey,
      appBar: AppBar(title: Text('Route Grey')),
      body: Center(
          child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
        Text('Şu an RouteGrey en üstte'),
        RaisedButton(child: Text('Git -> ....'), onPressed: () {}),
        RaisedButton(
            child: Text('Geri Dön'),
            onPressed: () {
              Navigator.pop(context);
            }),
      ])),
    );
  }
}

```

## switch - case 'li yapı

```dart
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        theme: ThemeData(accentColor: Colors.grey),
        //home: HomePage(),

//         initialRoute: HomePage.routeName,
//         routes: {
//           HomePage.routeName: (context) => HomePage(),
//           RoutePink.routeName: (context) => RoutePink(),
//           RouteGreen.routeName: (context) => RouteGreen(),
//           RouteGrey.routeName: (context) => RouteGrey(),
//         },

//       onGenerateRoute: (settings) {
//         if (settings.name == HomePage.routeName) {
//           return MaterialPageRoute(builder: (context) => HomePage());}
//         if (settings.name == RoutePink.routeName) {
//           return MaterialPageRoute(builder: (context) => RoutePink());}
//         if (settings.name == RouteGreen.routeName) {
//           return MaterialPageRoute(builder: (context) => RouteGreen());}
//         if (settings.name == RouteGrey.routeName) {
//           return MaterialPageRoute(builder: (context) => RouteGrey());}

//         return null;

//       },

        onGenerateRoute: (settings) {
          
          switch (settings.name) {
            case HomePage.routeName:
              return MaterialPageRoute(builder: (context) => HomePage());
            case RoutePink.routeName:
              return MaterialPageRoute(builder: (context) => RoutePink(settings.arguments));
            case RouteGreen.routeName:
              return MaterialPageRoute(builder: (context) => RouteGreen());
            case RouteGrey.routeName:
              return MaterialPageRoute(builder: (context) => RouteGrey());
            default:
              return null;
          }
        });
  }
}

class Kullanici {
  String ad;
  int yas;
  String adres;

  Kullanici({this.ad, this.yas, this.adres});
}

class HomePage extends StatelessWidget {
  final Kullanici kullanici_1 =
      Kullanici(ad: 'Metin', adres: 'Beşiktaş', yas: 40);

  static const String routeName = '/';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.yellow,
      appBar: AppBar(title: Text('Sayfalar Arası Geçiş / Navigation')),
      body: Center(
          child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
        Text('HomePage'),
        SizedBox(height: 15.0),
        RaisedButton(
            child: Text('Git -> Route Pink'),
            onPressed: () {
              Navigator.pushNamed(context, RoutePink.routeName,
                  arguments: kullanici_1);
            })
      ])),
    );
  }
}

///////////////////////////////////////////////
///   ROUTE PINK
///////////////////////////////////////////////

class RoutePink extends StatelessWidget {
  static const String routeName = '/routePink';
  
  final Kullanici yerelKullanici;
  
  RoutePink(this.yerelKullanici);

  @override
  Widget build(BuildContext context) {
  //  Kullanici yerelKullanici = ModalRoute.of(context).settings.arguments;

    return Scaffold(
      backgroundColor: Colors.pink,
      appBar: AppBar(title: Text('Route Pink')),
      body: Center(
          child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
         Text('Kullacıcı adı: ${yerelKullanici.ad}, Yaş : ${yerelKullanici.yas}, Adres : ${yerelKullanici.adres}'),
        Text('Pink Sayfası'),
        RaisedButton(
            child: Text('Git -> Route Green'),
            onPressed: () {
              Navigator.pushNamed(context, RouteGreen.routeName);
            }),
        RaisedButton(
            child: Text('Geri Dön'),
            onPressed: () {
              Navigator.pop(context);
            }),
      ])),
    );
  }
}

///////////////////////////////////////////////
///   ROUTE GREEN
///////////////////////////////////////////////
class RouteGreen extends StatelessWidget {
  static const String routeName = '/routeGreen';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.green,
      appBar: AppBar(title: Text('Route Green')),
      body: Center(
          child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
        Text('Şu an RouteGreen en üstte'),
        SizedBox(height: 35.0),
        RaisedButton(
            child: Text('Git -> Route Grey'),
            onPressed: () {
              Navigator.pushNamed(context, RouteGrey.routeName);
            }),
        SizedBox(height: 15.0),
        RaisedButton(
            child: Text('Geri Dön'),
            onPressed: () {
              Navigator.pop(context);
            }),
      ])),
    );
  }
}

///////////////////////////////////////////////
///   ROUTE GREY
///////////////////////////////////////////////
class RouteGrey extends StatelessWidget {
  static const String routeName = '/routeGrey';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey,
      appBar: AppBar(title: Text('Route Grey')),
      body: Center(
          child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
        Text('Şu an RouteGrey en üstte'),
        RaisedButton(child: Text('Git -> BİTTİ!'), onPressed: () {}),
        RaisedButton(
            child: Text('Geri Dön'),
            onPressed: () {
              Navigator.pop(context);
            }),
      ])),
    );
  }
}


```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://haluk-hackali.gitbook.io/flutter-dart-notes/flutter/navigation/navigation-ongenerateroute.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
