Skip to content

Commit b1f5a2a

Browse files
committed
升级 getx get: ^5.0.0-release-candidate-5 代码做响应调整,jonataslaw/getx#2966
1 parent 04a0257 commit b1f5a2a

File tree

54 files changed

+318
-278
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+318
-278
lines changed

doc/changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.1.27
2+
* 升级 getx get: ^5.0.0-release-candidate-5 代码做响应调整,https://github.com/jonataslaw/getx/issues/2966
3+
*
4+
15
# 0.1.26
26
* 引入 octo_image 库,聊天图片做相关调整;
37
* 引入 r_upgrade 库,做Android IOS APP升级功能;

doc/cocoapods.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
3+
## m1 silicon macos 安装 cocoapods
4+
5+
https://wiki.ducafecat.tech/blog/flutter-tips/3-m1-macos-install-cocoapods.html#_4-%E5%AE%89%E8%A3%85-cocoapods
6+
7+
```
8+
zsh
9+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
10+
11+
arch -arm64 brew upgrade
12+
13+
arch -arm64 brew reinstall ruby
14+
15+
rm -rf ~/.cocoapods
16+
sudo gem install cocoapods
17+
```

lib/component/helper/datetime.dart

+35
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,42 @@
11
import 'package:imboy/config/init.dart';
2+
import 'package:imboy/service/storage.dart';
23
import 'package:jiffy/jiffy.dart';
4+
import 'package:ntp/ntp.dart';
35

46
class DateTimeHelper {
7+
static Future<int> getNtpOffset() async {
8+
String key = "ntp_offset";
9+
String? val = StorageService.to.getString(key);
10+
// debugPrint("> on currentTimeMillis val1 ${val}");
11+
// val = null;
12+
int offset = 0;
13+
if (val == null) {
14+
try {
15+
offset = await NTP.getNtpOffset(
16+
localTime: Jiffy.now().dateTime,
17+
lookUpAddress: 'time5.cloud.tencent.com',
18+
);
19+
// debugPrint("> on currentTimeMillis offset2 ${offset}");
20+
String dt = Jiffy.now().format(pattern: 'y-MM-dd HH:mm:ss');
21+
val = '$dt$offset';
22+
// debugPrint("> on currentTimeMillis val2 ${val}");
23+
StorageService.to.setString(key, val);
24+
// ignore: empty_catches
25+
} catch (e) {}
26+
} else {
27+
// 2022-01-23 00:30:35 字符串的长度刚好19位
28+
offset = Jiffy.now().diff(
29+
Jiffy.parse(val.substring(0, 19)),
30+
unit: Unit.second,
31+
) as int;
32+
if (offset > 3600) {
33+
await StorageService.to.remove(key);
34+
return getNtpOffset();
35+
}
36+
}
37+
return offset;
38+
}
39+
540
static String customDateHeader(DateTime dt) {
641
int diff = Jiffy.now().diff(
742
Jiffy.parseFromDateTime(dt),

lib/component/helper/func.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import 'package:cached_network_image/cached_network_image.dart';
44
import 'package:flutter/material.dart';
55
import 'package:get/get.dart';
66
import 'package:imboy/component/ui/icon_image_provider.dart';
7-
import 'package:imboy/page/chat/chat/chat_binding.dart';
87
import 'package:imboy/page/chat/chat/chat_view.dart';
98
import 'package:imboy/service/assets.dart';
109
import 'package:imboy/service/encrypter.dart';
@@ -255,7 +254,7 @@ void toChatPage(String peerId, String type) async {
255254
),
256255
transition: Transition.rightToLeft,
257256
popGesture: true, // 右滑,返回上一页
258-
binding: ChatBinding(),
257+
// binding: ChatBinding(),
259258
);
260259
}
261260
}

lib/component/helper/jwt.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import 'package:imboy/component/helper/datetime.dart';
33
import 'package:jose/jose.dart';
44

55
/// 验证token是否过期
6-
bool tokenExpired(String token) {
6+
bool tokenExpired(String? token) {
77
try {
8-
var jwt = JsonWebToken.unverified(token);
8+
var jwt = JsonWebToken.unverified(token ?? '');
99
// 极端情况下扣除2秒
1010
int ts = DateTimeHelper.currentTimeMillis() - 2000;
1111
// debugPrint("> on jwt claims ${jwt.claims}, ${ts > jwt.claims['exp']}");

lib/component/http/http_interceptor.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class IMBoyInterceptor extends Interceptor {
1212
options.headers['device-type'] = Platform.operatingSystem;
1313
options.headers['device-type-vsn'] = Platform.operatingSystemVersion;
1414

15-
String tk = UserRepoLocal.to.accessToken;
15+
String? tk = UserRepoLocal.to.accessToken;
1616
if (strNoEmpty(tk)) {
1717
options.headers[Keys.tokenKey] = tk;
1818
}

lib/component/image_gallery/image_gallery.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void zoomInPhotoView(String thumb) async {
138138
Get.bottomSheet(
139139
InkWell(
140140
onTap: () {
141-
Get.back();
141+
Get.close(closeBottomSheet: true);
142142
},
143143
child: PhotoView(
144144
imageProvider: thumbProvider,

lib/component/ui/select_region_view.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class SelectRegionPage extends StatelessWidget {
169169
bool res = await outCallback(logic.selectedVal.value);
170170
if (res) {
171171
int t = logic.selectedVal.value.split(" ").length;
172-
Get.close(t);
172+
Get.back(times: t);
173173
}
174174
},
175175
// ignore: sort_child_properties_last

lib/component/webrtc/func.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Future<void> incomingCallScreen(
124124
gTimer = Timer(const Duration(seconds: 60), () {
125125
MessageService.to.changeLocalMsgState(msgId, 5);
126126
if (Get.isDialogOpen != null && Get.isDialogOpen == true) {
127-
Get.close(0);
127+
Get.back(times: 1);
128128
}
129129
gTimer?.cancel();
130130
gTimer = null;
@@ -195,7 +195,7 @@ Future<void> incomingCallScreen(
195195
gTimer = null;
196196
sendWebRTCMsg('busy', {}, to: peer.peerId);
197197
p2pCallScreenOn = false;
198-
Get.close(0);
198+
Get.closeAllDialogs();
199199
},
200200
child: const Icon(Icons.call_end, color: Colors.white),
201201
),
@@ -211,7 +211,7 @@ Future<void> incomingCallScreen(
211211
onPressed: () {
212212
gTimer?.cancel();
213213
gTimer = null;
214-
Get.close(0);
214+
Get.closeAllDialogs();
215215
option['msgId'] = msgId;
216216
openCallScreen(peer, session: s, option, caller: false);
217217
},

lib/config/init.dart

+10-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:get/get.dart' as getx;
1010
import 'package:imboy/component/controller.dart';
1111
import 'package:imboy/component/extension/device_ext.dart';
1212
import 'package:imboy/component/extension/imboy_cache_manager.dart';
13+
import 'package:imboy/component/helper/datetime.dart';
1314
import 'package:imboy/component/helper/func.dart';
1415
import 'package:imboy/component/helper/jwt.dart';
1516
import 'package:imboy/component/http/http_client.dart';
@@ -71,10 +72,15 @@ String deviceId = '';
7172

7273
Future<void> init() async {
7374
WakelockPlus.enable();
75+
76+
await StorageService.init();
77+
// 放在 UserRepoLocal 前面
78+
getx.Get.lazyPut(() => StorageService());
79+
7480
// 解决使用自签证书报错问题
7581
io.HttpOverrides.global = GlobalHttpOverrides();
7682
// Get.put(DeviceExt()); 需要放到靠前
77-
getx.Get.put(DeviceExt());
83+
getx.Get.lazyPut(() => DeviceExt());
7884

7985
PackageInfo packageInfo = await PackageInfo.fromPlatform();
8086
appVsn = packageInfo.version;
@@ -86,9 +92,6 @@ Future<void> init() async {
8692
await dotenv.load(fileName: ".env"); //
8793
// iPrint("> on UP_AUTH_KEY: ${dotenv.get('UP_AUTH_KEY')}");
8894

89-
// 放在 UserRepoLocal 前面
90-
await getx.Get.putAsync<StorageService>(() => StorageService().init());
91-
9295
getx.Get.put(UserRepoLocal(), permanent: true);
9396
getx.Get.lazyPut(() => ThemeController());
9497

@@ -114,7 +117,7 @@ Future<void> init() async {
114117
getx.Get.put(MessageService());
115118
// getx.Get.lazyPut(() => DeviceExt());
116119

117-
ntpOffset = await StorageService.to.ntpOffset();
120+
ntpOffset = await DateTimeHelper.getNtpOffset();
118121
AMapHelper.setApiKey();
119122

120123
// 初始化单例 WebSocketService
@@ -128,7 +131,7 @@ Future<void> init() async {
128131
LifecycleEventHandler(
129132
resumeCallBack: () async {
130133
// app 恢复
131-
String token = UserRepoLocal.to.accessToken;
134+
String? token = UserRepoLocal.to.accessToken;
132135
if (tokenExpired(token)) {
133136
iPrint('LifecycleEventHandler tokenExpired true');
134137
await (UserProvider()).refreshAccessTokenApi(
@@ -138,7 +141,7 @@ Future<void> init() async {
138141
// 统计新申请好友数量
139142
bnLogic.countNewFriendRemindCounter();
140143
iPrint("> on LifecycleEventHandler resumeCallBack");
141-
ntpOffset = await StorageService.to.ntpOffset();
144+
ntpOffset = await DateTimeHelper.getNtpOffset();
142145
// 检查WS链接状态
143146
WebSocketService.to.openSocket();
144147
},

lib/main.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class IMBoyApp extends StatelessWidget {
167167
? BottomNavigationPage()
168168
: PassportPage(),
169169
debugShowCheckedModeBanner: false,
170-
getPages: AppPages.routes,
170+
// getPages: AppPages.routes,
171171
// initialRoute: AppPages.INITIAL,
172172
// translations: TranslationService(),
173173
navigatorObservers: [AppPages.observer],
@@ -185,8 +185,8 @@ class IMBoyApp extends StatelessWidget {
185185
fallbackLocale: const Locale('en', 'US'),
186186
// 添加一个回调语言选项,以备上面指定的语言翻译不存在
187187
defaultTransition: Transition.fade,
188-
opaqueRoute: Get.isOpaqueRouteDefault,
189-
popGesture: Get.isPopGestureEnable,
188+
// opaqueRoute: Get.isOpaqueRouteDefault,
189+
// popGesture: Get.isPopGestureEnable,
190190
// theme: Get.find<ThemeController>().darkMode == 0
191191
// ? ThemeData.light()
192192
// : ThemeData.dark(),

lib/page/bottom_navigation/bottom_navigation_binding.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import 'package:get/get.dart';
22

33
import 'bottom_navigation_logic.dart';
44

5-
class BottomNavigationBinding extends Bindings {
5+
class BottomNavigationBinding extends Binding {
66
@override
7-
void dependencies() {
8-
Get.lazyPut(() => BottomNavigationLogic());
9-
}
7+
List<Bind> dependencies() => [
8+
Bind.lazyPut(() => BottomNavigationLogic()),
9+
];
1010
}

lib/page/bottom_navigation/bottom_navigation_view.dart

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:badges/badges.dart' as badges;
22
import 'package:flutter/material.dart';
33
import 'package:get/get.dart';
4+
45
import 'package:imboy/page/contact/contact/contact_view.dart';
56
import 'package:imboy/page/conversation/conversation_logic.dart';
67
import 'package:imboy/page/conversation/conversation_view.dart';

lib/page/chat/chat/chat_binding.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import 'package:get/get.dart';
33
import 'chat_logic.dart';
44
import 'chat_state.dart';
55

6-
class ChatBinding extends Bindings {
6+
class ChatBinding extends Binding {
77
@override
8-
void dependencies() {
9-
Get.lazyPut(() => ChatLogic());
10-
Get.lazyPut(() => ChatState());
11-
}
8+
List<Bind> dependencies() => [
9+
Bind.lazyPut(() => ChatLogic()),
10+
Bind.lazyPut(() => ChatState()),
11+
];
1212
}

lib/page/chat/chat/chat_view.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ class ChatPageState extends State<ChatPage> {
812812
popGesture: true, // 右滑,返回上一页
813813
)?.then((value) {
814814
// debugPrint("ChatSettingPage then $value, $mounted");
815-
if (value != null && value) {
815+
if (value != null) {
816816
_page = 1;
817817
_handleEndReached();
818818
}

lib/page/chat/chat_background/chat_background_binding.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import 'package:get/get.dart';
22

33
import 'chat_background_logic.dart';
44

5-
class ChatBackgroundBinding extends Bindings {
5+
class ChatBackgroundBinding extends Binding {
66
@override
7-
void dependencies() {
8-
Get.lazyPut(() => ChatBackgroundLogic());
9-
}
7+
List<Bind> dependencies() => [
8+
Bind.lazyPut(() => ChatBackgroundLogic()),
9+
];
1010
}

lib/page/chat/chat_setting/chat_setting_binding.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import 'package:get/get.dart';
22

33
import 'chat_setting_logic.dart';
44

5-
class ChatSettingBinding extends Bindings {
5+
class ChatSettingBinding extends Binding {
66
@override
7-
void dependencies() {
8-
Get.lazyPut(() => ChatSettingLogic());
9-
}
7+
List<Bind> dependencies() => [
8+
Bind.lazyPut(() => ChatSettingLogic()),
9+
];
1010
}

lib/page/chat/send_to/send_to_view.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class SendToPage extends StatelessWidget {
245245
}
246246

247247
/// 分别发送给
248-
void separatelySendToDialog(List items, int callbackTime) {
248+
void separatelySendToDialog(List items, int times) {
249249
List towD = listTo2D(items, 5);
250250
Get.defaultDialog(
251251
title: '分别发送给'.tr,
@@ -270,12 +270,12 @@ class SendToPage extends StatelessWidget {
270270
callback!();
271271
}
272272
Future.delayed(const Duration(milliseconds: 1600), () {
273-
Get.close(callbackTime);
273+
Get.back(times: times);
274274
});
275275
// if (res) {
276276
// EasyLoading.showSuccess('发送成功'.tr);
277277
// Future.delayed(const Duration(milliseconds: 1600), () {
278-
// Get.close(callbackTime);
278+
// Get.back(times: times);
279279
// });
280280
// } else {
281281
// EasyLoading.showError('发送失败'.tr);
@@ -318,7 +318,7 @@ class SendToPage extends StatelessWidget {
318318
);
319319
}
320320

321-
void sendToDialog(ConversationModel model, int callbackTime) {
321+
void sendToDialog(ConversationModel model, int times) {
322322
Get.defaultDialog(
323323
title: '发送给'.tr,
324324
radius: 6,
@@ -342,7 +342,7 @@ class SendToPage extends StatelessWidget {
342342
callback!();
343343
}
344344
Future.delayed(const Duration(milliseconds: 1600), () {
345-
Get.close(callbackTime);
345+
Get.back(times: times);
346346
});
347347
} else {
348348
EasyLoading.showError('发送失败'.tr);

lib/page/contact/apply_friend/apply_friend_logic.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ class ApplyFriendLogic extends GetxController {
7575
// debugPrint("> on receivedAddFriend ${saveData.toString()}");
7676
(NewFriendRepo()).save(saveData);
7777
EasyLoading.showSuccess("已发送".tr);
78-
Get.close(2);
78+
Get.back();
79+
Get.back();
7980
} else {
8081
EasyLoading.showError("网络故障,请重试!".tr);
8182
}

lib/page/contact/confirm_new_friend/confirm_new_friend_logic.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class ConfirmNewFriendLogic extends GetxController {
7777
bottomNavigationLogic.newFriendRemindCounter,
7878
]);
7979
});
80-
Get.close(1);
80+
Get.back(times: 1);
8181
} else {
8282
EasyLoading.showError("网络故障,请重试!".tr);
8383
}

lib/page/contact/contact_setting/contact_setting_view.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class ContactSettingPage extends StatelessWidget {
261261
bool res = await logic.deleteContact(peerId);
262262
if (res) {
263263
EasyLoading.showSuccess("操作成功");
264-
Get.close(3);
264+
Get.back(times: 3);
265265
Get.to(
266266
() => BottomNavigationPage(),
267267
arguments: {'index': 1},

lib/page/conversation/conversation_view.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ class _ConversationPageState extends State<ConversationPage> {
137137
key: ValueKey(model.id),
138138
groupTag: '0',
139139
closeOnScroll: true,
140-
startActionPane: ActionPane(
140+
141+
endActionPane: ActionPane(
141142
extentRatio: 0.75,
142143
motion: const StretchMotion(),
143144
children: [

0 commit comments

Comments
 (0)