144 lines
4.2 KiB
Dart
144 lines
4.2 KiB
Dart
|
|
import 'dart:io';
|
|
|
|
import 'package:circle_app/app/splash/binding.dart';
|
|
import 'package:circle_app/router/app_pages.dart';
|
|
import 'package:circle_app/router/app_routers.dart';
|
|
import 'package:circle_app/util/PaymentUtils.dart';
|
|
import 'package:circle_app/util/util.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';
|
|
|
|
import 'app/splash/view.dart';
|
|
|
|
|
|
final CoreServicesImpl coreInstance = TIMUIKitCore.getInstance();
|
|
|
|
void main() {
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
|
|
//登录IM
|
|
loginIM(String userId,String sig) async {
|
|
var info = await coreInstance.login(
|
|
userID: userId,
|
|
userSig:sig,);
|
|
}
|
|
|
|
//退出IM
|
|
logoutIM() async {
|
|
final result = await coreInstance.logout();
|
|
print(result.desc + '退出IM');
|
|
}
|
|
|
|
//跳转发消息页面
|
|
pushChatPage(String imId,String userName) {
|
|
var con = V2TimConversation(
|
|
conversationID: "c2c_$imId",
|
|
userID: imId,
|
|
showName: userName,
|
|
type: 1);
|
|
Get.toNamed(AppRoutes.Chat,arguments: con);
|
|
}
|
|
|
|
class MyApp extends StatefulWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
State<MyApp> createState() => _MyAppState();
|
|
}
|
|
|
|
|
|
|
|
class _MyAppState extends State<MyApp> {
|
|
// This widget is the root of your application.
|
|
|
|
final List<String> _guideList = ['bg', 'home_back'];
|
|
|
|
|
|
@override
|
|
void initState() {
|
|
initIM();
|
|
if( Platform.isAndroid){
|
|
initWxApi();
|
|
}
|
|
loadBgImage();
|
|
super.initState();
|
|
}
|
|
|
|
initIM() {
|
|
coreInstance.init(
|
|
sdkAppID:
|
|
1400799631, // Replace 0 with the SDKAppID of your IM application when integrating
|
|
// language: LanguageEnum.en, // 界面语言配置,若不配置,则跟随系统语言
|
|
loglevel: LogLevelEnum.V2TIM_LOG_DEBUG,
|
|
onTUIKitCallbackListener: (TIMCallback callbackValue) {
|
|
switch (callbackValue.type) {
|
|
case TIMCallbackType.INFO:
|
|
// Shows the recommend text for info callback directly
|
|
showToast(callbackValue.infoRecommendText!);
|
|
break;
|
|
case TIMCallbackType.API_ERROR:
|
|
//Prints the API error to console, and shows the error message.
|
|
print(
|
|
"Error from TUIKit: ${callbackValue.errorMsg}, Code: ${callbackValue.errorCode}");
|
|
if (callbackValue.errorCode == 10004 &&
|
|
callbackValue.errorMsg!.contains("not support @all")) {
|
|
showToast("当前群组不支持@全体成员");
|
|
} else {
|
|
showToast(callbackValue.errorMsg ??
|
|
callbackValue.errorCode.toString());
|
|
}
|
|
break;
|
|
case TIMCallbackType.FLUTTER_ERROR:
|
|
default:
|
|
// prints the stack trace to console or shows the catch error
|
|
if (callbackValue.catchError != null) {
|
|
showToast(callbackValue.catchError.toString());
|
|
} else {
|
|
print(callbackValue.stackTrace);
|
|
// loginIM();
|
|
}
|
|
}
|
|
}, // [建议配置,详见此部分](https://cloud.tencent.com/document/product/269/70746#callback)
|
|
listener: V2TimSDKListener(onConnectSuccess: () {
|
|
print('IM登录成功');
|
|
// loginIM();
|
|
}));
|
|
}
|
|
|
|
loadBgImage() async {
|
|
await precacheImage(precacheImages(_guideList.first),context);
|
|
await precacheImage(precacheImages(_guideList.last),context);
|
|
}
|
|
|
|
precacheImages(String image) {
|
|
return AssetImage(getBaseImage(image));
|
|
}
|
|
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
//填入设计稿中设备的屏幕尺寸,单位dp
|
|
// configureDio();
|
|
return ScreenUtilInit(
|
|
designSize: const Size(375, 812),
|
|
minTextAdapt: true,
|
|
splitScreenMode: true,
|
|
builder: (context, child) {
|
|
return GetMaterialApp(
|
|
title: 'Flutter Demo',
|
|
initialBinding: SplashBinding(),
|
|
getPages: AppPages.routes,
|
|
home: SplashPage(),
|
|
builder: FlutterSmartDialog.init(),
|
|
debugShowCheckedModeBanner: false,
|
|
);
|
|
});
|
|
}
|
|
}
|