0% found this document useful (0 votes)
5 views2 pages

Flutter Navigation Setup Guide

The document provides a Flutter code example for setting up navigation between two screens using the Navigator. It defines a main application with a HomeScreen that contains a button to navigate to a NewScreen. The NewScreen displays a simple message indicating it is a new screen.

Uploaded by

motevinay
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Flutter Navigation Setup Guide

The document provides a Flutter code example for setting up navigation between two screens using the Navigator. It defines a main application with a HomeScreen that contains a button to navigate to a NewScreen. The NewScreen displays a simple message indicating it is a new screen.

Uploaded by

motevinay
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Week-4(b): Setup navigation between different screens using

Navigator.

import 'package:flutter/[Link]';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context){
return MaterialApp(title:'FlutterDemo',
theme:ThemeData(primarySwatch:[Link]), home: HomeScreen(),
);
}
}
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context){
return Scaffold(
appBar:AppBar(title:const Text('HomeScreen')),
body: Center(child:ElevatedButton(
child: const Text('Navigate to a new screen >>',
style:TextStyle(fontSize:24.0),
),
onPressed:() {
_navigateToNextScreen(context);
},
),
),
);
}
void _navigateToNextScreen(BuildContext context) {
[Link](context).push(MaterialPageRoute(builder:(context)=>
NewScreen()));
}
}
class NewScreen extends StatelessWidget {
@override
Widget build(BuildContext context){ return Scaffold(
appBar:AppBar(title:const Text('NewScreen')), body: const Center(
child:Text('This is a new screen',style:TextStyle(fontSize:24.0),
),
),
);
}
}

You might also like