|
|
|
import 'dart:ui' as ui;
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:color_thief_dart/color_thief_dart.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
|
|
|
|
|
|
import 'package:huixiang/retrofit/retrofit_api.dart';
|
|
|
|
import 'package:huixiang/utils/flutter_utils.dart';
|
|
|
|
import 'package:huixiang/utils/shared_preference.dart';
|
|
|
|
|
|
|
|
miniLogin(ApiService apiService, String tenant, String storeId, Function(String token) callback) async {
|
|
|
|
apiService.minLogin(storeId).then((baseData) async {
|
|
|
|
if (baseData.isSuccess ?? false) {
|
|
|
|
Map<String, dynamic> minStoreInfo = baseData.data;
|
|
|
|
String minToken = minStoreInfo["token"];
|
|
|
|
SharedInstance.instance.saveMini(minToken, tenant, storeId);
|
|
|
|
callback.call(baseData.data["token"]);
|
|
|
|
}
|
|
|
|
}, onError: (error) {
|
|
|
|
SmartDialog.showToast(
|
|
|
|
AppUtils.dioErrorTypeToString(error.type),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
);
|
|
|
|
debugPrint("${error}");
|
|
|
|
return Future.value(null);
|
|
|
|
}).catchError((onError) {
|
|
|
|
SmartDialog.showToast(
|
|
|
|
AppUtils.dioErrorTypeToString(onError.type),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
);
|
|
|
|
debugPrint("${onError}");
|
|
|
|
return Future.value(null);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<Color?> loadShopColor(String imageUrl) async {
|
|
|
|
int? color = SharedInstance.instance.getShopColor(imageUrl);
|
|
|
|
if (color != null) {
|
|
|
|
return Color(color);
|
|
|
|
}
|
|
|
|
NetworkImage imageProvider = NetworkImage(imageUrl);
|
|
|
|
final completer = Completer<ui.Image>();
|
|
|
|
imageProvider.resolve(ImageConfiguration.empty).addListener(ImageStreamListener((ImageInfo imageInfo, bool synchronousCall) {
|
|
|
|
completer.complete(imageInfo.image);
|
|
|
|
}));
|
|
|
|
final ui.Image loadedImage = await completer.future;
|
|
|
|
List<int>? colorRgb = await getColorFromImage(loadedImage);
|
|
|
|
if (colorRgb?.isNotEmpty ?? false) {
|
|
|
|
Color color = Color.fromARGB(255, colorRgb![0], colorRgb[1], colorRgb[2]);
|
|
|
|
SharedInstance.instance.saveShopColor(imageUrl, color.value);
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|