Learning Programming through a Flutter Project

Jul 21, 2024

Learning Programming through a Flutter Project

Introduction

  • Best way to learn programming: start building a simple project.
  • Focus: Learn Flutter basics by doing a project.
  • Objective: Improve programming skills and prepare for more advanced topics.

Getting Started with Flutter

  • No need to cover Flutter installation (many online tutorials available).
  • Command to create Flutter project:
    flutter create <project_name>
    
  • Work primarily within the lib folder.
  • main.dart file: Entry point of the Flutter application.
    • Main function: void main().
    • runApp function: Launches the application by passing a widget as the root.

Running the Application

  • Select emulator and press F5 to run the application.
  • Default Flutter application appears in the MyHomePage class.

Coding the Project

  1. Creating Pages

    • Create a Pages folder for different app pages.
    • Create a home.dart file in the Pages folder.
  2. Widgets Overview

    • Material Widgets: For Android, following Material Design guidelines.
    • Cupertino Widgets: For iOS, following Human Interface guidelines.
    • Stateless Widgets: No state changes.
    • Stateful Widgets: Mutable state, can be redrawn.
    • Use sdl shortcut in the editor for a Stateless widget.
  3. Home Screen Setup

    • Set home property to HomePage class in main.dart.
    • Use const keyword for compile-time constants.
  4. Build Method

    • Describes part of the user interface (returns a widget).
    • Use Scaffold: Provides framework for the app layout.
      • Contains widgets like AppBar, Drawer, etc.
  5. App Bar Implementation

    • Add AppBar to Scaffold.
    • Center text in AppBar using centerTitle: true.
    • Change text style (size, color, weight).
    • Customize background color and elevation.
    • Add buttons (using Container and GestureDetector).
    • Use flutter_svg package for SVG icons.
  6. Search TextField

    • Add TextField in Scaffold body.
    • Use Container for styling and margins.
    • Add shadow using BoxDecoration.
    • Customize TextField (remove border, add radius).
    • Add icons using prefixIcon and suffixIcon properties.
    • Include padding for correct sizing.
    • Display hint text (hintText property).
    • Remove debugShowCheckedModeBanner for clean UI.
  7. Category Section

    • Create Category model class.
    • Define properties: category name, icon path, background color.
    • Use ListView.builder for horizontal list display.
    • Implement item spacing with ListView.separated.
    • Set item color and radius.
    • Display category details (icon, text) using Column.
  8. Recommendation for Diet Section

    • Similar implementation to the category section.
    • Use ListView.builder and ListView.separated.
    • Display diets with icons and details.
    • Implement View button with gradient background.
  9. Popular Section

    • Define model for popular items.
    • Use ListView for scrollable list.
    • Customize container styles and icons.
    • Implement button with click events.

Enhancements

  • Modularize code: Extract methods for different sections.
  • Use const wherever applicable to avoid warnings.

Conclusion

  • Successfully created a basic Flutter application.
  • Continue exploring Flutter by building more projects.
  • Follow up with next tutorials for advanced features.