Site icon Flutter Packages | Pub dev Packages – Flutter Mobile App World

Flutter Pizza Hut

Short Intro:

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

Flutter Pizza Hut 

Description:

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

enum LocationType {
  hanoi,
  danang,
  hochiminh,
}
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 [];
  }
}
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;
  }
}
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?

flutter pub get
flutter run

Screenshots

Download Flutter Pizza Hut app source code on GitHub

https://github.com/hongvinhmobile/flutter_pizza_store

Exit mobile version