Initial commit: Penyerahan final Source code Tugas Akhir
This commit is contained in:
118
lib/providers/order_provider.dart
Normal file
118
lib/providers/order_provider.dart
Normal file
@ -0,0 +1,118 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:initial_folder/models/order_model.dart';
|
||||
|
||||
enum ResultState { loading, succes, failed }
|
||||
|
||||
class OrderProvider with ChangeNotifier {
|
||||
ResultState? _state;
|
||||
ResultState? get state => _state;
|
||||
|
||||
String? _totalPrice;
|
||||
String? _discountPrice;
|
||||
String? _idCourse;
|
||||
String? _thumbnail;
|
||||
String? _title;
|
||||
String? _instructor;
|
||||
|
||||
String? get totalPrice => _totalPrice;
|
||||
String? get discountPrice => _discountPrice;
|
||||
String? get idCourse => _idCourse;
|
||||
String? get thumbnail => _thumbnail;
|
||||
String? get title => _title;
|
||||
String? get instructor => _instructor;
|
||||
|
||||
set selectedThumbnail(String value) {
|
||||
_thumbnail = value;
|
||||
}
|
||||
|
||||
set selectedTitle(String value) {
|
||||
_title = value;
|
||||
}
|
||||
|
||||
set selectedInstructor(String value) {
|
||||
_instructor = value;
|
||||
}
|
||||
|
||||
void getTotalPrice(String total) {
|
||||
_totalPrice = total;
|
||||
}
|
||||
|
||||
void getdiscountPrice(String discountPrice) {
|
||||
_discountPrice = discountPrice;
|
||||
}
|
||||
|
||||
void getIdCourse(String idCourse) {
|
||||
_idCourse = idCourse;
|
||||
}
|
||||
|
||||
List<OrderModel> _orders = [];
|
||||
List<OrderModel> get orders => _orders;
|
||||
|
||||
List<Map<String, String>> _invoice = [];
|
||||
List<Map<String, String>> get invoice => _invoice;
|
||||
|
||||
void addOrder({
|
||||
String? id,
|
||||
String? title,
|
||||
String? price,
|
||||
String? imageUrl,
|
||||
String? discountPrice,
|
||||
String? instructor,
|
||||
}) {
|
||||
_orders.add(
|
||||
OrderModel(
|
||||
idCourse: id as String,
|
||||
title: title as String,
|
||||
price: price as String,
|
||||
instructor: instructor as String,
|
||||
imageUrl: imageUrl!,
|
||||
discountPrice: discountPrice as String,
|
||||
),
|
||||
);
|
||||
_invoice.add({
|
||||
"id_kursus": id,
|
||||
"title_kursus": title,
|
||||
"qty": "1",
|
||||
"harga": discountPrice == "0" ? price : discountPrice
|
||||
});
|
||||
}
|
||||
|
||||
void removeOrder(
|
||||
{String? id,
|
||||
String? title,
|
||||
String? price,
|
||||
String? imageUrl,
|
||||
String? discountPrice,
|
||||
String? instructor}) {
|
||||
_orders.remove(OrderModel(
|
||||
idCourse: id ?? '',
|
||||
title: title ?? '',
|
||||
price: price ?? '',
|
||||
instructor: instructor ?? '',
|
||||
imageUrl: imageUrl ?? '',
|
||||
discountPrice: discountPrice ?? '',
|
||||
));
|
||||
_invoice.remove({
|
||||
"id_kursus": id ?? '',
|
||||
"title_kursus": title ?? '',
|
||||
"qty": "1",
|
||||
"harga": (discountPrice == "0" || discountPrice == null)
|
||||
? price
|
||||
: discountPrice
|
||||
});
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_orders = [];
|
||||
_invoice = [];
|
||||
}
|
||||
|
||||
// void addInvoice({
|
||||
// required String id,
|
||||
// required String title,
|
||||
// required String price,
|
||||
// }) {
|
||||
// _invoice.add(
|
||||
// {"id_kursus": id, "title_kursus": title, "qty": "1", "harga": price});
|
||||
// }
|
||||
}
|
Reference in New Issue
Block a user