{"id":1449,"date":"2023-12-06T05:19:53","date_gmt":"2023-12-06T05:19:53","guid":{"rendered":"https:\/\/www.devopssupport.in\/blog\/?p=1449"},"modified":"2024-01-03T05:23:16","modified_gmt":"2024-01-03T05:23:16","slug":"navigating-between-screens-in-flutter-a-step-by-step-guide","status":"publish","type":"post","link":"https:\/\/www.devopssupport.in\/blog\/navigating-between-screens-in-flutter-a-step-by-step-guide\/","title":{"rendered":"Navigating Between Screens in Flutter: A Step-by-Step Guide"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Set Up Your Project<\/h3>\n\n\n\n<p>Start by creating two new Dart files, naming them &#8220;home.dart&#8221; and &#8220;about.dart.&#8221; These will represent the two screens you&#8217;ll navigate between.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Import Dependencies<\/h3>\n\n\n\n<p>In your <code>main.dart<\/code> file, ensure you import the necessary material library and the Dart files you just created:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import 'package:flutter\/material.dart';\r\nimport 'home.dart';\r\n\r\nvoid main() {\r\n  runApp(MaterialApp(\r\n    home: Scaffold(\r\n      appBar: AppBar(\r\n        title: Text(\"Navigation App\"),\r\n      ),\r\n      body: Home(),\r\n    ),\r\n  ));\r\n}\r\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Implement Navigation<\/h3>\n\n\n\n<p>In your <code>home.dart<\/code> file, create a Stateful Widget named <code>Home<\/code> with a <code>RaisedButton<\/code>. This button will trigger the navigation to the &#8220;About&#8221; screen when pressed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import 'package:flutter\/material.dart';\r\nimport 'about.dart';\r\n\r\nclass Home extends StatefulWidget {\r\n  @override\r\n  State&lt;StatefulWidget> createState() {\r\n    return _HomeState();\r\n  }\r\n}\r\n\r\nclass _HomeState extends State&lt;Home> {\r\n  @override\r\n  Widget build(BuildContext context) {\r\n    return Container(\r\n      child: Column(\r\n        children: &lt;Widget>&#91;\r\n          RaisedButton(\r\n            onPressed: () {\r\n              Navigator.push(context, MaterialPageRoute(builder: (context) {\r\n                return About();\r\n              }));\r\n            },\r\n            child: Text(\"Go to About Screen\"),\r\n          ),\r\n        ],\r\n      ),\r\n    );\r\n  }\r\n}\r\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"> Create the About Screen<\/h3>\n\n\n\n<p>In your <code>about.dart<\/code> file, create a Stateless Widget named <code>About<\/code> with a simple <code>Scaffold<\/code> containing an <code>AppBar<\/code> and a <code>Text<\/code> widget in the body.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import 'package:flutter\/material.dart';\r\n\r\nclass About extends StatelessWidget {\r\n  @override\r\n  Widget build(BuildContext context) {\r\n    return Scaffold(\r\n      appBar: AppBar(\r\n        title: Text(\"About Screen\"),\r\n      ),\r\n      body: Center(\r\n        child: Text(\"This is About Screen\"),\r\n      ),\r\n    );\r\n  }\r\n}\r\n<\/code><\/pre>\n\n\n\n<p>With these steps completed, you&#8217;re ready to run your Flutter project.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Set Up Your Project Start by creating two new Dart files, naming them &#8220;home.dart&#8221; and &#8220;about.dart.&#8221; These will represent the two screens you&#8217;ll navigate between. Import Dependencies&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[801,791,804,805,787,788,796,794,799,800,802,793,789,798,803,790,797,792,806,795],"class_list":["post-1449","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-cross-platform-development","tag-dart-programming","tag-flutter-app-structure","tag-flutter-best-practices","tag-flutter-development","tag-flutter-navigation","tag-flutter-routes","tag-flutter-screens","tag-flutter-stateful-widget","tag-flutter-statelesswidget","tag-flutter-ui","tag-flutter-widgets","tag-materialapp","tag-materialpageroute","tag-mobile-app-design","tag-mobile-app-development","tag-raised-button","tag-scaffold-widget","tag-software-development-2","tag-ui-navigation"],"_links":{"self":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/comments?post=1449"}],"version-history":[{"count":1,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1449\/revisions"}],"predecessor-version":[{"id":1450,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/1449\/revisions\/1450"}],"wp:attachment":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/media?parent=1449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/categories?post=1449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/tags?post=1449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}