Skip to content

Commit ac87fd5

Browse files
asamizHeshamMegid
authored andcommitted
[MOB-12516] Fix zone mismatch issue (#376)
* fix(initialization): fix zone mismatch issue in initialization code * fix(initilization): fix the PR comments
1 parent ceaf667 commit ac87fd5

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

README.md

+16-13
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ A Flutter plugin for [Instabug](https://instabug.com/).
2222

2323
### Installation
2424

25-
2625
1. Add Instabug to your `pubspec.yaml` file.
2726

2827
```yaml
@@ -65,18 +64,23 @@ Instabug automatically captures every crash of your app and sends relevant detai
6564

6665
```dart
6766
void main() {
68-
WidgetsFlutterBinding.ensureInitialized();
69-
70-
Instabug.init(
71-
token: 'APP_TOKEN',
72-
invocationEvents: [InvocationEvent.floatingButton],
67+
runZonedGuarded(
68+
() {
69+
WidgetsFlutterBinding.ensureInitialized();
70+
71+
Instabug.init(
72+
token: 'APP_TOKEN',
73+
invocationEvents: [InvocationEvent.shake],
74+
);
75+
76+
FlutterError.onError = (FlutterErrorDetails details) {
77+
Zone.current.handleUncaughtError(details.exception, details.stack!);
78+
};
79+
80+
runApp(MyApp());
81+
},
82+
CrashReporting.reportCrash,
7383
);
74-
75-
FlutterError.onError = (FlutterErrorDetails details) {
76-
Zone.current.handleUncaughtError(details.exception, details.stack!);
77-
};
78-
79-
runZonedGuarded(() => runApp(MyApp()), CrashReporting.reportCrash);
8084
}
8185
```
8286

@@ -90,7 +94,6 @@ Repro Steps list all of the actions an app user took before reporting a bug or c
9094
));
9195
```
9296

93-
9497
## Network Logging
9598
You can choose to attach all your network requests to the reports being sent to the dashboard. To enable the feature when using the `dart:io` package `HttpClient`, please refer to the [Instabug Dart IO Http Client](https://github.com/Instabug/instabug-dart-io-http-client) repository.
9699

example/lib/main.dart

+14-12
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ import 'package:flutter/material.dart';
44
import 'package:instabug_flutter/instabug_flutter.dart';
55

66
void main() {
7-
WidgetsFlutterBinding.ensureInitialized();
7+
runZonedGuarded(
8+
() {
9+
WidgetsFlutterBinding.ensureInitialized();
810

9-
Instabug.init(
10-
token: 'ed6f659591566da19b67857e1b9d40ab',
11-
invocationEvents: [InvocationEvent.floatingButton],
12-
debugLogsLevel: LogLevel.verbose,
13-
);
14-
15-
Instabug.setWelcomeMessageMode(WelcomeMessageMode.disabled);
11+
Instabug.init(
12+
token: 'ed6f659591566da19b67857e1b9d40ab',
13+
invocationEvents: [InvocationEvent.floatingButton],
14+
);
1615

17-
FlutterError.onError = (FlutterErrorDetails details) {
18-
Zone.current.handleUncaughtError(details.exception, details.stack!);
19-
};
16+
FlutterError.onError = (FlutterErrorDetails details) {
17+
Zone.current.handleUncaughtError(details.exception, details.stack!);
18+
};
2019

21-
runZonedGuarded(() => runApp(MyApp()), CrashReporting.reportCrash);
20+
runApp(MyApp());
21+
},
22+
CrashReporting.reportCrash,
23+
);
2224
}
2325

2426
class MyApp extends StatelessWidget {

0 commit comments

Comments
 (0)