You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.6 KiB
42 lines
1.6 KiB
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/constant.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"]); |
|
} |
|
}).catchEr(); |
|
} |
|
|
|
|
|
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; |
|
}
|
|
|