Created
May 14, 2025 23:04
-
-
Save sethladd/97d0daccec76ddaa2627261689dd2565 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Navigation Demo', | |
theme: ThemeData(primarySwatch: Colors.blue), | |
home: const FirstScreen(), | |
); | |
} | |
} | |
class FirstScreen extends StatelessWidget { | |
const FirstScreen({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: const Text('First Screen')), | |
body: Center( | |
child: ElevatedButton( | |
child: const Text('Go to Second Screen'), | |
onPressed: () { | |
Navigator.push( | |
context, | |
MaterialPageRoute(builder: (context) => const SecondScreen()), | |
); | |
}, | |
), | |
), | |
); | |
} | |
} | |
class SecondScreen extends StatelessWidget { | |
const SecondScreen({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: const Text('Second Screen')), | |
body: Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Column( | |
children: [ | |
const TextField( | |
decoration: InputDecoration(hintText: 'Enter text here'), | |
), | |
const SizedBox(height: 20), | |
ElevatedButton( | |
onPressed: () { | |
Navigator.pop(context); | |
}, | |
child: const Text('Go back'), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment