feat(sample-app): add sentry
Signed-off-by: xsahil03x <xdsahil@gmail.com>
This commit is contained in:
@@ -40,7 +40,7 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||||
applicationId "com.example.example"
|
applicationId "com.example.example"
|
||||||
minSdkVersion 21
|
minSdkVersion 22
|
||||||
targetSdkVersion 30
|
targetSdkVersion 30
|
||||||
versionCode flutterVersionCode.toInteger()
|
versionCode flutterVersionCode.toInteger()
|
||||||
versionName flutterVersionName
|
versionName flutterVersionName
|
||||||
|
|||||||
@@ -294,10 +294,7 @@ class _AdvancedOptionsPageState extends State<AdvancedOptionsPage> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final client = StreamChatClient(
|
final client = buildStreamChatClient(apiKey);
|
||||||
apiKey,
|
|
||||||
logLevel: Level.INFO,
|
|
||||||
)..chatPersistenceClient = chatPersistentClient;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.connectUser(
|
await client.connectUser(
|
||||||
|
|||||||
@@ -4,17 +4,16 @@ import 'package:example/choose_user_page.dart';
|
|||||||
import 'package:example/home_page.dart';
|
import 'package:example/home_page.dart';
|
||||||
import 'package:example/localizations.dart';
|
import 'package:example/localizations.dart';
|
||||||
import 'package:example/splash_screen.dart';
|
import 'package:example/splash_screen.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/scheduler.dart';
|
import 'package:flutter/scheduler.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
|
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||||
import 'package:stream_chat_localizations/stream_chat_localizations.dart';
|
import 'package:stream_chat_localizations/stream_chat_localizations.dart';
|
||||||
import 'package:stream_chat_persistence/stream_chat_persistence.dart';
|
import 'package:stream_chat_persistence/stream_chat_persistence.dart';
|
||||||
import 'package:streaming_shared_preferences/streaming_shared_preferences.dart';
|
import 'package:streaming_shared_preferences/streaming_shared_preferences.dart';
|
||||||
|
|
||||||
import 'app_config.dart';
|
|
||||||
import 'routes/app_routes.dart';
|
import 'routes/app_routes.dart';
|
||||||
import 'routes/routes.dart';
|
import 'routes/routes.dart';
|
||||||
|
|
||||||
@@ -23,8 +22,65 @@ final chatPersistentClient = StreamChatPersistenceClient(
|
|||||||
connectionMode: ConnectionMode.regular,
|
connectionMode: ConnectionMode.regular,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
void sampleAppLogHandler(LogRecord record) async {
|
||||||
|
if (kDebugMode) StreamChatClient.defaultLogHandler(record);
|
||||||
|
|
||||||
|
// report errors to sentry
|
||||||
|
if (record.error != null || record.stackTrace != null) {
|
||||||
|
await Sentry.captureException(
|
||||||
|
record.error,
|
||||||
|
stackTrace: record.stackTrace,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StreamChatClient buildStreamChatClient(
|
||||||
|
String apiKey, {
|
||||||
|
Level logLevel = Level.SEVERE,
|
||||||
|
}) {
|
||||||
|
return StreamChatClient(
|
||||||
|
apiKey,
|
||||||
|
logLevel: logLevel,
|
||||||
|
logHandlerFunction: sampleAppLogHandler,
|
||||||
|
)..chatPersistenceClient = chatPersistentClient;
|
||||||
|
}
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
runApp(MyApp());
|
const sentryDsn =
|
||||||
|
'https://6381ef88de4140db8f5e25ab37e0f08c@o1213503.ingest.sentry.io/6352870';
|
||||||
|
|
||||||
|
/// Captures errors reported by the Flutter framework.
|
||||||
|
FlutterError.onError = (FlutterErrorDetails details) {
|
||||||
|
if (kDebugMode) {
|
||||||
|
// In development mode, simply print to console.
|
||||||
|
FlutterError.dumpErrorToConsole(details);
|
||||||
|
} else {
|
||||||
|
// In production mode, report to the application zone to report to sentry.
|
||||||
|
Zone.current.handleUncaughtError(details.exception, details.stack!);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Future<void> _reportError(dynamic error, StackTrace stackTrace) async {
|
||||||
|
// Print the exception to the console.
|
||||||
|
if (kDebugMode) {
|
||||||
|
// Print the full stacktrace in debug mode.
|
||||||
|
print(stackTrace);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
// Send the Exception and Stacktrace to sentry in Production mode.
|
||||||
|
await Sentry.captureException(error, stackTrace: stackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runZonedGuarded(
|
||||||
|
() async {
|
||||||
|
await SentryFlutter.init(
|
||||||
|
(options) => options.dsn = sentryDsn,
|
||||||
|
);
|
||||||
|
runApp(MyApp());
|
||||||
|
},
|
||||||
|
_reportError,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatefulWidget {
|
class MyApp extends StatefulWidget {
|
||||||
@@ -46,10 +102,7 @@ class _MyAppState extends State<MyApp>
|
|||||||
token = await secureStorage.read(key: kStreamToken);
|
token = await secureStorage.read(key: kStreamToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
final client = StreamChatClient(
|
final client = buildStreamChatClient(apiKey ?? kStreamApiKey);
|
||||||
apiKey ?? kDefaultStreamApiKey,
|
|
||||||
logLevel: Level.SEVERE,
|
|
||||||
)..chatPersistenceClient = chatPersistentClient;
|
|
||||||
|
|
||||||
if (userId != null && token != null) {
|
if (userId != null && token != null) {
|
||||||
await client.connectUser(
|
await client.connectUser(
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ dependencies:
|
|||||||
streaming_shared_preferences: ^2.0.0
|
streaming_shared_preferences: ^2.0.0
|
||||||
lottie: ^1.2.1
|
lottie: ^1.2.1
|
||||||
collection: ^1.15.0
|
collection: ^1.15.0
|
||||||
|
sentry_flutter: ^6.5.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_launcher_icons: ^0.9.2
|
flutter_launcher_icons: ^0.9.2
|
||||||
@@ -40,10 +41,7 @@ dev_dependencies:
|
|||||||
|
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
stream_chat:
|
stream_chat:
|
||||||
git:
|
path: ../../../stream-chat-flutter/packages/stream_chat
|
||||||
url: https://github.com/GetStream/stream-chat-flutter.git
|
|
||||||
ref: develop
|
|
||||||
path: packages/stream_chat
|
|
||||||
stream_chat_flutter_core:
|
stream_chat_flutter_core:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/GetStream/stream-chat-flutter.git
|
url: https://github.com/GetStream/stream-chat-flutter.git
|
||||||
|
|||||||
Reference in New Issue
Block a user