<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rashpinder Singh on Medium]]></title>
        <description><![CDATA[Stories by Rashpinder Singh on Medium]]></description>
        <link>https://medium.com/@flutter.rashpinder?source=rss-7e8fb1fbf562------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*enTEfpSLVQFTQ0qj.jpg</url>
            <title>Stories by Rashpinder Singh on Medium</title>
            <link>https://medium.com/@flutter.rashpinder?source=rss-7e8fb1fbf562------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 06:35:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@flutter.rashpinder/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Flutter Web Shortcuts with Intent Actions — Part 4 (Material App Widget)]]></title>
            <link>https://medium.com/@flutter.rashpinder/flutter-web-shortcuts-with-intent-actions-part-4-material-app-widget-269d39a6494b?source=rss-7e8fb1fbf562------2</link>
            <guid isPermaLink="false">https://medium.com/p/269d39a6494b</guid>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[future]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[future-of-work]]></category>
            <dc:creator><![CDATA[Rashpinder Singh]]></dc:creator>
            <pubDate>Sun, 17 Sep 2023 11:25:56 GMT</pubDate>
            <atom:updated>2023-09-17T11:27:51.431Z</atom:updated>
            <content:encoded><![CDATA[<h3>Material App Widget : Flutter Web Shortcuts with Intent Actions — Part 5 -</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*zIecNsnz3fEMS42tynIJCw.png" /></figure><p>Welcome to our in-depth guide on the Material App widget for Flutter. A key component of creating a Flutter application is the Material App widget, which unites the interface and visual design elements that comply to the Material Design principles. This post will discuss the Material App widget, its features, and how to use it in real-world Flutter applications.</p><p>If you haven’t read the first installment in this series, go here.<br><a href="https://medium.com/@flutter.rashpinder/flutters-the-material-app-widget-a-developer-s-guided-series-part-1-cded465e6e8e"><strong><em>Part -1</em></strong></a><strong><em> and </em></strong><a href="https://medium.com/@flutter.rashpinder/flutters-the-material-app-widget-a-developer-s-guided-series-part-2-21f1ef780890"><strong><em>Part -2</em></strong></a></p><p>You can use the shortcuts property of MaterialApp to define keyboard shortcuts that trigger specific actions (intents) in your app. To do this, you&#39;ll need to create a Map&lt;ShortcutActivator, Intent&gt; that maps keyboard key combinations to intents. You&#39;ll also need to create Actions that define how to handle those intents.</p><p>Here’s a complete example of using shortcuts in MaterialApp:</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:flutter/services.dart&#39;;<br><br>void main() {<br>  runApp(const IntentApp());<br>}<br><br>class IntentApp extends StatelessWidget {<br>  const IntentApp({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;Flutter Demo&#39;,<br>      theme: ThemeData(<br>        primarySwatch: Colors.blue,<br>      ),<br>      home: const MyHomePage(title: &#39;Flutter Demo Home Page&#39;),<br>      shortcuts: {<br>        LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyD):<br>            const SaveIntent(),<br>        // Add more keyboard shortcuts here<br>      },<br>      actions: {<br>        SaveIntent: CallbackAction(onInvoke: (Intent intent) =&gt; _saveData()),<br>        CustomButtonTapIntent: CallbackAction(<br>            onInvoke: (Intent intent) =&gt; _handleCustomButtonTap()),<br>        // Add more actions for other intents here<br>      },<br>    );<br>  }<br><br>  void _saveData() {<br>    print(&#39;Data saved&#39;);<br>  }<br>  void _handleCustomButtonTap() {<br>    print(&#39;Custom button tapped&#39;);<br>  }<br>}<br><br>class MyHomePage extends StatelessWidget {<br>  const MyHomePage({Key? key, required this.title}) : super(key: key);<br><br>  final String title;<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(<br>        title: Text(title),<br>      ),<br>      body:  Center(<br>        child: Column(<br>          mainAxisAlignment: MainAxisAlignment.center,<br>          children: &lt;Widget&gt;[<br>            const Text(&#39;Press &quot;Alt + S&quot; to trigger the save action.&#39;),<br>            Actions(<br>              actions: {<br>                CustomButtonTapIntent: CallbackAction(<br>                    onInvoke: (Intent intent) =&gt; _handleCustomButtonTap()),<br>              },<br>              child: CustomButton(),<br>            ),<br>          ],<br>        ),<br>      ),<br>    );<br>  }<br>   void _handleCustomButtonTap() {<br>    print(&#39;Custom button tapped&#39;);<br>  }<br>}<br><br>class SaveIntent extends Intent {<br>  const SaveIntent();<br>}<br>class CustomButton extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return GestureDetector(<br>      onTap: () {<br>        final action = Actions.handler&lt;CustomButtonTapIntent&gt;(<br>            context, const CustomButtonTapIntent());<br>        action?.call();<br>      },<br>      child: Container(<br>        padding: const EdgeInsets.all(16),<br>        decoration: BoxDecoration(<br>          color: Colors.blue,<br>          borderRadius: BorderRadius.circular(8),<br>        ),<br>        child: const Text(<br>          &#39;Custom Button&#39;,<br>          style: TextStyle(color: Colors.white),<br>        ),<br>      ),<br>    );<br>  }<br>}<br><br>class CustomButtonTapIntent extends Intent {<br>  const CustomButtonTapIntent();<br>}</pre><p>the actions property of MaterialApp is used to define how different intents should be handled when triggered. This property is platform-agnostic and works for both Android and iOS. Here&#39;s a complete example of using the actionsproperty in MaterialApp along with shortcuts for a Flutter app:</p><p>In Above example, we create a custom button widget called CustomButton. When the button is tapped, it triggers the CustomButtonTapIntent. We define an action that handles the CustomButtonTapIntent by calling the _handleCustomButtonTapmethod:</p><pre>actions: {<br>  CustomButtonTapIntent: CallbackAction(onInvoke: (Intent intent) =&gt; _handleCustomButtonTap()),<br>  // Add more actions for other intents here<br>},</pre><pre>Actions(<br>  actions: {<br>    CustomButtonTapIntent: CallbackAction(onInvoke: (Intent intent) =&gt; _handleCustomButtonTap()),<br>  },<br>  child: CustomButton(),<br>),</pre><p>When the custom button is tapped, the _handleCustomButtonTap method will be called, and the app will print &quot;Custom button tapped&quot; in the console.</p><p>You can check whole code at Github repository <a href="https://github.com/rashpinderleanix/flutter-widget-series">Flutter-Widget-Series.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=269d39a6494b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Material App Widget: A Developer’s Guided Series — Part 4]]></title>
            <link>https://medium.com/@flutter.rashpinder/the-material-app-widget-a-developers-guided-series-part-4-85d6bc06be3a?source=rss-7e8fb1fbf562------2</link>
            <guid isPermaLink="false">https://medium.com/p/85d6bc06be3a</guid>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[material-design]]></category>
            <category><![CDATA[future-of-work]]></category>
            <dc:creator><![CDATA[Rashpinder Singh]]></dc:creator>
            <pubDate>Sun, 17 Sep 2023 09:56:50 GMT</pubDate>
            <atom:updated>2023-09-17T09:56:50.552Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Material App Widget: A Developer’s Guided Series — Part 4</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*zIecNsnz3fEMS42tynIJCw.png" /></figure><p>Welcome to our in-depth guide on the Material App widget for Flutter. A key component of creating a Flutter application is the Material App widget, which unites the interface and visual design elements that comply to the Material Design principles. This post will discuss the Material App widget, its features, and how to use it in real-world Flutter applications.</p><p>If you haven’t read the first installment in this series, go here.<br><a href="https://medium.com/@flutter.rashpinder/flutters-the-material-app-widget-a-developer-s-guided-series-part-1-cded465e6e8e"><strong><em>Part -1</em></strong></a><strong><em> and </em></strong><a href="https://medium.com/@flutter.rashpinder/flutters-the-material-app-widget-a-developer-s-guided-series-part-2-21f1ef780890"><strong><em>Part -2</em></strong></a><strong><em> and </em></strong><a href="https://medium.com/@flutter.rashpinder/the-material-app-widget-a-developers-guided-series-part-3-db18aed53585"><strong><em>Part-3</em></strong></a></p><h3>Summary of Contents</h3><ol><li>How to implement <strong><em>LocaleListResolutionCallback</em></strong> <strong><em>localeListResolutionCallback?</em></strong></li><li>How to implement <strong><em>LocaleResolutionCallback localeResolutionCallback ?</em></strong></li><li>Usage of <strong><em>bool</em></strong> <strong><em>checkerboardRasterCacheImages.</em></strong></li></ol><h3>How to implement <strong>LocaleListResolutionCallback</strong> <strong><em>localeListResolutionCallback?</em></strong></h3><p>A callback called <strong><em>LocaleListResolution</em></strong>? When the device has many preferred locales, the <strong><em>localeListResolutionCallback</em></strong> optional callback in the <strong><em>MaterialApp</em></strong> widget lets you tailor the locale resolution process. You may specify how your app should select the ideal locale from the list of supported locales and the device’s preferred locales by <strong><em>implementing</em></strong> this callback.</p><pre>void main() {<br>  runApp(const MyApp());<br>}<br><br>class MyApp extends StatelessWidget {<br>  const MyApp({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;Flutter Demo&#39;,<br>      theme: ThemeData(<br>        primarySwatch: Colors.blue,<br>      ),<br>      home: const HomePage(),<br>      localizationsDelegates: const [<br>        // Add the localization delegates for Material, Cupertino, and your custom delegate<br>        GlobalMaterialLocalizations.delegate,<br>        GlobalWidgetsLocalizations.delegate,<br>        GlobalCupertinoLocalizations.delegate,<br>        MyLocalizationsDelegate(), // Add your custom localization delegate<br>      ],<br>      supportedLocales: const [<br>         Locale(&#39;en&#39;, &#39;US&#39;), // English, United States<br>         Locale(&#39;es&#39;, &#39;ES&#39;), // Spanish, Spain<br>        // Other locales can be added here<br>      ],<br>      localeListResolutionCallback:<br>          (List&lt;Locale&gt;? locales, Iterable&lt;Locale&gt; supportedLocales) {<br>        // Your custom logic to choose the best locale<br>        for (final locale in locales!) {<br>          if (supportedLocales.contains(locale)) {<br>            return locale;<br>          }<br>        }<br>        // If no match is found, return the first supported locale<br>        return supportedLocales.first;<br>      },<br>    );<br>  }<br>}</pre><p>In above example, the localeListResolutionCallback takes two parameters:</p><ol><li>List&lt;Locale&gt;? locales: The list of the device&#39;s preferred locales.</li><li>Iterable&lt;Locale&gt; supportedLocales: The list of locales supported by your app.</li></ol><p>The callback iterates through the device’s preferred locales and checks if any of them are in the list of supported locales. If a match is found, it returns that locale. If no match is found, it returns the first supported locale as the default.</p><p>By implementing the localeListResolutionCallback, you can customize how your app selects the best locale when the device has multiple preferred locales.</p><h3>How to implement <strong><em>LocaleResolutionCallback localeResolutionCallback ?</em></strong></h3><p>How about the <strong><em>LocaleResolutionCallback</em></strong>? When the device has a single preferred locale, the <strong><em>localeResolutionCallback</em></strong> optional callback in the <strong><em>MaterialApp</em></strong> widget lets you alter the locale resolution mechanism. You may specify how your app should select the ideal locale from the list of available locales and the device’s preferred locale by implementing this callback.</p><pre> localeResolutionCallback:<br>          (Locale? locale, Iterable&lt;Locale&gt; supportedLocales) {<br>        // Your custom logic to choose the best locale<br>        if (locale == null) {<br>          return supportedLocales.first;<br>        }<br><br>        for (final supportedLocale in supportedLocales) {<br>          if (supportedLocale.languageCode == locale.languageCode &amp;&amp;<br>              supportedLocale.countryCode == locale.countryCode) {<br>            return supportedLocale;<br>          }<br>        }<br><br>        // If no exact match is found, return the first supported locale with the same language code<br>        for (final supportedLocale in supportedLocales) {<br>          if (supportedLocale.languageCode == locale.languageCode) {<br>            return supportedLocale;<br>          }<br>        }<br><br>        // If no match is found, return the first supported locale<br>        return supportedLocales.first;<br>      },</pre><p>In above example, the localeResolutionCallback takes two parameters:</p><ol><li>Locale? locale: The device&#39;s preferred locale.</li><li>Iterable&lt;Locale&gt; supportedLocales: The list of locales supported by your app.</li></ol><p>The callback first checks if the preferred locale is null, in which case it returns the first supported locale. Then, it iterates through the supported locales, checking for an exact match with the preferred locale. If an exact match is found, it returns that locale. If no exact match is found, it returns the first supported locale with the same language code as the preferred locale. If there&#39;s still no match, it returns the first supported locale as the default.</p><p>By implementing the localeResolutionCallback, you can customize how your app selects the best locale when the device has a single preferred locale.</p><h3>Usage of <strong><em>bool</em></strong> <strong><em>checkerboardRasterCacheImages</em></strong></h3><p>The Material App widget supports the <strong><em>checkerboardRasterCacheImages</em></strong> feature. During development, it is used to display the raster cache pictures in a checkerboard pattern, which may be utilised to spot performance problems with image caching.</p><p>You must set the <strong><em>showPerformanceOverlay</em></strong> and <strong><em>checkerboardRasterCacheImages</em></strong> attributes of the MaterialApp widget to true in order to use <strong><em>checkerboardRasterCacheImages</em></strong> in your MaterialApp. Here’s an illustration:</p><pre>   showPerformanceOverlay: true, // Enable the performance overlay<br>   checkerboardRasterCacheImages:<br>          true, // Enable checkerboard pattern for raster cache images</pre><p>In this example, the showPerformanceOverlay and checkerboardRasterCacheImages properties are set to true in the MaterialAppwidget. This will enable the performance overlay and the checkerboard pattern for raster cache images in your app. When you run the app, you&#39;ll see a checkerboard pattern on images that are being cached, along with the performance overlay.</p><p>Keep in mind that these features are intended for development use only and should not be enabled in production. To disable the checkerboard pattern and performance overlay, set showPerformanceOverlay and checkerboardRasterCacheImages back to false.</p><p>The Flutter Material App widget, which is essential for creating Material Design apps, was investigated in this blog article. We studied the fundamental characteristics of our applications and learned how to properly use them in order to modify the way they appear and behave. Using the Material App widget, you can create apps that adhere to the Material Design tenets and are aesthetically pleasing and uniform.</p><p>You can check whole code at <strong><em>Github</em></strong> repository <a href="https://github.com/rashpinderleanix/flutter-widget-series">Flutter-Widget-Series.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85d6bc06be3a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Material App Widget: A Developer’s Guided Series — Part 3]]></title>
            <link>https://medium.com/@flutter.rashpinder/the-material-app-widget-a-developers-guided-series-part-3-db18aed53585?source=rss-7e8fb1fbf562------2</link>
            <guid isPermaLink="false">https://medium.com/p/db18aed53585</guid>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[future-technology]]></category>
            <category><![CDATA[future-of-work]]></category>
            <dc:creator><![CDATA[Rashpinder Singh]]></dc:creator>
            <pubDate>Thu, 07 Sep 2023 19:35:16 GMT</pubDate>
            <atom:updated>2023-09-17T09:57:43.481Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Material App Widget: A Developer’s Guided Series — Part 3</h3><p>Welcome to our in-depth guide on the Material App widget for Flutter. A key component of creating a Flutter application is the Material App widget, which unites the interface and visual design elements that comply to the Material Design principles. This post will discuss the Material App widget, its features, and how to use it in real-world Flutter applications.</p><p>If you haven’t read the first installment in this series, go here.<br><a href="https://medium.com/@flutter.rashpinder/flutters-the-material-app-widget-a-developer-s-guided-series-part-1-cded465e6e8e"><strong><em>Part -1</em></strong></a><strong><em> and </em></strong><a href="https://medium.com/@flutter.rashpinder/flutters-the-material-app-widget-a-developer-s-guided-series-part-2-21f1ef780890"><strong><em>Part -2</em></strong></a></p><h3>Summary of Contents</h3><ol><li>Usage of <strong><em>BackButtonDispatcher</em></strong> and <strong><em>backButtonDispatcher</em></strong></li><li>Usage of <strong><em>TransitionBuilder</em></strong> and <strong><em>builder</em></strong></li><li>Usage of <strong><em>Locale</em></strong>? locale</li><li>Usage of <strong><em>Iterable&lt;LocalizationsDelegate&lt;dynamic&gt;&gt;?</em></strong> <strong><em>localizationsDelegates</em></strong></li></ol><h3>Usage of BackButtonDispatcher and backButtonDispatcher</h3><p>When utilising the Router API for navigation, <strong><em>BackButtonDispatcher</em></strong> is an abstract class that may be customised to handle the Android back button press event. It is utilised in the <strong><em>MaterialApp.router </em></strong>constructor’s <strong><em>backButtonDispatcher</em></strong> property. You may manage how the back button push event is handled in your app by utilising a customised <strong><em>BackButtonDispatcher</em></strong>.</p><pre>import &#39;package:flutter/material.dart&#39;;<br><br>class CustomBackButtonDispatcher extends RootBackButtonDispatcher {<br>  @override<br>  Future&lt;bool&gt; invokeCallback(Future&lt;bool&gt; defaultValue) {<br>    print(&#39;Back button pressed&#39;);<br>    return super.invokeCallback(defaultValue);<br>  }<br>}</pre><p>The <strong><em>CustomBackButtonDispatcher</em></strong> class in the above example extends <strong><em>RootBackButtonDispatcher</em></strong> and overrides the <strong><em>invokeCallback</em></strong> function to print a message when the back button is hit. The <strong><em>CustomBackButtonDispatcher</em></strong> was then utilised in the MaterialApp.router constructor as the <strong><em>backButtonDispatcher</em></strong>.</p><p>Additionally, we developed a <strong><em>CustomRouteInformationParser</em></strong> to manage the parsing and restoration of route information as well as a <strong>CustomRouterDelegate</strong> to handle the routing logic. The <strong><em>onButtonPressed</em></strong> callback of the <strong><em>HomePage</em></strong> and <strong><em>SecondPage</em></strong> widgets modifies the <strong><em>CustomRouterDelegate’s</em></strong> current route.</p><p>The <strong><em>“Back button pressed”</em></strong> message will be printed to the console when you run this example and hit the back button on your Android device.</p><h3>Usage of TransitionBuilder and builder</h3><p>A <strong><em>TransitionBuilder</em></strong> function type accepts a <strong><em>BuildContext</em></strong> and a <strong><em>Widget</em></strong> as inputs and outputs a <strong><em>Widget</em></strong>. When applied to the <strong><em>MaterialApp</em></strong> widget, the builder property is used to create a custom widget that encompasses the whole application. This may be <strong><em>advantageous</em></strong> for implementing overall themes and styles as well as for offering inherited widgets that are available across the board.</p><pre>class MyApp extends StatelessWidget {<br>  final CustomRouteInformationProvider _customRouteInformationProvider =<br>      CustomRouteInformationProvider();<br><br>  MyApp({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp.router(<br>      title: &#39;Route Information Provider Demo&#39;,<br>      routerDelegate: CustomRouterDelegate(),<br>      backButtonDispatcher: CustomBackButtonDispatcher(),<br>      routeInformationParser: CustomRouteInformationParser(),<br>      routeInformationProvider:<br>          _customRouteInformationProvider,<br>        // Use the custom RouteInformationProvider<br>      builder: _customAppBuilder,<br>    );<br>  }<br>  Widget _customAppBuilder(BuildContext context, Widget? child) {<br>    // Wrap the entire app in a custom widget, in this case, a SafeArea<br>    return SafeArea(<br>      child: child ?? const SizedBox.shrink(),<br>    );<br>  }<br>}</pre><p>The <strong>Widget</strong> (the child widget) and <strong><em>BuildContext</em></strong> parameters are sent to the <strong><em>_customAppBuilder</em></strong> method in the aforementioned example, which produces a <strong><em>Widget</em></strong>. After that, we utilised this method as the MaterialApp widget’s builder property.</p><p>with this instance, we wrapped the whole programme with a <strong><em>SafeArea</em></strong> widget to make sure that its user interface didn’t interfere with any system UI components, such as the status bar or, on smartphones with asymmetrical screens, the notch. This is only one illustration of how you may utilise the builder property in <strong><em>MaterialApp</em></strong>; you can also use it to apply global themes, styles, or offer inherited widgets that are available across the app.</p><h3>Usage of <strong><em>Locale</em></strong>? locale</h3><p>The <strong><em>locale</em></strong> for your application may be specified using the <strong><em>final Locale? locale</em></strong>, an optional parameter in the MaterialApp widget. It chooses the linguistic and grammatical rules that are applied across your programme, including text direction, date, time, and number forms.</p><p>Here is a quick breakdown of the usage:</p><p>A <strong><em>locale</em></strong> is a designation for a particular language and <strong><em>geographical</em></strong> area. A language code (such as “en” for English) plus a possible nation code (such as “US” for the United States) make up the code.<br>The MaterialApp is a top-level widget that, in accordance with the Material Design principles, gives your app a unified visual identity and behaviour. Additionally, <strong><em>it manages theme customization, localization, and navigation.</em></strong><br>You may supply a Locale object to MaterialApp to set the locale.</p><pre>class MyApp extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;Flutter Demo&#39;,<br>      theme: ThemeData(<br>        primarySwatch: Colors.blue,<br>      ),<br>      home: MyHomePage(title: &#39;Flutter Demo Home Page&#39;),<br>      locale: Locale(&#39;en&#39;, &#39;US&#39;), // Set the locale to English, United States<br>    );<br>  }<br>}</pre><h3>Usage of <strong><em>Iterable&lt;LocalizationsDelegate&lt;dynamic&gt;&gt;?</em></strong> <strong><em>localizationsDelegates</em></strong></h3><p>Follow these steps to develop your own unique LocalizationsDelegate and utilise it with LocalizationsDelegates in MaterialApp:</p><ol><li>Make a class called MyLocalizations to house your own localization.</li><li>In that class, define a method that returns the localised values for a given key.</li><li>Adapt LocalizationsDelegateMyLocalizations&gt; to create a unique LocalizationsDelegate class.</li><li>To load the localised data based on the current locale, implement the load method in your custom delegate.</li><li>Include your unique delegate in the MaterialApp list of localizationsDelegates.</li></ol><pre><br>import &#39;package:flutter/foundation.dart&#39;;<br>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:flutter_localizations/flutter_localizations.dart&#39;;<br><br>void main() {<br>  runApp(const MyApp());<br>}<br><br>class MyApp extends StatelessWidget {<br>  const MyApp({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;Flutter Demo&#39;,<br>      theme: ThemeData(<br>        primarySwatch: Colors.blue,<br>      ),<br>      home: const HomePage(),<br>      localizationsDelegates: const [<br>        // Add the localization delegates for Material, Cupertino, and your custom delegate<br>        GlobalMaterialLocalizations.delegate,<br>        GlobalWidgetsLocalizations.delegate,<br>        GlobalCupertinoLocalizations.delegate,<br>        MyLocalizationsDelegate(), // Add your custom localization delegate<br>      ],<br>      supportedLocales: const [<br>         Locale(&#39;en&#39;, &#39;US&#39;), // English, United States<br>         Locale(&#39;es&#39;, &#39;ES&#39;), // Spanish, Spain<br>        // Other locales can be added here<br>      ],<br>    );<br>  }<br>}<br><br>class MyLocalizations {<br>  MyLocalizations(this.locale);<br><br>  final Locale locale;<br><br>  static MyLocalizations? of(BuildContext context) {<br>    return Localizations.of&lt;MyLocalizations&gt;(context, MyLocalizations);<br>  }<br><br>  // Define a method to get localized values for a specific key<br>  String get hello {<br>    return _localizedValues[locale.languageCode]![&#39;hello&#39;]!;<br>  }<br><br>  static final Map&lt;String, Map&lt;String, String&gt;&gt; _localizedValues = {<br>    &#39;en&#39;: {<br>      &#39;hello&#39;: &#39;Hello&#39;,<br>    },<br>    &#39;es&#39;: {<br>      &#39;hello&#39;: &#39;Hola&#39;,<br>    },<br>  };<br>}<br><br>class MyLocalizationsDelegate extends LocalizationsDelegate&lt;MyLocalizations&gt; {<br>  const MyLocalizationsDelegate();<br><br>  @override<br>  bool isSupported(Locale locale) {<br>    return [&#39;en&#39;, &#39;es&#39;].contains(locale.languageCode);<br>  }<br><br>  @override<br>  Future&lt;MyLocalizations&gt; load(Locale locale) {<br>    return SynchronousFuture&lt;MyLocalizations&gt;(MyLocalizations(locale));<br>  }<br><br>  @override<br>  bool shouldReload(MyLocalizationsDelegate old) =&gt; false;<br>}<br><br>class HomePage extends StatelessWidget {<br>  const HomePage({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(title: const Text(&#39;Home Page&#39;)),<br>      body: Center(<br>        child: ElevatedButton(<br>          onPressed: () {<br>            // Navigate to SecondPage using the onGenerateRoute<br>            Navigator.pushNamed(<br>              context,<br>              &#39;/second&#39;,<br>              arguments: &#39;Hello from Home Page!&#39;,<br>            );<br>          },<br>          child: const Text(&#39;Go to Second Page&#39;),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>Now, you can use your custom localization in your app like this:</p><pre>Text(MyLocalizations.of(context).hello)</pre><p><a href="https://medium.com/@flutter.rashpinder/the-material-app-widget-a-developers-guided-series-part-4-85d6bc06be3a"><strong><em>Part-4</em></strong></a><br>You can check whole code at Github repository <a href="https://github.com/rashpinderleanix/flutter-widget-series">Flutter-Widget-Series.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db18aed53585" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter’s The Material App Widget: A Developer’s Guided Series — Part 2]]></title>
            <link>https://medium.com/@flutter.rashpinder/flutters-the-material-app-widget-a-developer-s-guided-series-part-2-21f1ef780890?source=rss-7e8fb1fbf562------2</link>
            <guid isPermaLink="false">https://medium.com/p/21f1ef780890</guid>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[future-of-work]]></category>
            <category><![CDATA[construction-material-app]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[future-technology]]></category>
            <dc:creator><![CDATA[Rashpinder Singh]]></dc:creator>
            <pubDate>Tue, 05 Sep 2023 19:07:40 GMT</pubDate>
            <atom:updated>2023-09-07T19:37:39.990Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Material App Widget: A Developer’s Guided Series — Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kvCpcqLrpbDvsRTCX5zuAA.jpeg" /></figure><blockquote><em>Welcome to this thorough tutorial to Flutter’s Material App widget. The Material App widget unifies the interaction and visual design aspects that adhere to the Material Design standards, making it a crucial part of building a Flutter application. The Material App widget, its characteristics, and practical Flutter application usage will all be covered in this article.</em></blockquote><p>If you haven’t read the first installment in this series, go here.<br><a href="https://medium.com/@flutter.rashpinder/flutters-the-material-app-widget-a-developer-s-guided-series-part-1-cded465e6e8e"><strong><em>Part -1</em></strong></a></p><h3>Summary of Contents</h3><ol><li>Usage of <strong><em>InitialRouteListFactory</em></strong> and <strong><em>onGenerateInitialRoutes</em></strong></li><li>Usage of <strong><em>onUnknownRoute</em></strong></li><li>Usage of <strong><em>List&lt;NavigatorObserver&gt;</em></strong> and <strong><em>navigatorObservers</em></strong></li><li>Usage of <strong><em>RouteInformationProvider</em></strong> and <strong><em>routeInformationProvider</em></strong></li></ol><h3>Usage of InitialRouteListFactory and onGenerateInitialRoutes</h3><p>A function type called <strong><em>InitialRouteListFactory</em></strong> accepts a String (the beginning route) as an input and outputs a <strong><em>ListRoute&lt;dynamic</em></strong>&gt;. It is used to build a list of routes for the first navigation stack based on the initial route in the <strong><em>onGenerateInitialRoutes</em></strong> property of the <strong><em>MaterialApp</em></strong> widget. You may do this to manage deep linking in your app or to create your own navigation stacks.</p><p>In the example above, we created a _onGenerateInitialRoutes function that takes a String (the initial route) as an argument and returns a List&lt;Route&lt;dynamic&gt;&gt;. We then assigned this function to the onGenerateInitialRoutes property of the MaterialApp widget. This allows us to handle the initial route and create custom navigation stacks based on it.</p><p>In this case, we used _onGenerateInitialRoutes to handle an initial route like /second/42 and create a navigation stack with both HomePage and SecondPage. The SecondPage receives the parsed ID as a parameter. If the initial route doesn&#39;t match the expected pattern, the function returns a single-element list containing the HomePage route.</p><p>Here is an illustration of how to use <strong><em>InitialRouteListFactory</em></strong> in a Flutter app’s <strong><em>onGenerateInitialRoutes</em></strong> method:</p><pre>import &#39;package:flutter/material.dart&#39;;<br><br>void main() {<br>  runApp(const MyApp());<br>}<br><br>class MyApp extends StatelessWidget {<br>  const MyApp({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;On Generate Initial Routes Demo&#39;,<br>      initialRoute: &#39;/second/42&#39;,<br>      onGenerateInitialRoutes:<br>          _onGenerateInitialRoutes, // Assign the _onGenerateInitialRoutes function to MaterialApp<br>    );<br>  }<br><br>  List&lt;Route&lt;dynamic&gt;&gt; _onGenerateInitialRoutes(String initialRoute) {<br>    final uri = Uri.parse(initialRoute);<br>    if (uri.pathSegments.length == 2 &amp;&amp; uri.pathSegments.first == &#39;second&#39;) {<br>      final id = int.tryParse(uri.pathSegments.last);<br>      if (id != null) {<br>        return [<br>          MaterialPageRoute(builder: (context) =&gt; const HomePage()),<br>          MaterialPageRoute(builder: (context) =&gt; SecondPage(id: id)),<br>        ];<br>      }<br>    }<br>    return [MaterialPageRoute(builder: (context) =&gt; const HomePage())];<br>  }<br>}<br><br>class HomePage extends StatelessWidget {<br>  const HomePage({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(title:const Text(&#39;Home Page&#39;)),<br>      body:const Center(child: Text(&#39;Home Page&#39;)),<br>    );<br>  }<br>}<br><br>class SecondPage extends StatelessWidget {<br>  final int id;<br><br>  const SecondPage({super.key, required this.id});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(title: const Text(&#39;Second Page&#39;)),<br>      body: Center(child: Text(&#39;Second Page with ID: $id&#39;)),<br>    );<br>  }<br>}</pre><h3>Usage of onUnknownRoute</h3><p>A <strong><em>RouteSettings</em></strong> object is the input for the function type <strong><em>RouteFactory</em></strong>, which outputs a <strong><em>Route&lt;dynamic&gt;</em></strong>. To handle unregistered or unknown routes in the app, it is utilised in the <strong><em>MaterialApp</em></strong> widget’s onUnknownRoute property. When a user tries to go to an unregistered route, you can utilise this to construct personalised backup routes or show a “<strong><em>404 Not Found</em></strong>” page.</p><p>Here is an illustration of how to use <strong><em>RouteFactory</em></strong> as <strong><em>onUnknownRoute</em></strong> in a Flutter application:</p><pre>class MyApp extends StatelessWidget {<br>  const MyApp({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;On Generate Initial Routes Demo&#39;,<br>      initialRoute: &#39;/second/42&#39;,<br>      onGenerateInitialRoutes:<br>          _onGenerateInitialRoutes,<br>      onUnknownRoute: _onUnknownRoute, // Assign the _onGenerateInitialRoutes function to MaterialApp<br>    );<br>  }<br><br>  List&lt;Route&lt;dynamic&gt;&gt; _onGenerateInitialRoutes(String initialRoute) {<br>    final uri = Uri.parse(initialRoute);<br>    if (uri.pathSegments.length == 2 &amp;&amp; uri.pathSegments.first == &#39;second&#39;) {<br>      final id = int.tryParse(uri.pathSegments.last);<br>      if (id != null) {<br>        return [<br>          MaterialPageRoute(builder: (context) =&gt; const HomePage()),<br>          MaterialPageRoute(builder: (context) =&gt; SecondPage(id: id)),<br>        ];<br>      }<br>    }<br>    return [MaterialPageRoute(builder: (context) =&gt; const HomePage())];<br>  }<br>  Route&lt;dynamic&gt; _onUnknownRoute(RouteSettings settings) {<br>    return MaterialPageRoute(<br>      builder: (context) =&gt; NotFoundPage(routeName: settings.name!),<br>    );<br>  }<br>}<br><br>class NotFoundPage extends StatelessWidget {<br>  final String routeName;<br><br>  const NotFoundPage({super.key, required this.routeName});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(title: const Text(&#39;Not Found&#39;)),<br>      body: Center(<br>        child: Text(&#39;Route &quot;$routeName&quot; not found.&#39;),<br>      ),<br>    );<br>  }<br>}</pre><h3>Usage of List&lt;NavigatorObserver&gt; and navigatorObservers</h3><p>The <strong><em>navigatorObservers</em></strong> attribute of the <strong><em>MaterialApp</em></strong> widget accepts a list of <strong><em>NavigatorObserver</em></strong> objects named<strong><em> List&lt;NavigatorObserver&gt;</em></strong>. It is possible to extend the <strong><em>NavigatorObserver</em></strong> class to listen to navigational events like route pushing and popping. You may observe navigation events in your app with <strong><em>navigatorObservers</em></strong>, and you can take specific actions depending on these events, such as logging, analytics, or UI modifications.</p><p>Here is an illustration of how <strong><em>List&lt;NavigatorObserver&gt;</em></strong> may be used in a Flutter project as <strong><em>navigatorObservers</em></strong>:</p><pre>class MyApp extends StatelessWidget {<br>  MyApp({super.key});<br>  final CustomNavigatorObserver _customNavigatorObserver =<br>      CustomNavigatorObserver();<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;On Generate Initial Routes Demo&#39;,<br>      initialRoute: &#39;/second/42&#39;,<br>      onGenerateInitialRoutes:<br>          _onGenerateInitialRoutes,<br>      navigatorObservers: [<br>        _customNavigatorObserver, // Add the CustomNavigatorObserver to the navigatorObservers list<br>      ],<br>      onUnknownRoute: _onUnknownRoute, // Assign the _onGenerateInitialRoutes function to MaterialApp<br>    );<br>  }<br><br>  List&lt;Route&lt;dynamic&gt;&gt; _onGenerateInitialRoutes(String initialRoute) {<br>    final uri = Uri.parse(initialRoute);<br>    if (uri.pathSegments.length == 2 &amp;&amp; uri.pathSegments.first == &#39;second&#39;) {<br>      final id = int.tryParse(uri.pathSegments.last);<br>      if (id != null) {<br>        return [<br>          MaterialPageRoute(builder: (context) =&gt; const HomePage()),<br>          MaterialPageRoute(builder: (context) =&gt; SecondPage(id: id)),<br>        ];<br>      }<br>    }<br>    return [MaterialPageRoute(builder: (context) =&gt; const HomePage())];<br>  }<br>  Route&lt;dynamic&gt; _onUnknownRoute(RouteSettings settings) {<br>    return MaterialPageRoute(<br>      builder: (context) =&gt; NotFoundPage(routeName: settings.name!),<br>    );<br>  }<br>}<br><br><br>class CustomNavigatorObserver extends NavigatorObserver {<br>  @override<br>  void didPush(Route route, Route? previousRoute) {<br>    super.didPush(route, previousRoute);<br>    print(&#39;Navigated to ${route.settings.name}&#39;);<br>  }<br><br>  @override<br>  void didPop(Route route, Route? previousRoute) {<br>    print(&#39;Navigated back to ${previousRoute?.settings.name}&#39;);<br>    super.didPop(route, previousRoute);<br>  }<br><br>  @override<br>  void didRemove(Route route, Route? previousRoute) {<br>    print(&#39;Navigated remove to ${previousRoute?.settings.name}&#39;);<br>    super.didRemove(route, previousRoute);<br>  }<br><br>  @override<br>  void didReplace({Route? newRoute, Route? oldRoute}) {<br>    print(&#39;Navigation route replaced to ${newRoute?.settings.name}&#39;);<br>    super.didReplace(newRoute: newRoute, oldRoute: oldRoute);<br>  }<br>}</pre><h3>Usage of RouteInformationProvider and routeInformationProvider</h3><p>An abstract class called <strong><em>RouteInformationProvider</em></strong> may be modified to give the Router widget route information. When utilising the Router API for navigation, it is utilised in the <strong><em>routeInformationProvider</em></strong> field of the <strong><em>MaterialApp.router</em></strong> constructor. For deep linking, unique URL handling, or integration with other navigation systems, you may manage the source of route information by using a custom <strong><em>RouteInformationProvider</em></strong>.</p><p>In the aforementioned example, I developed a <strong><em>CustomRouteInformationProvider</em></strong> class that extends <strong><em>RouteInformationProvider</em></strong> and modifies the getter for valueListenable to deliver the most recent route data. I also included a way to update the route data. I then created a <strong><em>CustomRouteInformationProvider</em></strong> object and sent it to the <strong><em>MaterialApp.router constructor as the routeInformationProvider.</em></strong></p><p>To handle the routing logic, I also developed a <strong><em>CustomRouterDelegate</em></strong> and a <strong><em>CustomRouteInformationParser</em></strong>. The onButtonPressed callback of the <strong><em>HomePage</em></strong> and <strong><em>SecondPage</em></strong> widgets modifies the <strong><em>CustomRouterDelegate’s</em></strong> current route.</p><pre>import &#39;package:flutter/foundation.dart&#39;;<br>import &#39;package:flutter/material.dart&#39;;<br><br>void main() {<br>  runApp(MyApp());<br>}<br><br>class MyApp extends StatelessWidget {<br>  final CustomRouteInformationProvider _customRouteInformationProvider =<br>      CustomRouteInformationProvider();<br><br>  MyApp({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp.router(<br>      title: &#39;Route Information Provider Demo&#39;,<br>      routerDelegate: CustomRouterDelegate(),<br>      routeInformationParser: CustomRouteInformationParser(),<br>      routeInformationProvider:<br>          _customRouteInformationProvider, // Use the custom RouteInformationProvider<br>    );<br>  }<br>}<br><br>class CustomRouteInformationProvider extends RouteInformationProvider {<br>  late RouteInformation _routeInformation;<br><br>  CustomRouteInformationProvider() {<br>    // Set initial route information<br>    _routeInformation = RouteInformation(uri: Uri(path: &#39;/&#39;));<br>  }<br><br><br>  // Method to update the route information<br>  void updateRouteInformation(RouteInformation routeInformation) {<br>    _routeInformation = routeInformation;<br>  }<br>  <br>  @override<br>  void addListener(VoidCallback listener) {<br>  }<br>  <br>  @override<br>  void removeListener(VoidCallback listener) {<br><br>  }<br>  <br>  @override<br>  RouteInformation get value =&gt; _routeInformation;<br>}<br><br>class CustomRouterDelegate extends RouterDelegate&lt;String&gt;<br>    with ChangeNotifier, PopNavigatorRouterDelegateMixin&lt;String&gt; {<br>  String _currentRoute = &#39;/&#39;;<br><br>  @override<br>  GlobalKey&lt;NavigatorState&gt; get navigatorKey =&gt; GlobalKey&lt;NavigatorState&gt;();<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Navigator(<br>      key: navigatorKey,<br>      pages: [<br>        if (_currentRoute == &#39;/&#39;)<br>          MaterialPage(<br>            key: const ValueKey(&#39;HomePage&#39;),<br>            child: HomePage(onButtonPressed: _handleButtonPressed),<br>          ),<br>        if (_currentRoute == &#39;/second&#39;)<br>          MaterialPage(<br>            key: const ValueKey(&#39;SecondPage&#39;),<br>            child: SecondPage(onButtonPressed: _handleButtonPressed),<br>          ),<br>      ],<br>      onPopPage: (route, result) {<br>        if (!route.didPop(result)) return false;<br>        _currentRoute = &#39;/&#39;;<br>        notifyListeners();<br>        return true;<br>      },<br>    );<br>  }<br><br>  @override<br>  Future&lt;void&gt; setNewRoutePath(String configuration) {<br>    _currentRoute = configuration;<br>    return SynchronousFuture&lt;void&gt;(null);<br>  }<br><br>  void _handleButtonPressed(String route) {<br>    _currentRoute = route;<br>    notifyListeners();<br>  }<br>}<br><br>class CustomRouteInformationParser extends RouteInformationParser&lt;String&gt; {<br>  @override<br>  Future&lt;String&gt; parseRouteInformation(RouteInformation routeInformation) {<br>    return SynchronousFuture&lt;String&gt;(routeInformation.uri.toString());<br>  }<br><br>  @override<br>  RouteInformation restoreRouteInformation(String path) {<br>    return RouteInformation(uri: Uri(path: path));<br>  }<br>}<br><br>class HomePage extends StatelessWidget {<br>  final void Function(String) onButtonPressed;<br><br>  const HomePage({super.key, required this.onButtonPressed});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(title: const Text(&#39;Home Page&#39;)),<br>      body: Center(<br>        child: ElevatedButton(<br>          onPressed: () =&gt; onButtonPressed(&quot;/second&quot;),<br>          child: const Text(&#39;Go to Second Page&#39;),<br>        ),<br>      ),<br>    );<br>  }<br>}<br><br>class SecondPage extends StatelessWidget {<br>  final void Function(String) onButtonPressed;<br><br>  const SecondPage({super.key, required this.onButtonPressed});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(title: const Text(&#39;Second Page&#39;)),<br>      body: Center(<br>        child: ElevatedButton(<br>          onPressed: () =&gt; onButtonPressed(&quot;/&quot;),<br>          child: const Text(&#39;Go back to Home Page&#39;),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>The Flutter Material App widget, which is essential for creating Material Design apps, was investigated in this blog article. We studied the fundamental characteristics of our applications and learned how to properly use them in order to modify the way they appear and behave. Using the Material App widget, you can create apps that adhere to the Material Design tenets and are aesthetically pleasing and uniform.</p><h4><a href="https://medium.com/@flutter.rashpinder/the-material-app-widget-a-developers-guided-series-part-3-db18aed53585">Part-3</a></h4><p>You can check whole code at Github repository <a href="https://github.com/rashpinderleanix/flutter-widget-series">Flutter-Widget-Series.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21f1ef780890" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter’s The Material App Widget: A Developer’s Guided Series — Part 1]]></title>
            <link>https://medium.com/@flutter.rashpinder/flutters-the-material-app-widget-a-developer-s-guided-series-part-1-cded465e6e8e?source=rss-7e8fb1fbf562------2</link>
            <guid isPermaLink="false">https://medium.com/p/cded465e6e8e</guid>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter-3]]></category>
            <category><![CDATA[construction-material-app]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[future-technology]]></category>
            <dc:creator><![CDATA[Rashpinder Singh]]></dc:creator>
            <pubDate>Tue, 05 Sep 2023 05:23:16 GMT</pubDate>
            <atom:updated>2023-09-05T19:14:49.883Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Material App Widget: A Developer’s Guided Series — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*zIecNsnz3fEMS42tynIJCw.png" /></figure><blockquote>Welcome to this thorough tutorial to Flutter’s Material App widget. The Material App widget unifies the interaction and visual design aspects that adhere to the Material Design standards, making it a crucial part of building a Flutter application. The Material App widget, its characteristics, and practical Flutter application usage will all be covered in this article.</blockquote><h3>Summary of Contents</h3><ol><li><em>What the Material App Widget</em></li><li><em>Basic Usage of the Material App Widget</em></li><li>Usage of GlobalKey&lt;NavigatorState&gt;</li><li>Usage of GlobalKey&lt;ScaffoldMessengerState&gt;</li><li>Usage of RouteFactory and onGenerateRoute</li></ol><h4>A Material App Widget Introduction</h4><p>A top-level widget called the Material App makes it easier to create Material Design applications in Flutter. Developers may simply alter the look and behaviour of their apps because to the large number of features and functions it offers. You may design a sleek and unified user experience across several platforms by utilising Material App.</p><h4>The Fundamentals of Material App Widget</h4><p>The ‘<strong>material.dart’</strong> package must be imported in your ‘ <strong>main.dart’</strong> file in order to use the Material App widget:</p><pre>import &#39;package:flutter/material.dart&#39;;<br><br><br>void main() {<br>  runApp(MyApp());<br>}<br><br>class MyApp extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      home: Scaffold(<br>        appBar: AppBar(title: Text(&#39;My Material App&#39;)),<br>        body: Center(child: Text(&#39;Hello, World!&#39;)),<br>      ),<br>    );<br>  }<br>}</pre><h3>Key Properties of Material App Widget</h3><p>Here are some of the most important properties of the Material App widget:</p><ul><li>title: A one-line description of the app, used in the task manager and window switcher.</li><li>theme: The ThemeData object that defines the app&#39;s visual appearance.</li><li>darkTheme: The ThemeData object that defines the app&#39;s visual appearance when running on a platform with a dark theme.</li><li>themeMode: Determines which theme to use based on the user&#39;s preferences (light, dark, or system default).</li><li>color: The primary color of the app, used for branding and other visual elements.</li><li>home: The default route of the app, typically a Scaffold widget containing the main app content.</li><li>routes: A map of named routes used for navigating between different screens in the app.</li><li>onGenerateRoute: A function that generates custom routes based on the requested route name.</li><li>navigatorKey: A key used to access the NavigatorState of the app&#39;s root navigator.</li><li>initialRoute: The name of the first route to be displayed when the app starts.</li><li>debugShowCheckedModeBanner: A boolean flag that controls whether to display the &quot;debug&quot; banner in the top-right corner of the app.</li></ul><pre>class MaterialAppWidget extends StatelessWidget {<br>  const MaterialAppWidget({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;My Themed App&#39;,<br>      theme: ThemeData(<br>        primarySwatch: Colors.blue,<br>      ),<br>      darkTheme: ThemeData.dark(),<br>      themeMode: ThemeMode.system,<br>      initialRoute: &#39;/&#39;,<br>      routes: {<br>        &#39;/&#39;: (context) =&gt; Scaffold(<br>              appBar: AppBar(<br>                title: const Text(&#39;My First Page&#39;),<br>              ),<br>              body: const Center(<br>                child: Text(&#39;Hello, World!&#39;),<br>              ),<br>            ),<br>        &#39;/second&#39;: (context) =&gt; Scaffold(<br>              appBar: AppBar(<br>                title: const Text(&#39;My Second Page&#39;),<br>              ),<br>              body: const Center(<br>                child: Text(&#39;Hello, World!&#39;),<br>              ),<br>            ),<br>      },<br>    );<br>  }<br>}</pre><h3>Usage of GlobalKey&lt;NavigatorState&gt; and navigatorKey</h3><p>A unique kind of key called a <strong><em>GlobalKeyNavigatorState</em>&gt;</strong> may be used to retrieve a widget’s state anywhere in the widget tree. It is employed as the <strong><em>navigatorKey</em></strong> property of the Material App widget to gain access to the <strong><em>NavigatorState</em></strong> of the app’s root navigator. Because of this, you may push and pop routes from within your app, among other navigational operations, without having to send the <strong><em>BuildContext</em></strong> farther down the widget tree.</p><p>Here is an illustration showing how to use <strong><em>GlobalKeyNavigatorState</em>&gt;</strong> as <strong><em>navigatorKey</em></strong> in a Flutter application:</p><p>In the example below, we created a GlobalKey&lt;NavigatorState&gt; instance and assigned it to the navigatorKey property of the MaterialApp widget. This allows us to use the navigatorKey.currentState to perform navigation actions, like pushing and popping routes, from any part of the application. In this case, we used it to navigate between HomePage and SecondPage without having to pass the BuildContext down the widget tree.</p><pre>import &#39;package:flutter/material.dart&#39;;<br><br>void main() {<br>  runApp(const MyApp());<br>}<br>///GlobalKey&lt;NavigatorState&gt; is a special type of key that can be used to access the state of a widget across the widget tree. <br>/// In the context of the Material App widget, it is used as the navigatorKey property to access the NavigatorState of the app&#39;s root navigator. <br>///  This allows you to perform navigation actions, such as pushing and popping routes, from anywhere in your app, without having to pass the BuildContext down the widget tree.<br>///Here&#39;s an example that demonstrates the usage of GlobalKey&lt;NavigatorState&gt; as navigatorKey in a Flutter app:<br>///<br>// Create a GlobalKey&lt;NavigatorState&gt; instance<br>final GlobalKey&lt;NavigatorState&gt; navigatorKey = GlobalKey&lt;NavigatorState&gt;();<br><br>class MyApp extends StatelessWidget {<br>  const MyApp({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;Navigator Key Demo&#39;,<br>      navigatorKey: navigatorKey, // Assign the navigatorKey to MaterialApp<br>      home: const HomePage(),<br>      routes: {<br>        &#39;/second&#39;: (context) =&gt; const SecondPage(),<br>      },<br>    );<br>  }<br>}<br><br>class HomePage extends StatelessWidget {<br>  const HomePage({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(title: const Text(&#39;Home Page&#39;)),<br>      body: Center(<br>        child: ElevatedButton(<br>          onPressed: () {<br>            // Navigate to SecondPage using the navigatorKey<br>            navigatorKey.currentState?.pushNamed(&#39;/second&#39;);<br>          },<br>          child: const Text(&#39;Go to Second Page&#39;),<br>        ),<br>      ),<br>    );<br>  }<br>}<br><br>class SecondPage extends StatelessWidget {<br>  const SecondPage({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(title: const Text(&#39;Second Page&#39;)),<br>      body: Center(<br>        child: ElevatedButton(<br>          onPressed: () {<br>            // Navigate back to HomePage using the navigatorKey<br>            navigatorKey.currentState?.pop();<br>          },<br>          child: const Text(&#39;Go back to Home Page&#39;),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><h3>Usage of GlobalKey&lt;ScaffoldMessengerState&gt; and scaffoldMessengerKey</h3><p>The state of a ScaffoldMessenger widget may be accessed across the widget tree using a specific kind of key called <strong><em>GlobalKeyScaffoldMessengerState&gt;</em></strong>. Without having to send the <strong><em>BuildContext</em></strong> down the widget tree, you can control <strong><em>SnackBars</em></strong> from anywhere in your app by using a <strong><em>scaffoldMessengerKey</em></strong>.</p><p>Here is an illustration of how to use <strong><em>GlobalKeyScaffoldMessengerState&gt;</em></strong> as <strong><em>scaffoldMessengerKey</em></strong> in a Flutter application.</p><p>In the example above, we created a GlobalKey&lt;ScaffoldMessengerState&gt; instance and assigned it to the scaffoldMessengerKey property of the MaterialAppwidget. This allows us to use the scaffoldMessengerKey.currentState to show SnackBars from any part of the application. In this case, we used it to show a SnackBar from both the HomePage and SecondPage without having to pass the BuildContext down the widget tree.</p><pre>import &#39;package:flutter/material.dart&#39;;<br><br>void main() {<br>  runApp(const MyApp());<br>}<br><br>// Create a GlobalKey&lt;ScaffoldMessengerState&gt; instance<br>final GlobalKey&lt;ScaffoldMessengerState&gt; scaffoldMessengerKey =<br>    GlobalKey&lt;ScaffoldMessengerState&gt;();<br><br>class MyApp extends StatelessWidget {<br>  const MyApp({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;Scaffold Messenger Key Demo&#39;,<br>      scaffoldMessengerKey:<br>          scaffoldMessengerKey, // Assign the scaffoldMessengerKey to MaterialApp<br>      home: const HomePage(),<br>    );<br>  }<br>}<br><br>class HomePage extends StatelessWidget {<br>  const HomePage({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(title: const Text(&#39;Home Page&#39;)),<br>      body: Center(<br>        child: Column(<br>          mainAxisAlignment: MainAxisAlignment.center,<br>          children: [<br>            ElevatedButton(<br>              onPressed: () {<br>                // Show a SnackBar using the scaffoldMessengerKey<br>                scaffoldMessengerKey.currentState?.showSnackBar(<br>                  const SnackBar(<br>                    content: Text(&#39;Hello from Home Page!&#39;),<br>                    duration: Duration(seconds: 2),<br>                  ),<br>                );<br>              },<br>              child: const Text(&#39;Show SnackBar&#39;),<br>            ),<br>            ElevatedButton(<br>              onPressed: () {<br>                Navigator.push(<br>                  context,<br>                  MaterialPageRoute(builder: (context) =&gt; const SecondPage()),<br>                );<br>              },<br>              child: const Text(&#39;Go to Second Page&#39;),<br>            ),<br>          ],<br>        ),<br>      ),<br>    );<br>  }<br>}<br><br>class SecondPage extends StatelessWidget {<br>  const SecondPage({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(title: const Text(&#39;Second Page&#39;)),<br>      body: Center(<br>        child: ElevatedButton(<br>          onPressed: () {<br>            // Show a SnackBar using the scaffoldMessengerKey<br>            scaffoldMessengerKey.currentState?.showSnackBar(<br>              const SnackBar(<br>                content: Text(&#39;Hello from Second Page!&#39;),<br>                duration: Duration(seconds: 2),<br>              ),<br>            );<br>          },<br>          child: const Text(&#39;Show SnackBar&#39;),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><h3>Usage of RouteFactory and onGenerateRoute</h3><p>A <strong><em>RouteSettings</em></strong> object is the input for the function type <strong><em>RouteFactory</em></strong>, which outputs a <strong><em>Route&lt;dynamic&gt;</em></strong>. It is utilised in the <strong><em>MaterialApp</em></strong> widget’s <strong><em>onGenerateRoute</em></strong> feature to create custom routes depending on the provided route name. You can do things like handle routes dynamically, make your own <strong><em>transitions</em></strong>, or give the route arguments thanks to this.</p><p>In the example below, we created a _onGenerateRoute function that takes a RouteSettings object as an argument and returns a Route&lt;dynamic&gt;. We then assigned this function to the onGenerateRoute property of the MaterialAppwidget. This allows us to handle routes dynamically based on the requested route name.</p><p>Here is an illustration of how to use <strong><em>RouteFactory</em></strong> as <strong><em>onGenerateRoute</em></strong> in a Flutter application:</p><pre>import &#39;package:flutter/material.dart&#39;;<br><br>void main() {<br>  runApp(const MyApp());<br>}<br><br>class MyApp extends StatelessWidget {<br>  const MyApp({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;On Generate Route Demo&#39;,<br>      home: const HomePage(),<br>      onGenerateRoute:<br>          _onGenerateRoute, // Assign the _onGenerateRoute function to MaterialApp<br>    );<br>  }<br><br>  Route&lt;dynamic&gt; _onGenerateRoute(RouteSettings settings) {<br>    switch (settings.name) {<br>      case &#39;/second&#39;:<br>        final String message = settings.arguments as String;<br>        return MaterialPageRoute(<br>          builder: (context) =&gt; SecondPage(message: message),<br>        );<br>      default:<br>        return MaterialPageRoute(builder: (context) =&gt; const HomePage());<br>    }<br>  }<br>}<br><br>class HomePage extends StatelessWidget {<br>  const HomePage({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(title: const Text(&#39;Home Page&#39;)),<br>      body: Center(<br>        child: ElevatedButton(<br>          onPressed: () {<br>            // Navigate to SecondPage using the onGenerateRoute<br>            Navigator.pushNamed(<br>              context,<br>              &#39;/second&#39;,<br>              arguments: &#39;Hello from Home Page!&#39;,<br>            );<br>          },<br>          child: const Text(&#39;Go to Second Page&#39;),<br>        ),<br>      ),<br>    );<br>  }<br>}<br><br>class SecondPage extends StatelessWidget {<br>  final String message;<br><br>  const SecondPage({<br>    super.key,<br>    required this.message,<br>  });<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(title: const Text(&#39;Second Page&#39;)),<br>      body: Center(<br>        child: Text(message),<br>      ),<br>    );<br>  }<br>}</pre><p>In this case, we used _onGenerateRoute to navigate to the SecondPage and pass a message as an argument. When the user clicks on the &quot;Go to Second Page&quot; button in the HomePage, the Navigator.pushNamed() method is called with the route name /second and an argument containing the message. The _onGenerateRoutefunction then creates a MaterialPageRoute for the SecondPage and passes the message argument to it.</p><p>This blog post examined Flutter’s Material App widget, which is crucial for producing Material Design apps. In order to customise the look and behaviour of our apps, we learnt about its essential attributes and how to apply them successfully. You may develop apps that follow the Material Design principles and are aesthetically attractive and consistent by utilising the Material App widget.</p><p>You can check whole code at Github repository <a href="https://github.com/rashpinderleanix/flutter-widget-series">Flutter-Widget-Series</a>.<br><a href="https://medium.com/@flutter.rashpinder/flutters-the-material-app-widget-a-developer-s-guided-series-part-2-21f1ef780890"><strong><em>Part — 2</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cded465e6e8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>