import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/utils.dart'; /// 图片消息的图片URL的HOST const String chatImageHost = "http://skk8mlm5b.hn-bkt.clouddn.com/"; /// socket的host和port端口 //47.93.216.24:9090 线上 192.168.10.200/192.168.10.129:9090 测试 const String socketHost = kDebugMode ? '192.168.10.200' : '47.93.216.24'; const int socketPort = 9090; /// 小程序接口的请求地址 const localMiniBaseUrl = "http://192.168.10.54:8765/app/"; ///本地 ///线上 /// app接口的请求地址 const serviceMiniBaseUrl = "https://pos.api.yixinhuixiang.com/app/"; ///线下 /// app接口的请求地址 const localBaseUrl = "http://192.168.10.54:8766/app/"; ///本地 ///线上 const serviceBaseUrl = "https://pos.platform.yixinhuixiang.com/app/"; /// 线上 /// 对list进行分组 Map> groupBy(Iterable values, S Function(T) key) { var map = >{}; for (var element in values) { (map[key(element)] ??= []).add(element); } return map; } /// 对list进行分组计数 Map groupCount(Map> values) { var map = {}; for (var element in values.keys) { map["$element"] = values[element]?.length ?? 0; } return map; } /// 对list进行分组并取最大值 Map groupItem(Map> values, {int Function(T)? key}) { var map = {}; for (var element in values.keys) { if (values[element] == null) { continue; } if (values[element]!.isEmpty) { continue; } map["$element"] = key == null ? values[element]!.first : values[element]!.lMax(key); } return map; } /// 最大值 T max(Iterable list, int Function(T) key) { T? tt; for (T t in list) { if (tt == null) { tt = t; } if (key(tt!) < key(t)) { tt = t; } } return tt!; } extension ListExtension on Iterable { Map> lGroupBy(S Function(T) key) { return groupBy(this, key); } T lMax(int Function(T) key) { return max(this, key); } } extension MapExtension on Map> { Map get mGroupCount => groupCount(this); Map mGroupItem({int Function(T)? key}) { return groupItem(this, key: key); } } extension StrExtension on String { void get toast => SmartDialog.showToast( this, alignment: Alignment.center, nonAnimationTypes: [ SmartNonAnimationType.continueLoading_nonAnimation, SmartNonAnimationType.continueKeepSingle, ], ); void get loading => SmartDialog.showLoading( msg: this, displayTime: 25000.milliseconds, nonAnimationTypes: [ SmartNonAnimationType.continueLoading_nonAnimation, SmartNonAnimationType.continueKeepSingle, ], ); void get print => debugPrint(this); }