{"id":10055,"date":"2024-04-04T04:55:16","date_gmt":"2024-04-04T04:55:16","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=10055"},"modified":"2024-04-04T04:55:16","modified_gmt":"2024-04-04T04:55:16","slug":"flutter-text-and-text-color-not-updated-after-hot-reload","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/flutter\/flutter-text-and-text-color-not-updated-after-hot-reload","title":{"rendered":"Flutter Text and Text Color Not Updated After Hot Reload"},"content":{"rendered":"<p>To ensure that UI changes reflect properly after hot reload, it&#8217;s important to make those changes within the widget itself rather than relying on the <strong>main()<\/strong> function, which is executed only once in the entire app session.<\/p>\n<p>Widget should have the text color change within the <strong>build<\/strong> method of the <strong>_MyHomePageState<\/strong> widget. Here&#8217;s the example to follow:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import 'package:flutter\/material.dart';\r\n\r\nvoid main() {\r\n runApp(const MyApp());\r\n}\r\n\r\nclass MyApp extends StatelessWidget {\r\n const MyApp({super.key});\r\n @override\r\n Widget build(BuildContext context) {\r\n   return MaterialApp(\r\n     title: 'Flutter Demo',\r\n     theme: ThemeData(\r\n       colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),\r\n       useMaterial3: true,\r\n     ),\r\n     home: const MyHomePage(),\r\n   );\r\n }\r\n}\r\n\r\nclass MyHomePage extends StatefulWidget {\r\n const MyHomePage({super.key});\r\n @override\r\n State&lt;MyHomePage&gt; createState() =&gt; _MyHomePageState();\r\n}\r\n\r\nclass _MyHomePageState extends State&lt;MyHomePage&gt; {\r\n @override\r\n Widget build(BuildContext context) {\r\n   return const Scaffold(\r\n     body: SafeArea(\r\n       child: Center(\r\n         child: Text(\r\n           'Bacancy',\r\n           style: TextStyle(\r\n             color: Colors.red, \/\/ text color \r\n           ),\r\n         ),\r\n       ),\r\n     ),\r\n   );\r\n }\r\n}\r\n<\/pre>\n<p>By placing the text color change directly within the <strong>build<\/strong> method of the <strong>_MyHomePageState<\/strong> widget, any modifications to the text color will be reflected correctly after hot reload.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To ensure that UI changes reflect properly after hot reload, it&#8217;s important to make those changes within the widget itself rather than relying on the main() function, which is executed only once in the entire app session. Widget should have the text color change within the build method of the _MyHomePageState widget. Here&#8217;s the example [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":10056,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[15],"tags":[],"class_list":["post-10055","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-flutter"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/10055"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=10055"}],"version-history":[{"count":2,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/10055\/revisions"}],"predecessor-version":[{"id":10058,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/10055\/revisions\/10058"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/10056"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=10055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=10055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=10055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}