Skip to content

Commit e63db85

Browse files
TheBuggedYRNHeshamMegid
authored andcommitted
[MOB-11886] Add Instabug.init API (#333)
1 parent 7665f1c commit e63db85

File tree

13 files changed

+64
-36
lines changed

13 files changed

+64
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Unreleased
22

3+
* Deprecates `Instabug.start` in favour of the new `Instabug.init` API.
34
* Adds `hungarian` and `finnish` locales support
45
* Adds missing mapping for `norwegian` and `slovak` locales on iOS
56

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,21 @@ flutter packages get
3838

3939
### Initializing Instabug
4040

41-
To start using Instabug, import it into your Flutter app.
41+
Initialize the SDK in your `main` function. This starts the SDK with the default behavior and sets it to be shown when the device is shaken.
4242

4343
```dart
4444
import 'package:instabug_flutter/instabug_flutter.dart';
45-
```
4645
47-
Initialize the SDK in `initState()`. This line enables the SDK with the default behavior and sets it to be shown when the device is shaken.
46+
void main() {
47+
WidgetsFlutterBinding.ensureInitialized();
4848
49-
```dart
50-
Instabug.start('APP_TOKEN', [InvocationEvent.shake]);
49+
Instabug.init(
50+
token: 'APP_TOKEN',
51+
invocationEvents: [InvocationEvent.shake],
52+
);
53+
54+
runApp(MyApp());
55+
}
5156
```
5257

5358
> :warning: If you're updating the SDK from versions prior to v11, please check our [migration guide](https://docs.instabug.com/docs/flutter-migration-guide).
@@ -58,19 +63,20 @@ Instabug automatically captures every crash of your app and sends relevant detai
5863

5964
⚠️ **Crashes will only be reported in release mode and not in debug mode.**
6065

66+
```dart
67+
void main() {
68+
WidgetsFlutterBinding.ensureInitialized();
6169
62-
Replace `void main() => runApp(MyApp());` with the following snippet:
70+
Instabug.init(
71+
token: 'APP_TOKEN',
72+
invocationEvents: [InvocationEvent.floatingButton],
73+
);
6374
64-
```dart
65-
void main() async {
6675
FlutterError.onError = (FlutterErrorDetails details) {
67-
Zone.current.handleUncaughtError(details.exception, details.stack);
76+
Zone.current.handleUncaughtError(details.exception, details.stack!);
6877
};
69-
runZonedGuarded<Future<void>>(() async {
70-
runApp(MyApp());
71-
}, (Object error, StackTrace stackTrace) {
72-
CrashReporting.reportCrash(error, stackTrace);
73-
});
78+
79+
runZonedGuarded(() => runApp(MyApp()), CrashReporting.reportCrash);
7480
}
7581
```
7682

android/src/main/java/com/instabug/flutter/modules/InstabugApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void setEnabled(@NonNull Boolean isEnabled) {
8484
}
8585
}
8686

87-
public void start(@NonNull String token, @NonNull List<String> invocationEvents) {
87+
public void init(@NonNull String token, @NonNull List<String> invocationEvents) {
8888
setCurrentPlatform();
8989

9090
InstabugInvocationEvent[] invocationEventsArray = new InstabugInvocationEvent[invocationEvents.size()];

android/src/test/java/com/instabug/flutter/InstabugApiTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void testStart() {
111111
when(mock.setInvocationEvents(any())).thenReturn(mock);
112112
});
113113

114-
api.start(token, invocationEvents);
114+
api.init(token, invocationEvents);
115115

116116
Instabug.Builder builder = mInstabugBuilder.constructed().get(0);
117117

example/ios/InstabugSampleTests/InstabugApiTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ - (void)testStart {
3939
NSArray<NSString *> *invocationEvents = @[@"InvocationEvent.floatingButton", @"InvocationEvent.screenshot"];
4040
FlutterError *error;
4141

42-
[self.api startToken:token invocationEvents:invocationEvents error:&error];
42+
[self.api initToken:token invocationEvents:invocationEvents error:&error];
4343

4444
OCMVerify([self.mInstabug setCurrentPlatform:IBGPlatformFlutter]);
4545

example/lib/main.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ import 'package:flutter/material.dart';
44
import 'package:instabug_flutter/instabug_flutter.dart';
55

66
void main() {
7+
WidgetsFlutterBinding.ensureInitialized();
8+
9+
Instabug.init(
10+
token: 'ed6f659591566da19b67857e1b9d40ab',
11+
invocationEvents: [InvocationEvent.floatingButton],
12+
);
13+
14+
Instabug.setWelcomeMessageMode(WelcomeMessageMode.disabled);
15+
716
FlutterError.onError = (FlutterErrorDetails details) {
817
Zone.current.handleUncaughtError(details.exception, details.stack!);
918
};
1019

1120
runZonedGuarded(() => runApp(MyApp()), CrashReporting.reportCrash);
12-
13-
Instabug.start(
14-
'ed6f659591566da19b67857e1b9d40ab', [InvocationEvent.floatingButton]);
15-
Instabug.setWelcomeMessageMode(WelcomeMessageMode.disabled);
1621
}
1722

1823
class MyApp extends StatelessWidget {

ios/Classes/Modules/InstabugApi.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ - (void)setEnabledIsEnabled:(NSNumber *)isEnabled error:(FlutterError *_Nullable
1818
Instabug.enabled = [isEnabled boolValue];
1919
}
2020

21-
- (void)startToken:(NSString *)token invocationEvents:(NSArray<NSString *> *)invocationEvents error:(FlutterError *_Nullable *_Nonnull)error {
21+
- (void)initToken:(NSString *)token invocationEvents:(NSArray<NSString *> *)invocationEvents error:(FlutterError *_Nullable *_Nonnull)error {
2222
SEL setPrivateApiSEL = NSSelectorFromString(@"setCurrentPlatform:");
2323
if ([[Instabug class] respondsToSelector:setPrivateApiSEL]) {
2424
NSInteger *platformID = IBGPlatformFlutter;

lib/src/modules/bug_reporting.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class BugReporting implements BugReportingFlutterApi {
5353

5454
/// @nodoc
5555
@internal
56-
static void init() {
56+
static void $setup() {
5757
BugReportingFlutterApi.setup(_instance);
5858
}
5959

@@ -121,7 +121,7 @@ class BugReporting implements BugReportingFlutterApi {
121121
}
122122

123123
/// Sets the events that invoke the feedback form.
124-
/// Default is set by `Instabug.startWithToken`.
124+
/// Default is set by [Instabug.init].
125125
/// [invocationEvents] invocationEvent List of events that invokes the
126126
static Future<void> setInvocationEvents(
127127
List<InvocationEvent>? invocationEvents,
@@ -166,7 +166,7 @@ class BugReporting implements BugReportingFlutterApi {
166166
}
167167

168168
/// Sets the invocation options.
169-
/// Default is set by `Instabug.startWithToken`.
169+
/// Default is set by [Instabug.init].
170170
/// [invocationOptions] List of invocation options
171171
static Future<void> setInvocationOptions(
172172
List<InvocationOption>? invocationOptions,

lib/src/modules/instabug.dart

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ class Instabug {
136136

137137
/// @nodoc
138138
@internal
139-
static void init() {
140-
BugReporting.init();
141-
Replies.init();
142-
Surveys.init();
139+
static void $setup() {
140+
BugReporting.$setup();
141+
Replies.$setup();
142+
Surveys.$setup();
143143
}
144144

145145
/// Enables or disables Instabug functionality.
@@ -155,12 +155,25 @@ class Instabug {
155155
/// it on your dashboard.
156156
/// The [invocationEvents] are the events that invoke
157157
/// the SDK's UI.
158+
static Future<void> init({
159+
required String token,
160+
required List<InvocationEvent> invocationEvents,
161+
}) async {
162+
$setup();
163+
return _host.init(token, invocationEvents.mapToString());
164+
}
165+
166+
@Deprecated(
167+
"Use [Instabug.init] instead.",
168+
)
158169
static Future<void> start(
159170
String token,
160171
List<InvocationEvent> invocationEvents,
161172
) async {
162-
init();
163-
return _host.start(token, invocationEvents.mapToString());
173+
return init(
174+
token: token,
175+
invocationEvents: invocationEvents,
176+
);
164177
}
165178

166179
/// Shows the welcome message in a specific mode.

lib/src/modules/replies.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Replies implements RepliesFlutterApi {
3333

3434
/// @nodoc
3535
@internal
36-
static void init() {
36+
static void $setup() {
3737
RepliesFlutterApi.setup(_instance);
3838
}
3939

0 commit comments

Comments
 (0)