This commit is contained in:
2025-06-30 16:24:20 +08:00
commit 68de5eb048
454 changed files with 56921 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
enum TIMCallbackType { API_ERROR, FLUTTER_ERROR, INFO }
class TIMCallback {
TIMCallbackType? type;
String? errorMsg;
int? errorCode;
StackTrace? stackTrace;
Object? catchError;
int? infoCode;
String? infoRecommendText;
TIMCallback(
{this.catchError,
this.infoRecommendText,
this.errorMsg,
this.errorCode,
this.stackTrace,
this.infoCode,
this.type});
}
+51
View File
@@ -0,0 +1,51 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'dart:io';
import 'package:tencent_cloud_chat_uikit/base_widgets/tim_callback.dart';
abstract class TIMState<T extends StatefulWidget> extends State<T> {
@override
initState() {
super.initState();
}
// override这个函数来承接处理onTIMCallback回调。
// 目前base层,会自动触发`TIMCallbackType.FLUTTER_ERROR`类型Flutter Framework异常。
// 其他类型callback请自行处理。
void onTIMCallback(TIMCallback callbackValue) {
// TODO: 这里后续看看要不要默认加上报逻辑。
}
bool isAndroidDevice(){
return !kIsWeb && Platform.isAndroid;
}
bool isIosDevice(){
return !kIsWeb && Platform.isIOS;
}
bool isWebDevice(){
return kIsWeb;
}
setTIMState(VoidCallback fn){
}
@override
Widget build(BuildContext context) {
FlutterError.onError = (FlutterErrorDetails details) {
FlutterError.presentError(details);
onTIMCallback(TIMCallback(
type: TIMCallbackType.FLUTTER_ERROR,
stackTrace: details.stack,
errorMsg: "Error from Flutter"));
};
return timBuild(context);
}
// 请override这个方法来render界面
Widget timBuild(BuildContext context);
}
@@ -0,0 +1,43 @@
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:tencent_cloud_chat_uikit/base_widgets/tim_callback.dart';
abstract class TIMStatelessWidget extends StatelessWidget {
const TIMStatelessWidget({Key? key}) : super(key: key);
// override这个函数来承接处理onTIMCallback回调。
// 目前base层,会自动触发`TIMCallbackType.FLUTTER_ERROR`类型Flutter Framework异常。
// 其他类型callback请自行处理。
void onTIMCallback(TIMCallback callbackValue) {
}
bool isAndroidDevice(){
return !kIsWeb && Platform.isAndroid;
}
bool isIosDevice(){
return !kIsWeb && Platform.isIOS;
}
bool isWebDevice(){
return kIsWeb;
}
@override
Widget build(BuildContext context) {
FlutterError.onError = (FlutterErrorDetails details) {
FlutterError.presentError(details);
onTIMCallback(TIMCallback(
type: TIMCallbackType.FLUTTER_ERROR,
stackTrace: details.stack,
errorMsg: "Error from Flutter"));
};
return timBuild(context);
}
// 请override这个方法来render界面
Widget timBuild(BuildContext context);
}
+8
View File
@@ -0,0 +1,8 @@
import 'package:tencent_cloud_chat_uikit/theme/tui_theme.dart';
class TUIKitBuildValue {
// 这里预留以后可以扩展全局通用能力
TUITheme theme;
TUIKitBuildValue({required this.theme});
}
+12
View File
@@ -0,0 +1,12 @@
import 'package:tencent_cloud_chat_uikit/base_widgets/tim_callback.dart';
import 'package:tencent_cloud_chat_uikit/data_services/core/core_services_implements.dart';
import 'package:tencent_cloud_chat_uikit/data_services/services_locatar.dart';
class TIMUIKitClass {
static final CoreServicesImpl _coreServices =
serviceLocator<CoreServicesImpl>();
static void onTIMCallback(TIMCallback callbackValue) {
_coreServices.callOnCallback(callbackValue);
}
}
+39
View File
@@ -0,0 +1,39 @@
import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';
import 'package:tencent_cloud_chat_uikit/base_widgets/tim_callback.dart';
import 'package:tencent_cloud_chat_uikit/base_widgets/tim_state.dart';
import 'package:tencent_cloud_chat_uikit/base_widgets/tim_ui_kit_base.dart';
import 'package:tencent_cloud_chat_uikit/data_services/core/core_services_implements.dart';
import 'package:tencent_cloud_chat_uikit/data_services/services_locatar.dart';
import 'package:tencent_cloud_chat_uikit/theme/tui_theme_view_model.dart';
class TIMUIKitState<T extends StatefulWidget> extends TIMState<T> {
final CoreServicesImpl _coreServices = serviceLocator<CoreServicesImpl>();
@override
void onTIMCallback(TIMCallback callbackValue) {
super.onTIMCallback(callbackValue);
_coreServices.callOnCallback(callbackValue);
}
@override
Widget timBuild(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider.value(
value: serviceLocator<TUIThemeViewModel>()),
],
builder: (BuildContext context, Widget? w) {
final theme = Provider.of<TUIThemeViewModel>(context).theme;
final value = TUIKitBuildValue(theme: theme);
return tuiBuild(context, value);
},
);
}
@required
Widget tuiBuild(BuildContext context, TUIKitBuildValue value) {
return Container();
}
}
@@ -0,0 +1,40 @@
import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';
import 'package:tencent_cloud_chat_uikit/base_widgets/tim_callback.dart';
import 'package:tencent_cloud_chat_uikit/base_widgets/tim_stateless_widget.dart';
import 'package:tencent_cloud_chat_uikit/base_widgets/tim_ui_kit_base.dart';
import 'package:tencent_cloud_chat_uikit/data_services/core/core_services_implements.dart';
import 'package:tencent_cloud_chat_uikit/data_services/services_locatar.dart';
import 'package:tencent_cloud_chat_uikit/theme/tui_theme_view_model.dart';
class TIMUIKitStatelessWidget extends TIMStatelessWidget {
final CoreServicesImpl _coreServices = serviceLocator<CoreServicesImpl>();
TIMUIKitStatelessWidget({Key? key}) : super(key: key);
@override
void onTIMCallback(TIMCallback callbackValue) {
super.onTIMCallback(callbackValue);
_coreServices.callOnCallback(callbackValue);
}
@override
Widget timBuild(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider.value(
value: serviceLocator<TUIThemeViewModel>()),
],
builder: (BuildContext context, Widget? w) {
final theme = Provider.of<TUIThemeViewModel>(context).theme;
final value = TUIKitBuildValue(theme: theme);
return tuiBuild(context, value);
},
);
}
@required
Widget tuiBuild(BuildContext context, TUIKitBuildValue value) {
return Container();
}
}