<?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 Ahmed Alwaeli on Medium]]></title>
        <description><![CDATA[Stories by Ahmed Alwaeli on Medium]]></description>
        <link>https://medium.com/@amd4iq?source=rss-fb015ac3b073------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*COA5tarBM14eeajoqcFZIg.jpeg</url>
            <title>Stories by Ahmed Alwaeli on Medium</title>
            <link>https://medium.com/@amd4iq?source=rss-fb015ac3b073------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 09:48:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amd4iq/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 — Fetch data from API using HTTP package, with (MVC) architecture]]></title>
            <link>https://medium.com/@amd4iq/flutter-fetch-data-from-api-using-http-package-with-mvc-architecture-0817f6d12b36?source=rss-fb015ac3b073------2</link>
            <guid isPermaLink="false">https://medium.com/p/0817f6d12b36</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[mvc]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[https]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Ahmed Alwaeli]]></dc:creator>
            <pubDate>Fri, 24 Nov 2023 21:17:05 GMT</pubDate>
            <atom:updated>2023-11-24T21:17:05.747Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter — Fetch data from API using HTTP package, with (MVC) architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FLdX9ZdWfkeYAxWALBxwzw.jpeg" /></figure><p><strong>1. Begin by crafting the conceptual framework of the model:<br></strong>we will use <a href="https://newsapi.org/docs/endpoints/top-headlines">https://newsapi.org/</a> to fetch the ‘top-headlines’ news:<br><strong><em>note that we will fetch the news by ‘category’</em></strong></p><pre>class Articles {<br>  final Source source;<br>  final String author;<br>  final String title;<br>  final String description;<br>  final String url;<br>  final String urlToImage;<br>  final String publishedAt;<br>  final String content;<br><br>  Articles(<br>      {required this.source,<br>      required this.author,<br>      required this.title,<br>      required this.description,<br>      required this.url,<br>      required this.urlToImage,<br>      required this.publishedAt,<br>      required this.content});<br><br>  factory Articles.fromJson(Map&lt;String, dynamic&gt; json) =&gt; Articles(<br>        source: Source.fromJson(json[&#39;source&#39;] as Map&lt;String, dynamic&gt;),<br>        author: json[&#39;author&#39;] as String? ?? &#39;&#39;, // Handle null<br>        title: json[&#39;title&#39;] as String? ?? &#39;&#39;, // Handle null<br>        description: json[&#39;description&#39;] as String? ?? &#39;&#39;, // Handle null<br>        url: json[&#39;url&#39;] as String? ?? &#39;&#39;, // Handle null<br>        urlToImage: json[&#39;urlToImage&#39;] as String? ?? &#39;&#39;, // Handle null<br>        publishedAt: json[&#39;publishedAt&#39;] as String? ?? &#39;&#39;, // Handle null<br>        content: json[&#39;content&#39;] as String? ?? &#39;&#39;, // Handle null<br>      );<br>}</pre><p><strong>2. Initiate the process by retrieving the required data from the Application Programming Interface (API):</strong></p><pre>class NewsClient {<br>  Future&lt;String&gt; getNewsByCategory(String category) async {<br>    final response = await http.get(Uri.parse(BASE_URL + category));<br><br>    switch (response.statusCode) {<br>      case 200:<br>        print(&#39;HTTP Status: ${response.statusCode}&#39;);<br>        return response.body;<br>      default:<br>        print(&#39;HTTP Status: ${response.statusCode}&#39;);<br>    }<br><br>    return &#39;&#39;;<br>  }<br>}</pre><p><strong>3. In order to handle the data that we receive, we need to establish a dedicated Repository.<br></strong>This Repository will have the specific function of decoding the incoming data. This is a crucial step in ensuring that the data is in a format that we can work with, leading to more efficient data analysis and processing.</p><pre>final NewsClient client = NewsClient();<br><br>class NewsRepository {<br>  Future&lt;List&lt;Articles&gt;&gt; getNewsByCategory(String category) async {<br>    final response = await client.getNewsByCategory(category);<br>    if (response.isNotEmpty) {<br>      var jsonData = jsonDecode(response);<br>      List&lt;dynamic&gt; articlesJson = jsonData[&#39;articles&#39;];<br>      List&lt;Articles&gt; articles =<br>          articlesJson.map((e) =&gt; Articles.fromJson(e)).toList();<br>      return articles;<br>    } else {<br>      print(&#39;Data is empty&#39;);<br>    }<br>    return [];<br>  }<br>}</pre><p>4. To begin with, you need to<strong> create the Controller</strong>. <strong>This is an essential part of the system as it acts as an intermediate between the user and the system.<br></strong>Once the Controller has been created, the next step is to get the data from the repository. The repository is a storage area where data is kept. It serves as a source of information, which can be fetched and manipulated as required. By retrieving the data from the repository, we can then use it for further processing and operations. This is a crucial step because the data stored in the repository serves as the backbone for any operations that need to be performed.</p><pre>final NewsRepository repository = NewsRepository();<br><br>class NewsController {<br>  List&lt;Articles&gt; articles = &lt;Articles&gt;[];<br><br>  getNewsByCategory() async {<br>    List&lt;Articles&gt; data = await repository.getNewsByCategory(&#39;general&#39;);<br>    for (var item in data) {<br>      articles.add(item);<br>    }<br>  }<br><br>  clearNews() {<br>    articles.clear();<br>  }<br><br>  // sort news by Alphabetical order<br>  sortNewsByAlphabeticalOrder() {<br>    articles.sort((a, b) =&gt; a.title.compareTo(b.title));<br>  }<br><br>  // sort news by reverse Alphabetical order<br>  sortNewsByReverseAlphabeticalOrder() {<br>    articles.sort((a, b) =&gt; b.title.compareTo(a.title));<br>  }<br>}</pre><p><strong>That’s all there is to it!</strong> You have now reached a point where you can invoke the controller in your view page. This will allow you to display the data. The controller is a critical component in the Model-View-Controller (MVC) architecture. It acts as an interface between the Model, which handles the data, and the View, which presents this data to the user. By calling the controller in your view page, you’re able to effectively manage the data flow within your application. This is a significant step in developing efficient, scalable software.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0817f6d12b36" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring a Flutter Single “Sign-In/Sign-Up” Page with Offstage and Stak Widgets]]></title>
            <link>https://medium.com/@amd4iq/exploring-a-flutter-single-sign-in-sign-up-page-with-offstage-and-stakwidgets-b66e771ab9ef?source=rss-fb015ac3b073------2</link>
            <guid isPermaLink="false">https://medium.com/p/b66e771ab9ef</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Ahmed Alwaeli]]></dc:creator>
            <pubDate>Sat, 14 Oct 2023 22:07:46 GMT</pubDate>
            <atom:updated>2023-10-14T22:57:07.868Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we’ll delve into a Flutter application that features a sign-in and sign-up single page. We’ll explore the code of the main page, the sign-in/sign-up page, and the custom widgets used to create this user interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*7uhtOeLcE0Wm4YE8nrCSnA.gif" /></figure><p>here is a representation of the directory structure of our project:</p><pre>project/<br>├── ...<br>│<br>├── lib/ (Flutter source code)<br>│   ├── main.dart<br>│   ├── start_page.dart<br>│   ├── button.dart<br>│   ├── text_field.dart<br>│   └── ...<br>│</pre><h3>The Main Page (main.dart)</h3><p>The journey begins with the main page, “main.dart,” which serves as the entry point of your application. It establishes the foundation for the sign-in/sign-up page and sets the app&#39;s initial state.</p><p>Here’s the code for the main page:</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:playground/start_page.dart&#39;;<br><br>void main() {<br>  runApp(const MyApp());<br>}<br><br>class MyApp extends StatefulWidget {<br>  const MyApp({super.key});<br><br>  @override<br>  State&lt;MyApp&gt; createState() =&gt; _MyAppState();<br>}<br><br>class _MyAppState extends State&lt;MyApp&gt; {<br>  @override<br>  Widget build(BuildContext context) {<br>    return const MaterialApp(<br>      debugShowCheckedModeBanner: false,<br>      home: StartPage(),<br>    );<br>  }<br>}</pre><p>Key Points:</p><ul><li>The main function initializes the Flutter application with the MyApp widget.</li><li>MyApp is the root widget, and it manages the app&#39;s state.</li><li>The main page sets the initial state and displays the “StartPage” as its home.</li></ul><h3>Deciphering the Role of the Offstage Widget</h3><p>One of the remarkable features of the sign-in/sign-up page is the utilization of the Offstage widget. This widget allows sections of the page to be hidden when not in use, resulting in a cleaner and more intuitive user experience.</p><p>In particular, the code snippets within the StartPage widget incorporate the Offstage widget to toggle the visibility of sign-in and sign-up sections. When a user switches between these modes, the corresponding section is displayed, while the other remains offstage.</p><p>This clever use of the Offstage widget provides a seamless and space-efficient way to transition between sign-in and sign-up, making the UI more user-friendly.</p><h3>The Sign-In/Sign-Up Page (start_page.dart)</h3><p>The sign-in and sign-up page, “start_page.dart,” is where users interact with the app. This page is crucial for user authentication, and it’s designed to be flexible with a toggle between sign-in and sign-up.</p><p>Here’s the code for “StartPage” :</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:playground/button.dart&#39;;<br>import &#39;package:playground/text_field.dart&#39;;<br><br>class StartPage extends StatefulWidget {<br>  const StartPage({super.key});<br><br>  @override<br>  State&lt;StartPage&gt; createState() =&gt; _StartPageState();<br>}<br><br>class _StartPageState extends State&lt;StartPage&gt; {<br>  bool isSignin = false;<br>  bool isSignUp = true;<br>  bool obscureText = true;<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      backgroundColor: Colors.grey[900],<br>      body: Container(<br>        margin: const EdgeInsets.symmetric(horizontal: 20),<br>        child: Column(<br>          children: [<br>            Stack(<br>              children: [<br>                // Sgin IN<br>                SizedBox(<br>                  height: MediaQuery.of(context).size.height / 2,<br>                  child: Offstage(<br>                    offstage: isSignin,<br>                    child: Column(<br>                      children: [<br>                        const SizedBox(height: 70),<br>                        const Text(<br>                          &#39;Sign in&#39;,<br>                          style: TextStyle(<br>                            color: Colors.white,<br>                            fontSize: 25,<br>                          ),<br>                        ),<br>                        const SizedBox(height: 50),<br>                        const MyTextField(<br>                          hintText: &#39;Username&#39;,<br>                          obscureText: false,<br>                        ),<br>                        const SizedBox(height: 15),<br>                        Row(<br>                          children: [<br>                            Expanded(<br>                              child: MyTextField(<br>                                hintText: &#39;Password&#39;,<br>                                obscureText: obscureText,<br>                              ),<br>                            ),<br>                            Container(<br>                              margin: const EdgeInsets.only(left: 10),<br>                              width: 50,<br>                              height: 50,<br>                              decoration: BoxDecoration(<br>                                color: Colors.white38,<br>                                borderRadius: BorderRadius.circular(10),<br>                              ),<br>                              child: GestureDetector(<br>                                onTap: () {<br>                                  setState(() {<br>                                    obscureText = !obscureText;<br>                                  });<br>                                },<br>                                child: Icon(<br>                                  obscureText<br>                                      ? Icons.remove_red_eye_outlined<br>                                      : Icons.remove_red_eye,<br>                                  color: obscureText<br>                                      ? Colors.white<br>                                      : const Color.fromARGB(<br>                                          255, 235, 146, 146),<br>                                ),<br>                              ),<br>                            ),<br>                          ],<br>                        ),<br>                      ],<br>                    ),<br>                  ),<br>                ),<br><br>                // Sgin UP<br>                Offstage(<br>                  offstage: isSignUp,<br>                  child: Column(<br>                    children: [<br>                      const SizedBox(height: 70),<br>                      const Text(<br>                        &#39;Sign Up&#39;,<br>                        style: TextStyle(<br>                          color: Colors.white,<br>                          fontSize: 25,<br>                        ),<br>                      ),<br>                      const SizedBox(height: 50),<br>                      const MyTextField(<br>                        hintText: &#39;Username&#39;,<br>                        obscureText: false,<br>                      ),<br>                      const SizedBox(height: 15),<br>                      const MyTextField(<br>                        hintText: &#39;Email&#39;,<br>                        obscureText: false,<br>                      ),<br>                      const SizedBox(height: 15),<br>                      const MyTextField(<br>                        hintText: &#39;Confirm Email&#39;,<br>                        obscureText: false,<br>                      ),<br>                      const SizedBox(height: 15),<br>                      Row(<br>                        children: [<br>                          Expanded(<br>                            child: MyTextField(<br>                              hintText: &#39;Password&#39;,<br>                              obscureText: obscureText,<br>                            ),<br>                          ),<br>                          Container(<br>                            margin: const EdgeInsets.only(left: 10),<br>                            width: 50,<br>                            height: 50,<br>                            decoration: BoxDecoration(<br>                              color: Colors.white38,<br>                              borderRadius: BorderRadius.circular(10),<br>                            ),<br>                            child: GestureDetector(<br>                              onTap: () {<br>                                setState(() {<br>                                  obscureText = !obscureText;<br>                                });<br>                              },<br>                              child: Icon(<br>                                obscureText<br>                                    ? Icons.remove_red_eye_outlined<br>                                    : Icons.remove_red_eye,<br>                                color: obscureText<br>                                    ? Colors.white<br>                                    : const Color.fromARGB(255, 235, 146, 146),<br>                              ),<br>                            ),<br>                          ),<br>                        ],<br>                      ),<br>                    ],<br>                  ),<br>                ),<br>              ],<br>            ),<br>            Expanded(<br>              flex: 2,<br>              child: Column(<br>                mainAxisAlignment: MainAxisAlignment.spaceEvenly,<br>                children: [<br>                  Stack(<br>                    children: [<br>                      Offstage(<br>                        offstage: isSignin,<br>                        child: Row(<br>                          children: [<br>                            MyButton(<br>                              text: &#39;Sign in&#39;,<br>                              onPressed: () {<br>                                setState(() {<br>                                  isSignin = false;<br>                                  isSignUp = true;<br>                                });<br>                              },<br>                              padding: 102,<br>                              backgroundColor: Colors.blueAccent,<br>                            ),<br>                            MyButton(<br>                              text: &#39;Sign Up&#39;,<br>                              onPressed: () {<br>                                setState(() {<br>                                  isSignin = true;<br>                                  isSignUp = false;<br>                                });<br>                              },<br>                              padding: 30,<br>                              backgroundColor: Colors.grey,<br>                            ),<br>                          ],<br>                        ),<br>                      ),<br>                      Column(<br>                        children: [<br>                          Offstage(<br>                            offstage: isSignUp,<br>                            child: Row(<br>                              children: [<br>                                MyButton(<br>                                  text: &#39;Sign in&#39;,<br>                                  onPressed: () {<br>                                    setState(() {<br>                                      isSignin = false;<br>                                      isSignUp = true;<br>                                    });<br>                                  },<br>                                  padding: 30,<br>                                  backgroundColor: Colors.grey,<br>                                ),<br>                                MyButton(<br>                                  text: &#39;Continue Sign Up&#39;,<br>                                  onPressed: () {<br>                                    setState(() {<br>                                      isSignin = true;<br>                                      isSignUp = false;<br>                                    });<br>                                  },<br>                                  padding: 68,<br>                                  backgroundColor: Colors.blueAccent,<br>                                ),<br>                              ],<br>                            ),<br>                          ),<br><br>                        ],<br>                      ),<br>                    ],<br>                  ),<br>                  const Text(<br>                    &#39;Ahmed Alwaeli&#39;,<br>                    style: TextStyle(<br>                      color: Colors.white38,<br>                      fontSize: 12,<br>                    ),<br>                  ),<br>                ],<br>              ),<br>            ),<br>          ],<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>Key Points:</p><ul><li>“StartPage” is a StatefulWidget that represents the sign-in/sign-up screen.</li><li>It uses custom text fields and button widgets.</li><li>The page is divided into sections for sign-in and sign-up, with the ability to toggle between them.</li><li>User interaction and state changes are managed within this page.</li></ul><h3>Custom Widgets (button.dart and text_field.dart)</h3><p>To maintain clean and reusable code, custom widgets are utilized for the text fields and buttons on the sign-in/sign-up page. These widgets encapsulate the behavior and appearance of these components.</p><p>Here’s the code for “Custom button” :</p><pre>// ignore_for_file: public_member_api_docs, sort_constructors_first<br>import &#39;package:flutter/material.dart&#39;;<br><br>// ignore: must_be_immutable<br>class MyButton extends StatefulWidget {<br>  final String text;<br>  void Function() onPressed;<br>  final double padding;<br><br>  final Color backgroundColor;<br>  MyButton({<br>    Key? key,<br>    required this.padding,<br>    required this.text,<br>    required this.onPressed, required this.backgroundColor,<br>  }) : super(key: key);<br><br>  @override<br>  State&lt;MyButton&gt; createState() =&gt; _MyButtonState();<br>}<br><br>class _MyButtonState extends State&lt;MyButton&gt; {<br>  @override<br>  Widget build(BuildContext context) {<br>    return TextButton(<br>      style: TextButton.styleFrom(<br>        textStyle: const TextStyle(<br>          fontSize: 16,<br>        ),<br>        backgroundColor: widget.backgroundColor,<br>        padding: EdgeInsets.symmetric(horizontal: widget.padding, vertical: 15),<br>        shape: const RoundedRectangleBorder(<br>          borderRadius: BorderRadius.all(<br>            Radius.circular(0),<br>          )<br>        ),<br>      ),<br>      onPressed: widget.onPressed,<br>      child: Text(<br>        widget.text,<br>        style: const TextStyle(<br>          color: Colors.white,<br>          fontWeight: FontWeight.bold,<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>And here’s the code for “Custom TextField”:</p><pre>// ignore_for_file: public_member_api_docs, sort_constructors_first<br>import &#39;package:flutter/material.dart&#39;;<br><br>class MyTextField extends StatefulWidget {<br>  final String hintText;<br>  final bool obscureText;<br><br>  const MyTextField({<br>    Key? key,<br>    required this.hintText,<br>    required this.obscureText,<br>  }) : super(key: key);<br><br>  @override<br>  State&lt;MyTextField&gt; createState() =&gt; _MyTextFieldState();<br>}<br><br>class _MyTextFieldState extends State&lt;MyTextField&gt; {<br>  @override<br>  Widget build(BuildContext context) {<br>    return Container(<br>      padding: const EdgeInsets.symmetric(<br>        horizontal: 10,<br>      ),<br>      decoration: BoxDecoration(<br>        color: Colors.white38,<br>        borderRadius: BorderRadius.circular(8),<br>      ),<br>      child: TextField(<br>        obscureText: widget.obscureText,<br>        keyboardType:<br>            widget.hintText == &#39;Email&#39; || widget.hintText == &#39;Confirm Email&#39;<br>                ? TextInputType.emailAddress<br>                : TextInputType.text,<br>        decoration: InputDecoration(<br>          enabledBorder: InputBorder.none,<br>          focusedBorder: InputBorder.none,<br>          border: OutlineInputBorder(<br>            borderRadius: BorderRadius.circular(8),<br>          ),<br>          hintText: widget.hintText,<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>Key Points:</p><ul><li>Custom widgets like “MyButton” and “MyTextField” encapsulate specific functionality.</li><li>They enhance code modularity and maintainability.</li><li>The custom button widget, for instance, can be easily reused in various parts of the app.</li></ul><h3>Conclusion</h3><p>In this article, we’ve delved into the code of a Flutter sign-in/sign-up page and unearthed the intriguing role of the Offstage widget in enhancing user experience. This Flutter application showcases how this toolkit enables the creation of responsive and visually appealing user interfaces, emphasizing the importance of clean code structure and modular custom widgets.</p><p>As you delve deeper into the world of Flutter app development, you’ll uncover the toolkit’s full potential. By mastering its intricacies and best practices, you’ll be equipped to create complex, engaging applications that cater to a diverse range of user interactions.</p><p>Github: <a href="https://github.com/amd4iq/Flutter-Single-Sign-In-Sign-Up-Page">https://github.com/amd4iq/Flutter-Single-Sign-In-Sign-Up-Page</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b66e771ab9ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Todo app step-by-step]]></title>
            <link>https://medium.com/@amd4iq/flutter-todo-app-step-by-step-1011e17f1895?source=rss-fb015ac3b073------2</link>
            <guid isPermaLink="false">https://medium.com/p/1011e17f1895</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Ahmed Alwaeli]]></dc:creator>
            <pubDate>Wed, 27 Sep 2023 15:55:39 GMT</pubDate>
            <atom:updated>2023-09-27T15:55:39.421Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*36DLgHVHYzOAqyHTioWRDw.jpeg" /></figure><p>Creating a Flutter Todo app step by step involves several tasks, including setting up the project, creating screens, implementing data models, managing state, and handling navigation. I’ll provide you with a simplified example of building a basic Todo app. Note that this is a simple example, and real-world applications may require additional features and optimizations.</p><p>Here’s a step-by-step guide:</p><p><strong>Designing the file structure for a Flutter Todo app:<br></strong>Designing the file structure for a Flutter Todo app involves organizing your project into folders and files to maintain a clean and organized codebase. Here’s a common file structure for a Flutter Todo app:</p><pre>my_todo_app/<br>  ├── lib/<br>  │   ├── main.dart<br>  │   ├── screens/<br>  │   │   ├── home_screen.dart<br>  │   │   ├── add_task_screen.dart<br>  │   │   └── task_detail_screen.dart<br>  │   ├── widgets/<br>  │   │   ├── task_list.dart<br>  │   │   ├── task_tile.dart<br>  │   │   └── ... (other reusable widgets)<br>  │   ├── models/<br>  │   │   ├── task.dart<br>  │   │   └── ... (other data models)<br>  │   ├── providers/<br>  │   │   ├── task_provider.dart<br>  │   │   └── ... (other providers if needed)<br>  │   ├── database/<br>  │   │   ├── database.dart<br>  │   │   └── ... (other database-related files)<br>  │   ├── utils/<br>  │   │   ├── date_utils.dart<br>  │   │   └── ... (other utility functions)<br>  │   ├── routes/<br>  │   │   ├── app_routes.dart<br>  │   │   └── ... (other route-related files)<br>  │   └── constants/<br>  │       ├── app_constants.dart<br>  │       └── ... (other constants)<br>  ├── assets/<br>  │   ├── images/<br>  │   │   ├── todo_logo.png<br>  │   │   └── ... (other images)<br>  │   └── ... (other assets)<br>  ├── test/<br>  │   ├── unit/<br>  │   │   └── ... (unit test files)<br>  │   ├── widgets/<br>  │   │   └── ... (widget test files)<br>  └── pubspec.yaml</pre><p>Explanation of the key folders and files:</p><ul><li><strong>lib/main.dart:</strong> The entry point of the Flutter app.</li><li><strong>lib/screens/:</strong> Contains Dart files for different screens of your app, like the home screen, add task screen and task detail screen.</li><li><strong>lib/widgets/:</strong> Contains reusable widgets used across multiple screens.</li><li><strong>lib/models/:</strong> Defines data models, such as the Task class.</li><li><strong>lib/providers/:</strong> Manages state and business logic using providers, including TaskProvider.</li><li><strong>lib/database/:</strong> Contains code for managing the app’s database (if used).</li><li><strong>lib/utils/: </strong>Houses utility functions and helper methods.</li><li><strong>lib/routes/:</strong> Defines the app’s routes and navigation logic.</li><li><strong>lib/constants/:</strong> Stores constant values used throughout the app.</li><li><strong>assets/:</strong> Holds static assets like images.</li><li><strong>test/:</strong> Contains unit and widget tests for your app.</li></ul><p>You can further organize and split your code into more folders and subfolders as your app grows. This structure provides a good starting point for a Flutter Todo app, and you can expand and customize it according to your project’s needs.</p><p><strong>Creating a Flutter Todo app</strong> step by step involves several tasks, including setting up the project, creating screens, implementing data models, managing state, and handling navigation. I’ll provide you with a simplified example of building a basic Todo app. Note that this is a simple example, and real-world applications may require additional features and optimizations.</p><h4>Step 1: Set Up a Flutter Project</h4><ol><li>Create a new Flutter project using the Flutter CLI:</li></ol><pre>flutter create my_todo_app</pre><p>2. Open the project in your preferred code editor.</p><h4>Step 2: Define Data Models</h4><p>In your lib/models/ folder, create a file named task.dart to define the Task data model:</p><pre>class Task {<br>  final String id;<br>  final String title;<br>  final bool isDone;<br><br>  Task({<br>    required this.id,<br>    required this.title,<br>    required this.isDone,<br>  });<br>}</pre><h4>Step 3: Create Screens</h4><p>Create the following screens in the lib/screens/ folder:</p><p>Home Screen (home_screen.dart)</p><p>This screen displays the list of tasks.</p><pre>import &#39;package:flutter/material.dart&#39;;<br><br>class HomeScreen extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(<br>        title: Text(&#39;Todo List&#39;),<br>      ),<br>      body: // Implement the task list here<br>    );<br>  }<br>}</pre><p>Add Task Screen (add_task_screen.dart)</p><p>This screen allows users to add new tasks.</p><pre>import &#39;package:flutter/material.dart&#39;;<br><br>class AddTaskScreen extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(<br>        title: Text(&#39;Add Task&#39;),<br>      ),<br>      body: // Implement the form to add a task here<br>    );<br>  }<br>}</pre><p>Task Detail Screen (task_detail_screen.dart)</p><p>This screen shows the details of a specific task.</p><pre>import &#39;package:flutter/material.dart&#39;;<br><br>class TaskDetailScreen extends StatelessWidget {<br>  final String taskId;<br><br>  TaskDetailScreen({required this.taskId});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    // Fetch the task details based on taskId and display them<br>  }<br>}</pre><h4>Step 4: Create Widgets</h4><p>In the lib/widgets/ folder, create a task_tile.dart widget to represent a task item in the list:</p><pre>import &#39;package:flutter/material.dart&#39;;<br><br>class TaskTile extends StatelessWidget {<br>  final String title;<br>  final bool isDone;<br>  final Function(bool) onChanged;<br><br>  TaskTile({<br>    required this.title,<br>    required this.isDone,<br>    required this.onChanged,<br>  });<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return ListTile(<br>      title: Text(title),<br>      leading: Checkbox(<br>        value: isDone,<br>        onChanged: onChanged,<br>      ),<br>    );<br>  }<br>}</pre><h4>Step 5: Implement State Management</h4><p>In the lib/providers/ folder, create a task_provider.dart file to manage the state of tasks using the ChangeNotifier pattern:</p><pre>import &#39;package:flutter/foundation.dart&#39;;<br>import &#39;../models/task.dart&#39;;<br><br>class TaskProvider with ChangeNotifier {<br>  List&lt;Task&gt; _tasks = [];<br><br>  List&lt;Task&gt; get tasks {<br>    return [..._tasks];<br>  }<br><br>  void addTask(Task task) {<br>    _tasks.add(task);<br>    notifyListeners();<br>  }<br><br>  // Implement methods to update and delete tasks<br><br>  // You can also add methods for fetching and managing tasks<br>}</pre><h4>Step 6: Implement the Home Screen</h4><p>In the lib/screens/home_screen.dart file, create the HomeScreen widget and use the TaskProvider to display the list of tasks:</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:provider/provider.dart&#39;;<br>import &#39;../providers/task_provider.dart&#39;;<br>import &#39;../widgets/task_tile.dart&#39;;<br><br>class HomeScreen extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    final tasks = Provider.of&lt;TaskProvider&gt;(context).tasks;<br><br>    return Scaffold(<br>      appBar: AppBar(<br>        title: Text(&#39;Todo List&#39;),<br>      ),<br>      body: ListView.builder(<br>        itemCount: tasks.length,<br>        itemBuilder: (ctx, index) {<br>          final task = tasks[index];<br>          return TaskTile(<br>            title: task.title,<br>            isDone: task.isDone,<br>            onChanged: (value) {<br>              // Implement task completion logic<br>            },<br>          );<br>        },<br>      ),<br>      floatingActionButton: FloatingActionButton(<br>        onPressed: () {<br>          Navigator.of(context).pushNamed(&#39;/add-task&#39;);<br>        },<br>        child: Icon(Icons.add),<br>      ),<br>    );<br>  }<br>}</pre><h4>Step 7: Implement Navigation and Add Task Screen</h4><p>In the lib/main.dart file, define your app&#39;s routes, and create the TaskProvider:</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:provider/provider.dart&#39;;<br>import &#39;screens/home_screen.dart&#39;;<br>import &#39;screens/add_task_screen.dart&#39;;<br>import &#39;providers/task_provider.dart&#39;;<br><br>void main() {<br>  runApp(MyTodoApp());<br>}<br><br>class MyTodoApp extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return ChangeNotifierProvider(<br>      create: (context) =&gt; TaskProvider(),<br>      child: MaterialApp(<br>        title: &#39;Todo App&#39;,<br>        theme: ThemeData(<br>          primarySwatch: Colors.blue,<br>        ),<br>        initialRoute: &#39;/&#39;,<br>        routes: {<br>          &#39;/&#39;: (ctx) =&gt; HomeScreen(),<br>          &#39;/add-task&#39;: (ctx) =&gt; AddTaskScreen(),<br>          // Add more routes if needed<br>        },<br>      ),<br>    );<br>  }<br>}</pre><h4>Step 8: Add Task Functionality</h4><p>In the lib/screens/add_task_screen.dart file, implement the logic for adding a new task:</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:provider/provider.dart&#39;;<br>import &#39;../providers/task_provider.dart&#39;;<br><br>class AddTaskScreen extends StatelessWidget {<br>  final TextEditingController _taskController = TextEditingController();<br><br>  void _addTask(BuildContext context) {<br>    final taskText = _taskController.text;<br>    if (taskText.isNotEmpty) {<br>      Provider.of&lt;TaskProvider&gt;(context, listen: false).addTask(<br>        Task(<br>          id: DateTime.now().toString(),<br>          title: taskText,<br>          isDone: false,<br>        ),<br>      );<br>      Navigator.of(context).pop();<br>    }<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(<br>        title: Text(&#39;Add Task&#39;),<br>      ),<br>      body: Padding(<br>        padding: EdgeInsets.all(16.0),<br>        child: Column(<br>          children: &lt;Widget&gt;[<br>            TextField(<br>              controller: _taskController,<br>              decoration: InputDecoration(labelText: &#39;Task&#39;),<br>            ),<br>            SizedBox(height: 20),<br>            ElevatedButton(<br>              onPressed: () =&gt; _addTask(context),<br>              child: Text(&#39;Add Task&#39;),<br>            ),<br>          ],<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><h4>Step 9: Running the App</h4><p>You can now run your Flutter Todo app using the flutter run command. Make sure to connect a device or use an emulator.</p><p>This is a simplified example to get you started with a basic Todo app. You can enhance it by adding features like task editing, task deletion, task completion, and data persistence to make it more functional. Additionally, you can apply custom styling to improve the app’s appearance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1011e17f1895" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>