Skip to content

Commit e3e339a

Browse files
Use PlatformManager with startWithToken
1 parent 6db04e6 commit e3e339a

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
.pub/
3131
pubspec.lock
3232
build/
33+
coverage/
3334

3435
# Android related
3536
**/android/**/gradle-wrapper.jar

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
## master
22

33
* Change all `void ... async` methods to `Future<void> ... async` so that callers can use `await`.
4+
* Fixes a crash when Instabug.start API is called on Android.
45

56
## v9.1.9 (2021-05-11)
67

78
* Adds support for overriding the replies notification string values through `repliesNotificationTeamName`, `repliesNotificationReplyButton`, `repliesNotificationDismissButton`
89
* Removes the use of `android:requestLegacyExternalStorage` attribute on Android
10+
911
## v9.1.8 (2021-02-17)
1012

1113
* Fixes an issue with iOS invocation events causing the welcome message not to show.

lib/Instabug.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:typed_data';
66
import 'dart:ui';
77

88
import 'package:flutter/services.dart';
9+
import 'package:instabug_flutter/utils/platform_manager.dart';
910

1011
enum InvocationEvent {
1112
shake,
@@ -102,7 +103,7 @@ class Instabug {
102103
/// the SDK's UI.
103104
static Future<void> start(
104105
String token, List<InvocationEvent> invocationEvents) async {
105-
if (Platform.isIOS) {
106+
if (PlatformManager.instance.isIOS()) {
106107
final List<String> invocationEventsStrings =
107108
invocationEvents.map((e) => e.toString()).toList(growable: false);
108109
final List<dynamic> params = <dynamic>[token, invocationEventsStrings];

test/instabug_flutter_test.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,16 @@ import 'package:instabug_flutter/Replies.dart';
1616
import 'package:instabug_flutter/Surveys.dart';
1717
import 'package:instabug_flutter/models/crash_data.dart';
1818
import 'package:instabug_flutter/models/exception_data.dart';
19+
import 'package:instabug_flutter/utils/platform_manager.dart';
20+
import 'package:mockito/annotations.dart';
21+
import 'package:mockito/mockito.dart';
1922
import 'package:stack_trace/stack_trace.dart';
2023

24+
import 'instabug_flutter_test.mocks.dart';
25+
26+
@GenerateMocks([
27+
PlatformManager,
28+
])
2129
void main() {
2230
WidgetsFlutterBinding.ensureInitialized();
2331
final List<MethodCall> log = <MethodCall>[];
@@ -32,6 +40,7 @@ void main() {
3240
const Map<String, String> userAttributePair = <String, String>{
3341
'gender': 'female'
3442
};
43+
late MockPlatformManager mockPlatform;
3544

3645
setUpAll(() async {
3746
const MethodChannel('instabug_flutter')
@@ -50,11 +59,19 @@ void main() {
5059
});
5160
});
5261

62+
setUp(() {
63+
mockPlatform = MockPlatformManager();
64+
PlatformManager.setPlatformInstance(mockPlatform);
65+
});
66+
5367
tearDown(() async {
5468
log.clear();
5569
});
5670

57-
test('startWithToken:invocationEvents: Test', () async {
71+
test('startWithToken:invocationEvents: should be called on iOS',
72+
() async {
73+
when(mockPlatform.isIOS()).thenAnswer((_) => true);
74+
5875
Instabug.start(appToken, invocationEvents);
5976
final List<dynamic> args = <dynamic>[
6077
appToken,

0 commit comments

Comments
 (0)