Skip to content

Commit

Permalink
升级 getx get: ^5.0.0-release-candidate-5 代码做响应调整,jonataslaw/getx#2966
Browse files Browse the repository at this point in the history
  • Loading branch information
leeyisoft committed Jan 9, 2024
1 parent 04a0257 commit b1f5a2a
Show file tree
Hide file tree
Showing 54 changed files with 318 additions and 278 deletions.
4 changes: 4 additions & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.1.27
* 升级 getx get: ^5.0.0-release-candidate-5 代码做响应调整,https://github.com/jonataslaw/getx/issues/2966
*

# 0.1.26
* 引入 octo_image 库,聊天图片做相关调整;
* 引入 r_upgrade 库,做Android IOS APP升级功能;
Expand Down
17 changes: 17 additions & 0 deletions doc/cocoapods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


## m1 silicon macos 安装 cocoapods

https://wiki.ducafecat.tech/blog/flutter-tips/3-m1-macos-install-cocoapods.html#_4-%E5%AE%89%E8%A3%85-cocoapods

```
zsh
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
arch -arm64 brew upgrade
arch -arm64 brew reinstall ruby
rm -rf ~/.cocoapods
sudo gem install cocoapods
```
35 changes: 35 additions & 0 deletions lib/component/helper/datetime.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
import 'package:imboy/config/init.dart';
import 'package:imboy/service/storage.dart';
import 'package:jiffy/jiffy.dart';
import 'package:ntp/ntp.dart';

class DateTimeHelper {
static Future<int> getNtpOffset() async {
String key = "ntp_offset";
String? val = StorageService.to.getString(key);
// debugPrint("> on currentTimeMillis val1 ${val}");
// val = null;
int offset = 0;
if (val == null) {
try {
offset = await NTP.getNtpOffset(
localTime: Jiffy.now().dateTime,
lookUpAddress: 'time5.cloud.tencent.com',
);
// debugPrint("> on currentTimeMillis offset2 ${offset}");
String dt = Jiffy.now().format(pattern: 'y-MM-dd HH:mm:ss');
val = '$dt$offset';
// debugPrint("> on currentTimeMillis val2 ${val}");
StorageService.to.setString(key, val);
// ignore: empty_catches
} catch (e) {}
} else {
// 2022-01-23 00:30:35 字符串的长度刚好19位
offset = Jiffy.now().diff(
Jiffy.parse(val.substring(0, 19)),
unit: Unit.second,
) as int;
if (offset > 3600) {
await StorageService.to.remove(key);
return getNtpOffset();
}
}
return offset;
}

static String customDateHeader(DateTime dt) {
int diff = Jiffy.now().diff(
Jiffy.parseFromDateTime(dt),
Expand Down
3 changes: 1 addition & 2 deletions lib/component/helper/func.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:imboy/component/ui/icon_image_provider.dart';
import 'package:imboy/page/chat/chat/chat_binding.dart';
import 'package:imboy/page/chat/chat/chat_view.dart';
import 'package:imboy/service/assets.dart';
import 'package:imboy/service/encrypter.dart';
Expand Down Expand Up @@ -255,7 +254,7 @@ void toChatPage(String peerId, String type) async {
),
transition: Transition.rightToLeft,
popGesture: true, // 右滑,返回上一页
binding: ChatBinding(),
// binding: ChatBinding(),
);
}
}
4 changes: 2 additions & 2 deletions lib/component/helper/jwt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import 'package:imboy/component/helper/datetime.dart';
import 'package:jose/jose.dart';

/// 验证token是否过期
bool tokenExpired(String token) {
bool tokenExpired(String? token) {
try {
var jwt = JsonWebToken.unverified(token);
var jwt = JsonWebToken.unverified(token ?? '');
// 极端情况下扣除2秒
int ts = DateTimeHelper.currentTimeMillis() - 2000;
// debugPrint("> on jwt claims ${jwt.claims}, ${ts > jwt.claims['exp']}");
Expand Down
2 changes: 1 addition & 1 deletion lib/component/http/http_interceptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class IMBoyInterceptor extends Interceptor {
options.headers['device-type'] = Platform.operatingSystem;
options.headers['device-type-vsn'] = Platform.operatingSystemVersion;

String tk = UserRepoLocal.to.accessToken;
String? tk = UserRepoLocal.to.accessToken;
if (strNoEmpty(tk)) {
options.headers[Keys.tokenKey] = tk;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/component/image_gallery/image_gallery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void zoomInPhotoView(String thumb) async {
Get.bottomSheet(
InkWell(
onTap: () {
Get.back();
Get.close(closeBottomSheet: true);
},
child: PhotoView(
imageProvider: thumbProvider,
Expand Down
2 changes: 1 addition & 1 deletion lib/component/ui/select_region_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class SelectRegionPage extends StatelessWidget {
bool res = await outCallback(logic.selectedVal.value);
if (res) {
int t = logic.selectedVal.value.split(" ").length;
Get.close(t);
Get.back(times: t);
}
},
// ignore: sort_child_properties_last
Expand Down
6 changes: 3 additions & 3 deletions lib/component/webrtc/func.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Future<void> incomingCallScreen(
gTimer = Timer(const Duration(seconds: 60), () {
MessageService.to.changeLocalMsgState(msgId, 5);
if (Get.isDialogOpen != null && Get.isDialogOpen == true) {
Get.close(0);
Get.back(times: 1);
}
gTimer?.cancel();
gTimer = null;
Expand Down Expand Up @@ -195,7 +195,7 @@ Future<void> incomingCallScreen(
gTimer = null;
sendWebRTCMsg('busy', {}, to: peer.peerId);
p2pCallScreenOn = false;
Get.close(0);
Get.closeAllDialogs();
},
child: const Icon(Icons.call_end, color: Colors.white),
),
Expand All @@ -211,7 +211,7 @@ Future<void> incomingCallScreen(
onPressed: () {
gTimer?.cancel();
gTimer = null;
Get.close(0);
Get.closeAllDialogs();
option['msgId'] = msgId;
openCallScreen(peer, session: s, option, caller: false);
},
Expand Down
17 changes: 10 additions & 7 deletions lib/config/init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:get/get.dart' as getx;
import 'package:imboy/component/controller.dart';
import 'package:imboy/component/extension/device_ext.dart';
import 'package:imboy/component/extension/imboy_cache_manager.dart';
import 'package:imboy/component/helper/datetime.dart';
import 'package:imboy/component/helper/func.dart';
import 'package:imboy/component/helper/jwt.dart';
import 'package:imboy/component/http/http_client.dart';
Expand Down Expand Up @@ -71,10 +72,15 @@ String deviceId = '';

Future<void> init() async {
WakelockPlus.enable();

await StorageService.init();
// 放在 UserRepoLocal 前面
getx.Get.lazyPut(() => StorageService());

// 解决使用自签证书报错问题
io.HttpOverrides.global = GlobalHttpOverrides();
// Get.put(DeviceExt()); 需要放到靠前
getx.Get.put(DeviceExt());
getx.Get.lazyPut(() => DeviceExt());

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

// 放在 UserRepoLocal 前面
await getx.Get.putAsync<StorageService>(() => StorageService().init());

getx.Get.put(UserRepoLocal(), permanent: true);
getx.Get.lazyPut(() => ThemeController());

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

ntpOffset = await StorageService.to.ntpOffset();
ntpOffset = await DateTimeHelper.getNtpOffset();
AMapHelper.setApiKey();

// 初始化单例 WebSocketService
Expand All @@ -128,7 +131,7 @@ Future<void> init() async {
LifecycleEventHandler(
resumeCallBack: () async {
// app 恢复
String token = UserRepoLocal.to.accessToken;
String? token = UserRepoLocal.to.accessToken;
if (tokenExpired(token)) {
iPrint('LifecycleEventHandler tokenExpired true');
await (UserProvider()).refreshAccessTokenApi(
Expand All @@ -138,7 +141,7 @@ Future<void> init() async {
// 统计新申请好友数量
bnLogic.countNewFriendRemindCounter();
iPrint("> on LifecycleEventHandler resumeCallBack");
ntpOffset = await StorageService.to.ntpOffset();
ntpOffset = await DateTimeHelper.getNtpOffset();
// 检查WS链接状态
WebSocketService.to.openSocket();
},
Expand Down
6 changes: 3 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class IMBoyApp extends StatelessWidget {
? BottomNavigationPage()
: PassportPage(),
debugShowCheckedModeBanner: false,
getPages: AppPages.routes,
// getPages: AppPages.routes,
// initialRoute: AppPages.INITIAL,
// translations: TranslationService(),
navigatorObservers: [AppPages.observer],
Expand All @@ -185,8 +185,8 @@ class IMBoyApp extends StatelessWidget {
fallbackLocale: const Locale('en', 'US'),
// 添加一个回调语言选项,以备上面指定的语言翻译不存在
defaultTransition: Transition.fade,
opaqueRoute: Get.isOpaqueRouteDefault,
popGesture: Get.isPopGestureEnable,
// opaqueRoute: Get.isOpaqueRouteDefault,
// popGesture: Get.isPopGestureEnable,
// theme: Get.find<ThemeController>().darkMode == 0
// ? ThemeData.light()
// : ThemeData.dark(),
Expand Down
8 changes: 4 additions & 4 deletions lib/page/bottom_navigation/bottom_navigation_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'package:get/get.dart';

import 'bottom_navigation_logic.dart';

class BottomNavigationBinding extends Bindings {
class BottomNavigationBinding extends Binding {
@override
void dependencies() {
Get.lazyPut(() => BottomNavigationLogic());
}
List<Bind> dependencies() => [
Bind.lazyPut(() => BottomNavigationLogic()),
];
}
1 change: 1 addition & 0 deletions lib/page/bottom_navigation/bottom_navigation_view.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:badges/badges.dart' as badges;
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'package:imboy/page/contact/contact/contact_view.dart';
import 'package:imboy/page/conversation/conversation_logic.dart';
import 'package:imboy/page/conversation/conversation_view.dart';
Expand Down
10 changes: 5 additions & 5 deletions lib/page/chat/chat/chat_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import 'package:get/get.dart';
import 'chat_logic.dart';
import 'chat_state.dart';

class ChatBinding extends Bindings {
class ChatBinding extends Binding {
@override
void dependencies() {
Get.lazyPut(() => ChatLogic());
Get.lazyPut(() => ChatState());
}
List<Bind> dependencies() => [
Bind.lazyPut(() => ChatLogic()),
Bind.lazyPut(() => ChatState()),
];
}
2 changes: 1 addition & 1 deletion lib/page/chat/chat/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ class ChatPageState extends State<ChatPage> {
popGesture: true, // 右滑,返回上一页
)?.then((value) {
// debugPrint("ChatSettingPage then $value, $mounted");
if (value != null && value) {
if (value != null) {
_page = 1;
_handleEndReached();
}
Expand Down
8 changes: 4 additions & 4 deletions lib/page/chat/chat_background/chat_background_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'package:get/get.dart';

import 'chat_background_logic.dart';

class ChatBackgroundBinding extends Bindings {
class ChatBackgroundBinding extends Binding {
@override
void dependencies() {
Get.lazyPut(() => ChatBackgroundLogic());
}
List<Bind> dependencies() => [
Bind.lazyPut(() => ChatBackgroundLogic()),
];
}
8 changes: 4 additions & 4 deletions lib/page/chat/chat_setting/chat_setting_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'package:get/get.dart';

import 'chat_setting_logic.dart';

class ChatSettingBinding extends Bindings {
class ChatSettingBinding extends Binding {
@override
void dependencies() {
Get.lazyPut(() => ChatSettingLogic());
}
List<Bind> dependencies() => [
Bind.lazyPut(() => ChatSettingLogic()),
];
}
10 changes: 5 additions & 5 deletions lib/page/chat/send_to/send_to_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class SendToPage extends StatelessWidget {
}

/// 分别发送给
void separatelySendToDialog(List items, int callbackTime) {
void separatelySendToDialog(List items, int times) {
List towD = listTo2D(items, 5);
Get.defaultDialog(
title: '分别发送给'.tr,
Expand All @@ -270,12 +270,12 @@ class SendToPage extends StatelessWidget {
callback!();
}
Future.delayed(const Duration(milliseconds: 1600), () {
Get.close(callbackTime);
Get.back(times: times);
});
// if (res) {
// EasyLoading.showSuccess('发送成功'.tr);
// Future.delayed(const Duration(milliseconds: 1600), () {
// Get.close(callbackTime);
// Get.back(times: times);
// });
// } else {
// EasyLoading.showError('发送失败'.tr);
Expand Down Expand Up @@ -318,7 +318,7 @@ class SendToPage extends StatelessWidget {
);
}

void sendToDialog(ConversationModel model, int callbackTime) {
void sendToDialog(ConversationModel model, int times) {
Get.defaultDialog(
title: '发送给'.tr,
radius: 6,
Expand All @@ -342,7 +342,7 @@ class SendToPage extends StatelessWidget {
callback!();
}
Future.delayed(const Duration(milliseconds: 1600), () {
Get.close(callbackTime);
Get.back(times: times);
});
} else {
EasyLoading.showError('发送失败'.tr);
Expand Down
3 changes: 2 additions & 1 deletion lib/page/contact/apply_friend/apply_friend_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class ApplyFriendLogic extends GetxController {
// debugPrint("> on receivedAddFriend ${saveData.toString()}");
(NewFriendRepo()).save(saveData);
EasyLoading.showSuccess("已发送".tr);
Get.close(2);
Get.back();
Get.back();
} else {
EasyLoading.showError("网络故障,请重试!".tr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ConfirmNewFriendLogic extends GetxController {
bottomNavigationLogic.newFriendRemindCounter,
]);
});
Get.close(1);
Get.back(times: 1);
} else {
EasyLoading.showError("网络故障,请重试!".tr);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/page/contact/contact_setting/contact_setting_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class ContactSettingPage extends StatelessWidget {
bool res = await logic.deleteContact(peerId);
if (res) {
EasyLoading.showSuccess("操作成功");
Get.close(3);
Get.back(times: 3);
Get.to(
() => BottomNavigationPage(),
arguments: {'index': 1},
Expand Down
3 changes: 2 additions & 1 deletion lib/page/conversation/conversation_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ class _ConversationPageState extends State<ConversationPage> {
key: ValueKey(model.id),
groupTag: '0',
closeOnScroll: true,
startActionPane: ActionPane(

endActionPane: ActionPane(
extentRatio: 0.75,
motion: const StretchMotion(),
children: [
Expand Down
Loading

0 comments on commit b1f5a2a

Please sign in to comment.