Skip to content

Commit

Permalink
[example] Log errors to the logSink (#1864)
Browse files Browse the repository at this point in the history
Add global error handling to log errors to the `logSink`, which helps
internal testing.
  • Loading branch information
littleGnAl authored Jun 24, 2024
1 parent 98764c1 commit 79bf997
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io';

import 'package:agora_rtc_engine_example/components/android_foreground_service_widget.dart';
Expand All @@ -11,7 +12,24 @@ import 'examples/basic/index.dart';
import 'config/agora.config.dart' as config;
import 'components/log_sink.dart';

void main() => runApp(const MyApp());
void main() {
FlutterError.onError = (details) {
FlutterError.presentError(details);
logSink.log(details.toString());
};

// TODO(littlegnal): The newer version of Flutter SDK doc shows use of the
// `PlatformDispatcher.instance.onError` but not `runZonedGuarded` to
// handle "Errors not caught by Flutter",
// see: https://docs.flutter.dev/testing/errors#handling-all-types-of-errors,
// follow the Flutter SDK doc after we can bump the mini supported Flutter SDK (currently 2.10.x)
// to the newer version of Flutter SDK.
runZonedGuarded(() {
runApp(const MyApp());
}, (error, stackTrace) {
logSink.log(error.toString());
});
}

/// This widget is the root of your application.
class MyApp extends StatefulWidget {
Expand Down

0 comments on commit 79bf997

Please sign in to comment.