Skip to content

Instantly share code, notes, and snippets.

@NizarETH
Created November 25, 2022 12:50
Show Gist options
  • Select an option

  • Save NizarETH/fcffa380b8047fd60ccdb9ea93ecc505 to your computer and use it in GitHub Desktop.

Select an option

Save NizarETH/fcffa380b8047fd60ccdb9ea93ecc505 to your computer and use it in GitHub Desktop.

Revisions

  1. NizarETH created this gist Nov 25, 2022.
    53 changes: 53 additions & 0 deletions Navigator flutter
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    import 'package:flutter/material.dart';

    void main() {
    runApp(const MaterialApp(
    title: 'Navigation Basics',
    home: FirstRoute(),
    ));
    }

    class FirstRoute extends StatelessWidget {
    const FirstRoute({super.key});

    @override
    Widget build(BuildContext context) {
    return Scaffold(
    appBar: AppBar(
    title: const Text('First Route'),
    ),
    body: Center(
    child: ElevatedButton(
    child: const Text('Open route'),
    onPressed: () {
    Navigator.push(
    context,
    MaterialPageRoute(builder: (context) => const SecondRoute()),
    );
    },
    ),
    ),
    );
    }
    }

    class SecondRoute extends StatelessWidget {
    const SecondRoute({super.key});

    @override
    Widget build(BuildContext context) {
    return Scaffold(
    appBar: AppBar(
    title: const Text('Second Route'),
    ),
    body: Center(
    child: ElevatedButton(
    onPressed: () {
    Navigator.pop(context);
    },
    child: const Text('Go back!'),
    ),
    ),
    );
    }
    }