230 lines
5.6 KiB
Dart
230 lines
5.6 KiB
Dart
import 'dart:io';
|
||
import 'dart:ui';
|
||
|
||
import 'package:circle_app/common/values/values.dart';
|
||
import 'package:circle_app/router/app_routers.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
import 'package:fluttertoast/fluttertoast.dart';
|
||
import 'package:get/get.dart';
|
||
|
||
import 'package:path_provider/path_provider.dart';
|
||
import 'package:get/get_state_manager/get_state_manager.dart';
|
||
import 'package:video_compress/video_compress.dart';
|
||
|
||
class Util {
|
||
|
||
}
|
||
//获取图片
|
||
String getBaseImage(String image) {
|
||
return '${Values.base_images}${image}.png';
|
||
}
|
||
|
||
String getHomeImage(String image) {
|
||
return '${Values.home_images}${image}.png';
|
||
}
|
||
|
||
String getLoginImage(String image) {
|
||
return '${Values.login_images}${image}.png';
|
||
}
|
||
|
||
String getMineImage(String image) {
|
||
return '${Values.mine_images}${image}.png';
|
||
}
|
||
|
||
String getMsgImage(String image) {
|
||
return '${Values.msg_images}${image}.png';
|
||
}
|
||
|
||
String getNavigatorImage(String image) {
|
||
return '${Values.navigator_images}${image}.png';
|
||
}
|
||
|
||
String getTabbarImage(String image) {
|
||
return '${Values.tabbar_images}${image}.png';
|
||
}
|
||
|
||
String getCircleImage(String image) {
|
||
return '${Values.circle_images}${image}.png';
|
||
}
|
||
|
||
|
||
|
||
///弹窗文本提示 msg: 提示内容
|
||
showToast(String msg) {
|
||
Fluttertoast.showToast(
|
||
msg: msg,
|
||
toastLength: Toast.LENGTH_SHORT,
|
||
gravity: ToastGravity.CENTER,
|
||
timeInSecForIosWeb: 1,
|
||
backgroundColor: Colors.black54,
|
||
textColor: Colors.white,
|
||
fontSize: 16.0
|
||
);
|
||
}
|
||
|
||
loaddingWidget(bool isMore) {
|
||
return Container(
|
||
alignment: Alignment.center,
|
||
child: isMore ? const CircularProgressIndicator(color: Color(0xFF07FAFB),) : Container(
|
||
margin:EdgeInsets.only(top: 4.sp,bottom: 4.sp),
|
||
child: Text('--到底了--',style: TextStyle(color: Colors.white,fontSize: 13.sp),
|
||
),),
|
||
);
|
||
}
|
||
|
||
///value: 文本内容;fontSize : 文字的大小;fontWeight:文字权重;maxWidth:文本框的最大宽度;maxLines:文本支持最大多少行
|
||
double calculateTextHeight(String value, fontSize, FontWeight fontWeight,
|
||
double maxWidth, int maxLines) {
|
||
value = filterText(value);
|
||
TextPainter painter = TextPainter(
|
||
|
||
///AUTO:华为手机如果不指定locale的时候,该方法算出来的文字高度是比系统计算偏小的。
|
||
locale: WidgetsBinding.instance!.window.locale,
|
||
maxLines: maxLines,
|
||
textDirection: TextDirection.ltr,
|
||
textScaleFactor: 1, //字体缩放大小
|
||
text: TextSpan(
|
||
text: value,
|
||
style: TextStyle(
|
||
fontWeight: fontWeight,
|
||
fontSize: fontSize,
|
||
)));
|
||
painter.layout(maxWidth: maxWidth);
|
||
|
||
///文字的宽度:painter.width
|
||
return painter.height;
|
||
}
|
||
|
||
String filterText(String text) {
|
||
String tag = '<br>';
|
||
while (text.contains('<br>')) {
|
||
// flutter 算高度,单个\n算不准,必须加两个
|
||
text = text.replaceAll(tag, '\n\n');
|
||
}
|
||
return text;
|
||
}
|
||
|
||
|
||
String convertToTenThousand(int number) {
|
||
if (number >= 10000) {
|
||
double result = number / 10000;
|
||
return '${result.toStringAsFixed(1)}万';
|
||
} else {
|
||
return number.toString();
|
||
}
|
||
}
|
||
pushLoginPage() {
|
||
Get.offAllNamed(AppRoutes.Login);
|
||
}
|
||
String filterSensitiveWords(String input, List<String> sensitiveWords) {
|
||
String filteredString = input;
|
||
for (String word in sensitiveWords) {
|
||
String replacement = '*' * word.length;
|
||
filteredString = filteredString.replaceAll(word, replacement);
|
||
}
|
||
return filteredString;
|
||
}
|
||
|
||
String getAgeCOntent (int gender,int age,int role,int orientation){
|
||
return "${getGenderContent(gender)}.${age}.${getRoleContent(role)}.${getOrientationContent(orientation)}";
|
||
|
||
}
|
||
|
||
String getGenderContent(int number) {
|
||
switch (number) {
|
||
case 1:
|
||
return "男";
|
||
case 2:
|
||
return "女";
|
||
case 3:
|
||
return "MTF";
|
||
case 4:
|
||
return "FTM";
|
||
case 5:
|
||
return "CD";
|
||
case 6:
|
||
return "酷儿";
|
||
default:
|
||
return "";
|
||
}
|
||
}
|
||
String getOrientationContent(int number) {
|
||
switch (number) {
|
||
case 1:
|
||
return "异性恋";
|
||
case 2:
|
||
return "同性恋";
|
||
case 3:
|
||
return "双性恋";
|
||
case 4:
|
||
return "泛性恋";
|
||
case 5:
|
||
return "无性恋";
|
||
case 6:
|
||
return "智性恋";
|
||
case 7:
|
||
return "性单恋";
|
||
default:
|
||
return "";
|
||
}
|
||
}
|
||
String getRoleContent(int number) {
|
||
switch (number) {
|
||
case 1:
|
||
return "Sado";
|
||
case 2:
|
||
return "Maso";
|
||
case 3:
|
||
return "Dom";
|
||
case 4:
|
||
return "Sub";
|
||
case 5:
|
||
return "Switch";
|
||
default:
|
||
return "";
|
||
}
|
||
}
|
||
|
||
typedef void MyCallback(String path);
|
||
|
||
Future<void> compressVideo(String inputPath, String outputPath,MyCallback myCallback) async {
|
||
final info = await VideoCompress.compressVideo(
|
||
inputPath,
|
||
quality: VideoQuality.MediumQuality,
|
||
deleteOrigin: false,
|
||
);
|
||
|
||
if (info != null&&null!=info.path) {
|
||
print(info.path);
|
||
myCallback(info.path!);
|
||
} else {
|
||
print('视频压缩失败');
|
||
}
|
||
}
|
||
|
||
|
||
// 获取应用程序的文档目录路径
|
||
Future<String> getApplicationDocumentsDirectoryPath() async {
|
||
final directory = await getApplicationDocumentsDirectory();
|
||
return directory.path;
|
||
}
|
||
|
||
// 获取应用程序的支持目录路径
|
||
Future<String> getApplicationSupportDirectoryPath() async {
|
||
final directory = await getApplicationSupportDirectory();
|
||
return directory.path;
|
||
}
|
||
|
||
// 获取临时目录路径
|
||
Future<String> getTemporaryDirectoryPath() async {
|
||
final directory = await getTemporaryDirectory();
|
||
return directory.path;
|
||
}
|
||
|
||
// 获取库目录路径
|
||
Future<String> getLibraryDirectoryPath() async {
|
||
final directory = await getLibraryDirectory();
|
||
return directory.path;
|
||
}
|