This commit is contained in:
2026-07-12 04:33:48 +08:00
parent f8a90ad305
commit e7ce0f7bae
151 changed files with 2765 additions and 2947 deletions

View File

@@ -5,8 +5,6 @@ import 'dart:typed_data';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:url_launcher/url_launcher.dart';
import '../constants.dart';
@@ -36,27 +34,21 @@ class Util {
}
static Future<Box> getBox() async {
Hive.initFlutter();
Box box = await Hive.openBox('wisetronic_app_data');
return box;
}
static Widget showImage(String imageUrl, {double width, double height,
BoxFit fit, Widget Function(BuildContext, String, dynamic) errorWidget}) {
static Widget showImage(String imageUrl, {double? width, double? height,
BoxFit? fit, Widget Function(BuildContext, String?, dynamic)? errorWidget}) {
return Image.network(imageUrl,
fit: fit,
width: width,
height: height,
cacheWidth: width != null ? width.round() : null,
cacheHeight: height != null ? height.round() : null,
loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent loadingProgress) {
loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) return child;
return Center(
child: Utils.imageLoadingIndicator(),
);
},
errorBuilder: (BuildContext context, Object object, StackTrace stackTrace) {
errorBuilder: (BuildContext context, Object object, StackTrace? stackTrace) {
print('StackTrace: $stackTrace');
if (errorWidget != null) {
return errorWidget(context, null, null);
@@ -106,16 +98,16 @@ class Util {
}
void startFilePicker(BuildContext context, User user, {int commentId = -1, int orderId = 0}) async {
InputElement uploadInput = FileUploadInputElement();
InputElement uploadInput = FileUploadInputElement() as InputElement;
uploadInput.click();
uploadInput.onChange.listen((e) {
final files = uploadInput.files;
if (files.length >= 1) {
if (files!.length >= 1) {
final File file = files[0];
final FileReader reader = new FileReader();
reader.onLoadEnd.listen((e) {
uploadPicture(context, reader.result, file.name, user, commentId: commentId, orderId: orderId);
uploadPicture(context, reader.result as Uint8List, file.name, user, commentId: commentId, orderId: orderId);
});
reader.onError.listen((e) {
Fluttertoast.showToast(
@@ -210,11 +202,11 @@ class Util {
void startFilePicker2(BuildContext context, int imageId, OnGotFile onGotFile) async {
final _image = await WebImagePicker().pickImage();
onGotFile(imageId, _image.dataScheme);
onGotFile(imageId, _image!.dataScheme);
}
void createTicket(BuildContext context, String msg, List<Map<String, dynamic>> images,
OnSuccess onSuccess, OnError onError, {int id}) {
OnSuccess onSuccess, OnError onError, {int? id}) {
var formData = FormData();
formData.fields.add(MapEntry("msg", msg));
formData.fields.add(MapEntry('id', id == null ? '0' : id.toString()));
@@ -252,7 +244,7 @@ class Util {
PaymentPlatform paymentPlatform, {
bool googlePay=false,
bool applePay=false,
StripePaymentMethod stripePaymentMethod,
StripePaymentMethod? stripePaymentMethod,
}) {
switch(paymentPlatform.code) {
case Constants.PAYMENT_METHOD_CODE_SQUARE:
@@ -293,36 +285,36 @@ class Util {
}
class ImageInfo {
String name;
String data;
String dataScheme;
String path;
String name = '';
String data = '';
String dataScheme = '';
String path = '';
}
class WebImagePicker {
Future<ImageInfo> pickImage() async {
Future<ImageInfo?> pickImage() async {
print('pickImage');
final ImageInfo data = ImageInfo();
final FileUploadInputElement input = FileUploadInputElement();
document.body.children.add(input);
document.body!.children.add(input);
input..accept = 'image/*';
input.click();
await input.onChange.first;
if (input.files.isEmpty) return null;
if (input.files!.isEmpty) return null;
final reader = FileReader();
reader.readAsDataUrl(input.files[0]);
reader.readAsDataUrl(input.files![0]);
await reader.onLoad.first;
final encoded = reader.result as String;
// remove data:image/*;base64 preambule
final stripped =
encoded.replaceFirst(RegExp(r'data:image/[^;]+;base64,'), '');
//final imageBase64 = base64.decode(stripped);
final imageName = input.files?.first?.name;
final imagePath = input.files?.first?.relativePath;
data.name = imageName;
final imageName = input.files?.first.name;
final imagePath = input.files?.first.relativePath;
data.name = imageName!;
data.data = stripped;
data.dataScheme = encoded;
data.path = imagePath;
data.path = imagePath!;
return data;
}
}