utils.dart
6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import 'dart:io';
import 'package:common_utils/common_utils.dart';
import 'package:connectivity/connectivity.dart';
import 'package:device_info/device_info.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter/services.dart';
import 'package:fluwx/fluwx.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/utils/navigator_util.dart';
import 'package:package_info/package_info.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:webview_flutter/webview_flutter.dart';
import '../app.dart';
class Utils {
static void showToast(String msg) {
Fluttertoast.showToast(msg: msg, gravity: ToastGravity.CENTER);
}
//本地图片资源路径
static String getImgPath(String name, {String format: 'png'}) {
return 'assets/$name.$format';
}
//给数字前面加0
static String addZeroNumber(int num) {
return num < 10 ? "0" + num.toString() : num.toString();
}
//转换日期数字
static String formatWeekDayNum(int num) {
switch (num) {
case 1:
return "一";
case 2:
return "二";
case 3:
return "三";
case 4:
return "四";
case 5:
return "五";
case 6:
return "六";
case 7:
return "日";
default:
return "";
}
}
// 改变状态栏背景颜色,默认改变为透明
static changeStatusColor({Color color: Colors.white}) async {
try {
await FlutterStatusbarcolor.setStatusBarColor(color, animate: true);
if (useWhiteForeground(color)) {
FlutterStatusbarcolor.setStatusBarWhiteForeground(true);
} else {
FlutterStatusbarcolor.setStatusBarWhiteForeground(false);
}
} on PlatformException catch (e) {
debugPrint(e.toString());
}
}
//跳转拨打电话页面
static goPhone(String phoneNum) async {
String url = "tel:$phoneNum";
if (await canLaunch(url)) {
await launch(url);
} else {
LogUtil.e("Could not launch $url");
}
}
//跳转小程序包间类型置满管理
static goMiniProgramZm(BuildContext context){
UserModel model=Provider.of<UserModel>(context);
launchWeChatMiniProgram(
username: "gh_487873d353b3",
path: "pack-book/pages/book/b_index?seller_id=${model.user.sellerid}&seller_openid=seller_openid&manager_id=&goPath=roomtype/roomtype",
miniProgramType: WXMiniProgramType.RELEASE);
}
//跳转拨打电话页面
static goHelp(BuildContext context) async {
NavigatorUtil.goWebviewPage(context);
}
//获取应用版本昊
static Future<String> getCurrVersion() async {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
String version = packageInfo.version;
return version;
}
//获取当前构建版本号
static Future<int> getCurrBuildNum() async {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
return int.parse(packageInfo.buildNumber);
}
//获取唯一标识
static Future<String> getUUID() async {
DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
if (Platform.isAndroid) {
AndroidDeviceInfo androidDeviceInfo = await deviceInfoPlugin.androidInfo;
return androidDeviceInfo.androidId;
} else {
IosDeviceInfo iosDeviceInfo = await deviceInfoPlugin.iosInfo;
return iosDeviceInfo.identifierForVendor;
}
}
//比较两个日期是否同一天
static isOneDay(DateTime one, DateTime two) {
if (one.year == two.year && one.month == two.month && one.day == two.day)
return true;
return false;
}
//分享邀请函
static goShareInvicationToWeChat(String rid) {
String _webPageUrl = "http://colorcun.com/";
String _thumbnail =
"https://qn.colorcun.com/reserve/images/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_201911151148572.jpg";
String _title = "用餐已为您安排,点击查看详情";
String _userName = "gh_487873d353b3";
String _path = "pages/customer/index?id=$rid&hasInvitation=1";
String _description = "OneKey";
var model = new WeChatShareMiniProgramModel(
webPageUrl: _webPageUrl,
userName: _userName,
title: _title,
path: _path,
description: _description,
thumbnail: WeChatImage.network(_thumbnail));
shareToWeChat(model);
}
//检查网络连接
static Future<bool> checkConnectiviy() async {
var connectivityResult = await (new Connectivity().checkConnectivity());
if (connectivityResult == ConnectivityResult.mobile) {
// I am connected to a mobile network.
return true;
} else if (connectivityResult == ConnectivityResult.wifi) {
// I am connected to a wifi network.
return true;
}
return false;
}
/// 获取日期 今天 明天 后天等等
static int getDdate(List dateList) {
//当前选中 月 日string
String mdStr = '';
//今天 明天 其他天
for (var item in dateList) {
if (item['select'] == true) {
mdStr = item['title'];
}
}
String timeNowYear = DateUtil.formatDate(DateTime.now(), format: 'yyyy');
String ymyStr = timeNowYear + '-' + mdStr; //年月日
String timeStr = ymyStr + ' ' + "00:00:00";
int ddate = DateUtil.getDateMsByTimeStr(timeStr); //筛选日期时间戳
return ddate;
}
/// 获取早餐、午餐、晚餐字段 1 ,2, 3
static String getDdateSolt(List sunDateList) {
String ddateSolt = '';
for (var item in sunDateList) {
if (item['isSelect']) {
ddateSolt = '${item['ddateSolt']}';
}
}
return ddateSolt;
}
/// 选中前面的按钮获取人数,输入的自己获取
static String getPnum(List personNumList) {
String pnum = '6';
for (var item in personNumList) {
if (item['isSelect']) {
pnum = item['dateText'];
}
}
if (pnum == '更多') {
pnum = '6';
}
return pnum;
}
}