Coder Social home page Coder Social logo

trendingtechnology / flutter_pizza_store Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lambiengcode/pizza_store_flutter

0.0 2.0 0.0 3.98 MB

:pizza: This is mobile application using flutter for develop a pizza store, integrated factory for demo design pattern

License: MIT License

Kotlin 0.28% Dart 92.82% Ruby 2.81% Swift 0.84% Objective-C 0.08% HTML 3.17%

flutter_pizza_store's Introduction

Flutter Pizza Hut ๐Ÿ•

Description:

  • ๐Ÿš€ This is mobile application using Flutter for develop a pizza store

  • ๐Ÿš€ Factory Method

  • Create Enum product_type.dart & location_type.dart

enum ProductType {
  burger,
  pizza,
  chicken,
  chips,
}

enum LocationType {
  hanoi,
  danang,
  hochiminh,
}
  • Create Abstract Class - food.dart
import 'package:flutter_pizza_store/src/events/location_event.dart';
import 'package:flutter_pizza_store/src/models/product.dart';

abstract class Food {
  void initial() {}

  void filterByLocation(LocationType location) {}

  List<Product> products() {
    return [];
  }
}
  • Create Concrete Class - burger.dart, similar with pizza.dart, chicken.dart, chips.dart
import 'package:flutter_pizza_store/src/events/location_event.dart';
import 'package:flutter_pizza_store/src/events/product_event.dart';
import 'package:flutter_pizza_store/src/models/food.dart';
import 'package:flutter_pizza_store/src/models/product.dart';
import 'package:flutter_pizza_store/src/repository/product_repository.dart';

class Burger implements Food {
  List<Product> _products = [];

  @override
  void initial() {
    allProducts.forEach((product) {
      if (product.type == ProductType.burger) _products.add(product);
    });
  }

  @override
  void filterByLocation(LocationType location) {
    _products
        .where((e) {
          return e.location != location;
        })
        .toList()
        .forEach((_products.remove));
  }

  @override
  List<Product> products() {
    return _products;
  }
}
  • Create Factory Class - food_factory.dart
import 'package:flutter_pizza_store/src/events/product_event.dart';
import 'package:flutter_pizza_store/src/models/burger.dart';
import 'package:flutter_pizza_store/src/models/chicken.dart';
import 'package:flutter_pizza_store/src/models/chips.dart';
import 'package:flutter_pizza_store/src/models/food.dart';
import 'package:flutter_pizza_store/src/models/pizza.dart';

class FoodFactory {
  static Food getFood(ProductType type) {
    switch (type) {
      case ProductType.burger:
        return Burger();
      case ProductType.pizza:
        return Pizza();
      case ProductType.chicken:
        return Chicken();
      case ProductType.chips:
        return Chips();
      default:
        return Burger();
    }
  }
}

How I can run it?

  • ๐Ÿš€ Clone this repo
  • ๐Ÿš€ Run below code in terminal of project
flutter pub get
flutter run

Screenshots

Author: lambiengcode

flutter_pizza_store's People

Contributors

lambiengcode avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.