Fa-chapter-2 - Lightweight Recipe App Built With Flutter

Overview

Recipe App

Our app will offer a hard-coded list of recipes and let us use a Slider to recalculate quanties based on the number of servings.

Creating a new app

There are two simple ways to start a new Flutter app:

  1. Create a new project through the IDE.
  2. Create a new project through flutter create command.

Making the app ours

Change the class MyApp extends StatelessWidget to class RecipeApp extends StatelessWidget.

This defines a new Dart class named RecipeApp which extends -- or inherits from StatelessWidget. In Flutter, almost everything that makes up the user interface is a widget. A StatelessWidget doesn't change after you build it. Think of RecipeApp as the container of the app.


class RecipeApp extends StatelessWidget {

main() is the entry point for the code when the app launches. runApp() tells Flutter which is the top-level widget for the app.

Styling our app

Widget build(BuildContext context) {
    const appTitle = "Recipe Calculator";
    final ThemeData theme = ThemeData();

    return MaterialApp(
        title: appTitle,
        theme: theme.copyWith(
            colorScheme: theme.colorScheme.copyWith(
                primary: Colors.grey,
                secondary: Colors.black,
            ),
        );
        home: const MyHomePage(title: appTitle),
    );
}

This code changes the appearance of the app:

  1. A widget's build() method is the entry point for composing together other widgets to make a new widget.
  2. A theme determines visual aspects like color.
  3. MaterialApp uses Material Design and is the widget that will be included in RecipeApp
  4. The title of the app is a description that the device uses to identify the app. The UI won’t display this.
  5. By copying the theme and replacing the color scheme with an updated copy lets us change the app’s colors. Here, the primary color is Colors.grey and the secondary color is Colors.black.

Building a recipe list

An empty recipe app isn’t very useful. The app should have a nice list of recipes for the user to scroll through. Before we can display these, however, we need the data to fill out the UI.

Adding a data model

  String label;
  String imageUrl;
  int servings;
  List<Ingredient> ingredients;

  Recipe(
    this.label,
    this.imageUrl,
    this.servings,
    this.ingredients,
  );

  static List<Recipe> samples = [
    Recipe(
      'Spaghetti and Meatballs',
      'assets/2126711929_ef763de2b3_w.jpg',
      4,
      [
        Ingredient(
          1,
          'box',
          'Spaghetti',
        ),
        Ingredient(
          4,
          '',
          'Frozen Meatballs',
        ),
        Ingredient(
          0.5,
          'jar',
          'sauce',
        ),
      ],
    ),
    Recipe(
      'Tomato Soup',
      'assets/27729023535_a57606c1be.jpg',
      2,
      [
        Ingredient(
          1,
          'can',
          'Tomato Soup',
        ),
      ],
    ),
    Recipe(
      'Grilled Cheese',
      'assets/3187380632_5056654a19_b.jpg',
      1,
      [
        Ingredient(
          2,
          'slices',
          'Cheese',
        ),
        Ingredient(
          2,
          'slices',
          'Bread',
        ),
      ],
    ),
    Recipe(
      'Chocolate Chip Cookies',
      'assets/15992102771_b92f4cc00a_b.jpg',
      24,
      [
        Ingredient(
          4,
          'cups',
          'flour',
        ),
        Ingredient(
          2,
          'cups',
          'sugar',
        ),
        Ingredient(
          0.5,
          'cups',
          'chocolate chips',
        ),
      ],
    ),
    Recipe(
      'Taco Salad',
      'assets/8533381643_a31a99e8a6_c.jpg',
      1,
      [
        Ingredient(
          4,
          'oz',
          'nachos',
        ),
        Ingredient(
          3,
          'oz',
          'taco meat',
        ),
        Ingredient(
          0.5,
          'cup',
          'cheese',
        ),
        Ingredient(
          0.25,
          'cup',
          'chopped tomatoes',
        ),
      ],
    ),
    Recipe(
      'Hawaiian Pizza',
      'assets/15452035777_294cefced5_c.jpg',
      4,
      [
        Ingredient(
          1,
          'item',
          'pizza',
        ),
        Ingredient(
          1,
          'cup',
          'pineapple',
        ),
        Ingredient(
          8,
          'oz',
          'ham',
        ),
      ],
    ),
  ];
}

class Ingredient {
  double quantity;
  String measure;
  String name;

  Ingredient(
    this.quantity,
    this.measure,
    this.name,
  );
}

This is just an overview of all the step we went through creating our app.

You might also like...

Bmprogresshud - A lightweight progress HUD for Flutter app

Bmprogresshud - A lightweight progress HUD for Flutter app

bmprogresshud A lightweight progress HUD for your Flutter app, Inspired by SVProgressHUD. Showcase Example local HUD place ProgressHud to you containe

Nov 19, 2021

A clean and lightweight progress HUD for your iOS and tvOS app.

SVProgressHUD SVProgressHUD is a clean and easy-to-use HUD meant to display the progress of an ongoing task on iOS and tvOS. Demo Try SVProgressHUD on

Jan 3, 2023

A lightweight and customizable http client that allows you to create offline-first dart app easily.

Enjoyable & customizable offline-first REST API client Unruffled is lightweight and customizable http client that allows you to create offline-first e

May 20, 2022

A lightweight flutter package to linkify texts containing urls, emails and hashtags

A lightweight flutter package to linkify texts containing urls, emails and hashtags

linkfy_text A lightweight flutter package to linkify texts containing urls, emails and hashtags. Usage To use this package, add linkfy_text as a depen

Nov 23, 2022

A lightweight HTML-Richtext editor for Flutter

A lightweight HTML-Richtext editor for Flutter

Flutter HTML Editor Flutter HTML Editor is a simple HTML-based Richtext editor, which is able to edit and parse a selected set of HTML tags into a Flu

Oct 19, 2022

Easy to use, reliable and lightweight gesture detector for Flutter apps, exposing simple API for basic gestures

Simple Gesture Detector Easy to use, reliable and lightweight gesture detector for Flutter apps. Exposes simple API to react to basic gestures. Featur

Nov 4, 2022

Zerker is a lightweight and powerful flutter graphic animation library

Zerker is a lightweight and powerful flutter graphic animation library

What is Zerker Zerker is a flexible and lightweight flutter canvas graphic animation library. With Zerker, you can create a lot of seemingly cumbersom

Dec 31, 2022

Lightweight i18n solution for Flutter

fast_i18n Lightweight i18n solution. Use JSON, YAML or CSV files to create typesafe translations. About this library 🚀 Minimal setup, create JSON fil

Dec 26, 2022

The typesafe, reactive, and lightweight SQLite abstraction for your Flutter applications

The typesafe, reactive, and lightweight SQLite abstraction for your Flutter applications

See the project's website for the full documentation. Floor provides a neat SQLite abstraction for your Flutter applications inspired by the Room pers

Dec 28, 2022
Owner
Siphumelelo Talent Qwabe
Software Engineer based in Durban, South Africa
Siphumelelo Talent Qwabe
Hungry is a Free Flutter Recipe App Starter Template that can help you develop a Recipe application much faster.

Hungry is a Free Flutter Recipe App Starter Template that can help you develop a Recipe application much faster. You just need to add some adjustment to the frontend and you can create your own backend.

Muhammad Rezky Sulihin 48 Dec 20, 2022
A Food Recipe App Built Using Flutter

ChefBook ??️ Description: Do you enjoy cooking? If not, are there any culinary f

李瑞孟 1 Dec 23, 2021
Receitas app - Recipe app jointly developed by Cod3r on Flutter & Dart course

Let's cook? Aplicativo de receitas desenvolvido em conjunto a Cod3r dentro do cu

Erilândio Santos Medeiros 1 Dec 22, 2022
A Recipe App created by following the first section of the book, Flutter Apprentice 2nd Edition.

recipes A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this

Kian Yang Lee 1 Dec 17, 2021
This is a Flutter Food Recipe App this shows food recipes of any food which you want.

food_recipe_app A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

Saksham gupta 3 Oct 31, 2022
social recipe app

fooderlich A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if th

Keneth Kogi 2 Nov 3, 2021
A recipe app, in which you will learn about different Scrollable widgets.

Scrollable-Widgets : A recipe app, in which you will learn about different Scrollable widgets. Concepts Included : ListView & Nested ListView GridView

Ashirbad Swain 6 Apr 26, 2022
A lightweight flutter plugin to check if your app is up-to-date on Google Play Store or Apple App Store

App Version Checker this package is used to check if your app has a new version on playstore or apple app store. or you can even check what is the lat

Iheb Briki 6 Dec 14, 2022
Bhagavad Gita app using flutter & Bhagavad-Gita-API is A lightweight Node.js based Bhagavad Gita API [An open source rest api on indian Vedic Scripture Shrimad Bhagavad Gita].

Gita Bhagavad Gita flutter app. Download App - Playstore Web Application About Bhagavad Gita app using flutter & Bhagavad-Gita-API is A lightweight No

Ravi Kovind 7 Apr 5, 2022
A lightweight & effective Todo app made with Flutter

Blue Diary A lightweight & effective Todo app made with Flutter. Supports English and Korean. Screenshots • Download • Usage • Architecture • Feedback

Hansol Lee 152 Dec 6, 2022