fix: ultra-fake orders
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import 'package:gymlink_module_web/components/app_bar.dart';
|
||||
@@ -69,6 +71,57 @@ class _OrderConfirmationPageState extends State<OrderConfirmationPage> {
|
||||
final _addressController = TextEditingController();
|
||||
final _nameController = TextEditingController();
|
||||
|
||||
Future<void> _addOrderToHistory() async {
|
||||
String name = _nameController.text;
|
||||
String email = _emailController.text;
|
||||
String address = _addressController.text;
|
||||
|
||||
Set<String> supplierIdsSet = {};
|
||||
for (final item in cartItems) {
|
||||
supplierIdsSet.add(item.supplierId);
|
||||
}
|
||||
List<GymHistoryItemDetailProvider> providers = [];
|
||||
for (final supplierId in supplierIdsSet) {
|
||||
List<GymItem> items =
|
||||
cartItems.where((e) => e.supplierId == supplierId).toList();
|
||||
List<GymHistoryItemDetailItem> detailItems = [];
|
||||
for (final item in items) {
|
||||
detailItems.add(GymHistoryItemDetailItem(
|
||||
id: item.id,
|
||||
photo: item.images[0].url,
|
||||
count: item.localCount,
|
||||
price: item.price.toString(),
|
||||
name: item.title,
|
||||
));
|
||||
}
|
||||
GymHistoryItemDetailProvider provider = GymHistoryItemDetailProvider(
|
||||
id: supplierId,
|
||||
name: items.first.supplierName,
|
||||
items: detailItems,
|
||||
// status: 'Не оплачен'
|
||||
status: Random().nextBool()
|
||||
? 'Не оплачен'
|
||||
: Random().nextBool()
|
||||
? 'Не оплачен'
|
||||
: Random().nextBool()
|
||||
? 'Сборка'
|
||||
: 'Доставляется',
|
||||
);
|
||||
providers.add(provider);
|
||||
}
|
||||
|
||||
final order = GymHistoryItemDetail(
|
||||
id: Random().nextInt(1000000).toString(),
|
||||
receiver: name,
|
||||
email: email,
|
||||
address: address,
|
||||
sum: totalPrice.toString(),
|
||||
date: '',
|
||||
providers: providers,
|
||||
);
|
||||
await addToHistory(order);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -248,12 +301,7 @@ class _OrderConfirmationPageState extends State<OrderConfirmationPage> {
|
||||
if (!_checkInputs()) return;
|
||||
_goToPage();
|
||||
await clearCart();
|
||||
await addToHistory(GymHistoryItem(
|
||||
id: '123',
|
||||
date: '01.01.1970',
|
||||
sum: '123',
|
||||
photo: 'product.png',
|
||||
));
|
||||
await _addOrderToHistory();
|
||||
Provider.of<CartProvider>(context, listen: false)
|
||||
.updateCartLength();
|
||||
Navigator.of(context).pushAndRemoveUntil(
|
||||
|
||||
Reference in New Issue
Block a user