Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

flutter pizza hut

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

  • �� 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?

  • �� download this repo
  • �� run below code in terminal of project
flutter pub get
flutter run

screenshots

home-2

author: lambiengcode


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.