import 'package:flutter/material.dart'; void main() { runApp(MaterialApp( title: 'Named Routes', debugShowCheckedModeBanner: false, initialRoute: '/', routes: { '/': (context) => const firstRoute(), '/second': (context) => const secondRoute(), }, )); } // ignore: camel_case_types class firstRoute extends StatelessWidget { const firstRoute({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('GFG First Route'), backgroundColor: Colors.green, foregroundColor: Colors.white, ), body: Center( child: ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: Colors.green, foregroundColor: Colors.white), child: const Text('Launch screen'), onPressed: () { Navigator.pushNamed(context, '/second'); }, ), // Elevated ), ); } } // ignore: camel_case_types class secondRoute extends StatelessWidget { const secondRoute({Key? key}) : super(key: key); @override // ignore: dead_code Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text("GFG Second Route"), backgroundColor: Colors.green, foregroundColor: Colors.white, ), body: Center( child: ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: Colors.green, foregroundColor: Colors.white), onPressed: () { Navigator.pop(context); }, child: const Text('Go back!'), ), // ElevatedButton ), ); } }