initial commit to gitea

This commit is contained in:
2022-03-10 00:47:26 -05:00
parent 808ffa3211
commit f504e213a0
93 changed files with 4394 additions and 1539 deletions

View File

@@ -58,7 +58,7 @@ class HttpUtil {
localHeaders['Http-Signature'] = generateSignature(url);
}
localHeaders['Http-Business-Id'] = businessId.toString();
localHeaders['Http-Business-Id'] = businessId == 0 ? '${Constants.BUSINESS_ID}' : businessId.toString();
Box box = await Utils.getBox();
localHeaders['Http-Contact-Authorization'] = box.get(Constants.KEY_ACCESS_TOKEN, defaultValue: '');
localHeaders['Http-App-Key'] = platformName;
@@ -81,7 +81,7 @@ class HttpUtil {
onReceiveProgress: receiveProgress,
).timeout(const Duration(seconds: 30));
// print(response.data);
// print('response data: ${response.data}');
// Utils.jsonPrettyPrint(response.data);
int statusCode = response.statusCode;
@@ -115,7 +115,7 @@ class HttpUtil {
if (!url.startsWith('http')) {
localHeaders['Http-Signature'] = generateSignature(url);
}
localHeaders['Http-Business-Id'] = businessId.toString();
localHeaders['Http-Business-Id'] = businessId == 0 ? '${Constants.BUSINESS_ID}' : businessId.toString();
Box box = await Utils.getBox();
localHeaders['Http-Contact-Authorization'] = box.get(Constants.KEY_ACCESS_TOKEN, defaultValue: '');
localHeaders['Http-App-Key'] = platformName;
@@ -189,7 +189,7 @@ class HttpUtil {
localHeaders['Http-Signature'] = generateSignature(url);
}
localHeaders['Http-Business-Id'] = businessId.toString();
localHeaders['Http-Business-Id'] = businessId == 0 ? '${Constants.BUSINESS_ID}' : businessId.toString();
Box box = await Utils.getBox();
localHeaders['Http-Contact-Authorization'] = box.get(Constants.KEY_ACCESS_TOKEN, defaultValue: '');
localHeaders['Http-App-Key'] = platformName;
@@ -254,7 +254,7 @@ class HttpUtil {
localHeaders['Http-Signature'] = generateSignature(url);
}
localHeaders['Http-Business-Id'] = businessId.toString();
localHeaders['Http-Business-Id'] = businessId == 0 ? '${Constants.BUSINESS_ID}' : businessId.toString();
Box box = await Utils.getBox();
localHeaders['Http-Contact-Authorization'] = box.get(Constants.KEY_ACCESS_TOKEN, defaultValue: '');
localHeaders['Http-App-Key'] = platformName;
@@ -319,7 +319,7 @@ class HttpUtil {
localHeaders['Http-Signature'] = generateSignature(url);
}
localHeaders['Http-Business-Id'] = businessId.toString();
localHeaders['Http-Business-Id'] = businessId == 0 ? '${Constants.BUSINESS_ID}' : businessId.toString();
Box box = await Utils.getBox();
localHeaders['Http-Contact-Authorization'] = box.get(Constants.KEY_ACCESS_TOKEN, defaultValue: '');
localHeaders['Http-App-Key'] = platformName;

View File

@@ -1,39 +0,0 @@
import 'dart:html';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
class IFrameWeb extends StatefulWidget {
final String width;
final String height;
final String src;
const IFrameWeb({this.width, this.height, this.src});
@override
State<StatefulWidget> createState() {
return IFrameWebState();
}
}
class IFrameWebState extends State<IFrameWeb> {
final IFrameElement _iframeElement = IFrameElement();
@override
Widget build(BuildContext context) {
_iframeElement.height = widget.height;
_iframeElement.width = widget.width;
_iframeElement.src = widget.src;
_iframeElement.style.border = 'none';
ui.platformViewRegistry.registerViewFactory(
'iframeElement',
(int viewId) => _iframeElement,
);
return HtmlElementView(
key: UniqueKey(),
viewType: 'iframeElement',
);
}
}

View File

@@ -57,7 +57,7 @@ class Util {
);
},
errorBuilder: (BuildContext context, Object object, StackTrace stackTrace) {
print(stackTrace);
print('StackTrace: $stackTrace');
if (errorWidget != null) {
return errorWidget(context, null, null);
}

View File

@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:convert';
import 'package:dio/dio.dart';
@@ -36,6 +37,142 @@ typedef void OnOk();
typedef void OnLoadImageError();
class Utils {
static StreamSubscription onProductWillAddToCartSubscription;
static StreamSubscription onProductWillRemoveFromCartSubscription;
init() async {
onProductWillAddToCartSubscription =
eventBus.on<OnProductWillAddToCart>().listen((event) {
CartInfo cartInfo =
getCartInfoByBusiness(store.state.cartInfos, event.business);
if (cartInfo == null || cartInfo.productList.length == 0) {
cartInfo = CartInfo();
cartInfo.id = 0;
cartInfo.amountPaid = 0.0;
cartInfo.businessInfo = event.business;
cartInfo.extraFeeList = [];
cartInfo.discountList = [];
CartLineItem lineItem = newCartLineItem(
id: 0,
price: event.price,
product: event.product,
name: event.product.name,
description: event.description,
quantity: 1.0);
cartInfo.productList = [lineItem];
addSubproductToCard(cartInfo, lineItem);
store.dispatch(new UpdateCartInfo(addCartInfoToCartInfoList(
store.state.cartInfos, cartInfo)));
eventBus.fire(new OnCartInfoUpdated());
print('#1');
} else {
if (event.product.productAttributes.length > 0) {
CartLineItem lineItem = newCartLineItem(
id: 0,
price: event.price,
product: event.product,
name: event.product.name,
description: event.description,
quantity: 1.0);
cartInfo.productList.add(lineItem);
addSubproductToCard(cartInfo, lineItem);
store.dispatch(new UpdateCartInfo(addCartInfoToCartInfoList(
store.state.cartInfos, cartInfo)));
print('#2');
eventBus.fire(new OnCartInfoUpdated());
} else {
int found = -1;
for (var i = 0; i < cartInfo.productList.length; i++) {
if (event.product.id == cartInfo.productList[i].product.id) {
found = i;
break;
}
}
if (found == -1) {
CartLineItem lineItem = newCartLineItem(
id: 0,
price: event.price,
product: event.product,
name: event.product.name,
description: event.description,
quantity: 1.0);
cartInfo.productList.add(lineItem);
addSubproductToCard(cartInfo, lineItem);
store.dispatch(new UpdateCartInfo(addCartInfoToCartInfoList(
store.state.cartInfos, cartInfo)));
print('#3');
eventBus.fire(new OnCartInfoUpdated());
} else {
if (cartInfo.productList[found].quantity + 1.0 >
event.product.leftNum) {
// Fluttertoast.showToast(
// msg: S.of(context).product_insufficient,
// toastLength: Toast.LENGTH_SHORT,
// gravity: ToastGravity.CENTER,
// backgroundColor: Colors.red,
// textColor: Colors.white);
} else {
cartInfo.productList[found].quantity += 1;
addSubproductQty(cartInfo, cartInfo.productList[found]);
store.dispatch(new UpdateCartInfo(
addCartInfoToCartInfoList(
store.state.cartInfos, cartInfo)));
print('#4');
eventBus.fire(new OnCartInfoUpdated());
}
}
}
}
});
onProductWillRemoveFromCartSubscription =
eventBus.on<OnProductWillRemoveFromCart>().listen((event) {
CartInfo cartInfo =
getCartInfoByBusiness(store.state.cartInfos, event.business);
if (cartInfo != null) {
if (cartInfo.productList.length > 0) {
if (event.productListIndex != -1) {
if (cartInfo.productList[event.productListIndex].quantity <= 1) {
String uuid = cartInfo.productList[event.productListIndex].uuid;
cartInfo.productList.removeAt(event.productListIndex);
removeSubproduct(cartInfo, uuid);
} else {
cartInfo.productList[event.productListIndex].quantity -= 1;
addSubproductQty(cartInfo, cartInfo.productList[event.productListIndex], remove: true);
}
} else {
int productListIndex = -1;
for (var i = 0; i < cartInfo.productList.length; i++) {
if (cartInfo.productList[i].product.id == event.product.id) {
productListIndex = i;
break;
}
}
if (productListIndex != -1) {
if (cartInfo.productList[productListIndex].quantity <= 1) {
String uuid = cartInfo.productList[productListIndex].uuid;
cartInfo.productList.removeAt(productListIndex);
removeSubproduct(cartInfo, uuid);
} else {
cartInfo.productList[productListIndex].quantity -= 1;
addSubproductQty(cartInfo, cartInfo.productList[productListIndex], remove: true);
}
}
}
}
if (cartInfo.productList.length <= 0) {
store.dispatch(UpdateCartInfo(removeCartInfoFromCartInfoList(
store.state.cartInfos, cartInfo)));
} else {
store.dispatch(UpdateCartInfo(addCartInfoToCartInfoList(
store.state.cartInfos, cartInfo)));
}
eventBus.fire(new OnCartInfoUpdated());
}
});
}
static bool equalsIgnoreCase(String a, String b) =>
(a == null && b == null) ||
(a != null && b != null && a.toLowerCase() == b.toLowerCase());
@@ -373,6 +510,8 @@ class Utils {
message = error.response.data.toString();
}
}
} else if (error is String) {
message = '$error';
} else if (error.message != null) {
message = error.message;
} else {
@@ -642,7 +781,8 @@ class Utils {
}
static void loadProducts(int businessId, int categoryId, int page, bool more,
OnComplete onComplete, OnError onError) {
OnComplete onComplete, OnError onError, {int featuredCount=4, int hotSaleCount=4, String keyword=''}) {
print('feature $featuredCount');
HttpUtil.httpGet(
more ? 'v1/service-category-products-more' : 'v1/service-category-products',
businessId: businessId,
@@ -650,9 +790,12 @@ class Utils {
// 'lat': store.state.position.latitude.toString(),
// 'lng': store.state.position.longitude.toString(),
'category_id': categoryId,
'preview': 'no',
'preview': Constants.isPreview,
'page': page,
'num_per_page': Constants.ORDERS_PER_PAGE,
'featured_count': featuredCount,
'hot_sale_count': hotSaleCount,
'keyword': Uri.encodeComponent(keyword),
},
).then((value) {
if (onComplete != null) {
@@ -667,6 +810,9 @@ class Utils {
static String timestampToString(BuildContext context, int timestamp, {bool withTime=false}) {
DateTime date = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
if (timestamp == 0) {
return '';
}
return datetimeFormat(context, date, withTime: withTime);
}
@@ -966,6 +1112,10 @@ class Utils {
child: row,
);
}
static int getBusinessId() {
return Constants.BUSINESS_ID;
}
}
class RuntimeError extends Error {