Skip to content

Commit 6b0af45

Browse files
authored
📝 Dividing into modules (#49)
Divides the library into modules to be on par with native sides
1 parent 589dd72 commit 6b0af45

File tree

5 files changed

+115
-89
lines changed

5 files changed

+115
-89
lines changed

example/lib/main.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import 'dart:async';
22
import 'dart:io' show Platform;
33
import 'package:flutter/material.dart';
44
import 'package:flutter/services.dart';
5-
import 'package:instabug_flutter/instabug_flutter.dart';
5+
import 'package:instabug_flutter/Instabug.dart';
6+
import 'package:instabug_flutter/BugReporting.dart';
7+
import 'package:instabug_flutter/InstabugLog.dart';
68

79
void main() => runApp(MyApp());
810

@@ -30,12 +32,12 @@ class _MyAppState extends State<MyApp> {
3032
}
3133
Instabug.showWelcomeMessageWithMode(WelcomeMessageMode.beta);
3234
Instabug.identifyUserWithEmail('[email protected]', 'Aly Ezz');
33-
Instabug.logInfo('Test Log Info Message from Flutter!');
34-
Instabug.logDebug('Test Debug Message from Flutter!');
35-
Instabug.logVerbose('Test Verbose Message from Flutter!');
36-
Instabug.clearAllLogs();
37-
Instabug.logError('Test Error Message from Flutter!');
38-
Instabug.logWarn('Test Warn Message from Flutter!');
35+
InstabugLog.logInfo('Test Log Info Message from Flutter!');
36+
InstabugLog.logDebug('Test Debug Message from Flutter!');
37+
InstabugLog.logVerbose('Test Verbose Message from Flutter!');
38+
InstabugLog.clearAllLogs();
39+
InstabugLog.logError('Test Error Message from Flutter!');
40+
InstabugLog.logWarn('Test Warn Message from Flutter!');
3941
Instabug.logOut();
4042
Instabug.setLocale(Locale.German);
4143
Instabug.setColorTheme(ColorTheme.dark);
@@ -73,7 +75,7 @@ class _MyAppState extends State<MyApp> {
7375
}
7476

7577
void invokeWithMode() {
76-
Instabug.invokeWithMode(InvocationMode.BUG, [InvocationOption.EMAIL_FIELD_HIDDEN]);
78+
BugReporting.invokeWithMode(InvocationMode.BUG, [InvocationOption.EMAIL_FIELD_HIDDEN]);
7779
}
7880

7981
void getTags() async {

lib/BugReporting.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import 'dart:async';
2+
import 'package:flutter/services.dart';
3+
import 'package:instabug_flutter/Instabug.dart';
4+
5+
enum InvocationOption {
6+
COMMENT_FIELD_REQUIRED,
7+
DISABLE_POST_SENDING_DIALOG,
8+
EMAIL_FIELD_HIDDEN,
9+
EMAIL_FIELD_OPTIONAL
10+
}
11+
12+
class BugReporting {
13+
static const MethodChannel _channel = MethodChannel('instabug_flutter');
14+
15+
static Future<String> get platformVersion async {
16+
final String version = await _channel.invokeMethod('getPlatformVersion');
17+
return version;
18+
}
19+
/// invoke sdk manually with desire invocation mode
20+
/// [invocationMode] the invocation mode
21+
/// [invocationOptions] the array of invocation options
22+
static void invokeWithMode(InvocationMode invocationMode, [List<InvocationOption> invocationOptions]) async {
23+
List<String> invocationOptionsStrings = <String>[];
24+
if (invocationOptions != null) {
25+
invocationOptions.forEach((e) {
26+
invocationOptionsStrings.add(e.toString());
27+
});
28+
}
29+
final List<dynamic> params = <dynamic>[invocationMode.toString(), invocationOptionsStrings];
30+
await _channel.invokeMethod<Object>('invokeWithMode:options:',params);
31+
}
32+
}

lib/instabug_flutter.dart renamed to lib/Instabug.dart

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ enum InvocationMode {
4343
REPLIES
4444
}
4545

46-
enum InvocationOption {
47-
COMMENT_FIELD_REQUIRED,
48-
DISABLE_POST_SENDING_DIALOG,
49-
EMAIL_FIELD_HIDDEN,
50-
EMAIL_FIELD_OPTIONAL
51-
}
52-
53-
5446
enum ColorTheme { dark, light }
5547

5648
enum IBGCustomTextPlaceHolderKey {
@@ -143,56 +135,6 @@ class Instabug {
143135
final List<dynamic> params = <dynamic>[locale.toString()];
144136
await _channel.invokeMethod<Object>('setLocale:', params);
145137
}
146-
147-
/// Appends a log [message] to Instabug internal log
148-
/// These logs are then sent along the next uploaded report.
149-
/// All log messages are timestamped
150-
/// Note: logs passed to this method are NOT printed to console
151-
static void logVerbose(String message) async {
152-
final List<dynamic> params = <dynamic>[message];
153-
await _channel.invokeMethod<Object>('logVerbose:', params);
154-
}
155-
156-
/// Appends a log [message] to Instabug internal log
157-
/// These logs are then sent along the next uploaded report.
158-
/// All log messages are timestamped
159-
/// Note: logs passed to this method are NOT printed to console
160-
static void logDebug(String message) async {
161-
final List<dynamic> params = <dynamic>[message];
162-
await _channel.invokeMethod<Object>('logDebug:', params);
163-
}
164-
165-
/// Appends a log [message] to Instabug internal log
166-
/// These logs are then sent along the next uploaded report.
167-
/// All log messages are timestamped
168-
/// Note: logs passed to this method are NOT printed to console
169-
static void logInfo(String message) async {
170-
final List<dynamic> params = <dynamic>[message];
171-
await _channel.invokeMethod<Object>('logInfo:', params);
172-
}
173-
174-
/// Clears Instabug internal log
175-
static void clearAllLogs() async {
176-
await _channel.invokeMethod<Object>('clearAllLogs');
177-
}
178-
179-
/// Appends a log [message] to Instabug internal log
180-
/// These logs are then sent along the next uploaded report.
181-
/// All log messages are timestamped
182-
/// Note: logs passed to this method are NOT printed to console
183-
static void logError(String message) async {
184-
final List<dynamic> params = <dynamic>[message];
185-
await _channel.invokeMethod<Object>('logError:', params);
186-
}
187-
188-
/// Appends a log [message] to Instabug internal log
189-
/// These logs are then sent along the next uploaded report.
190-
/// All log messages are timestamped
191-
/// Note: logs passed to this method are NOT printed to console
192-
static void logWarn(String message) async {
193-
final List<dynamic> params = <dynamic>[message];
194-
await _channel.invokeMethod<Object>('logWarn:', params);
195-
}
196138

197139
/// Sets the color theme of the SDK's whole UI to the [colorTheme] given.
198140
/// It should be of type [ColorTheme].
@@ -248,21 +190,6 @@ class Instabug {
248190
await _channel.invokeMethod<Object>('show');
249191
}
250192

251-
252-
/// invoke sdk manually with desire invocation mode
253-
/// [invocationMode] the invocation mode
254-
/// [invocationOptions] the array of invocation options
255-
static void invokeWithMode(InvocationMode invocationMode, [List<InvocationOption> invocationOptions]) async {
256-
List<String> invocationOptionsStrings = <String>[];
257-
if (invocationOptions != null) {
258-
invocationOptions.forEach((e) {
259-
invocationOptionsStrings.add(e.toString());
260-
});
261-
}
262-
final List<dynamic> params = <dynamic>[invocationMode.toString(), invocationOptionsStrings];
263-
await _channel.invokeMethod<Object>('invokeWithMode:options:',params);
264-
}
265-
266193
/// Logs a user event with [name] that happens through the lifecycle of the application.
267194
/// Logged user events are going to be sent with each report, as well as at the end of a session.
268195
static void logUserEventWithName(String name) async {
@@ -279,3 +206,4 @@ class Instabug {
279206
}
280207

281208

209+

lib/InstabugLog.dart

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import 'dart:async';
2+
import 'package:flutter/services.dart';
3+
4+
class InstabugLog {
5+
static const MethodChannel _channel = MethodChannel('instabug_flutter');
6+
7+
static Future<String> get platformVersion async {
8+
final String version = await _channel.invokeMethod('getPlatformVersion');
9+
return version;
10+
}
11+
12+
/// Appends a log [message] to Instabug internal log
13+
/// These logs are then sent along the next uploaded report.
14+
/// All log messages are timestamped
15+
/// Note: logs passed to this method are NOT printed to console
16+
static void logError(String message) async {
17+
final List<dynamic> params = <dynamic>[message];
18+
await _channel.invokeMethod<Object>('logError:', params);
19+
}
20+
21+
/// Appends a log [message] to Instabug internal log
22+
/// These logs are then sent along the next uploaded report.
23+
/// All log messages are timestamped
24+
/// Note: logs passed to this method are NOT printed to console
25+
static void logWarn(String message) async {
26+
final List<dynamic> params = <dynamic>[message];
27+
await _channel.invokeMethod<Object>('logWarn:', params);
28+
}
29+
30+
/// Appends a log [message] to Instabug internal log
31+
/// These logs are then sent along the next uploaded report.
32+
/// All log messages are timestamped
33+
/// Note: logs passed to this method are NOT printed to console
34+
static void logVerbose(String message) async {
35+
final List<dynamic> params = <dynamic>[message];
36+
await _channel.invokeMethod<Object>('logVerbose:', params);
37+
}
38+
39+
/// Appends a log [message] to Instabug internal log
40+
/// These logs are then sent along the next uploaded report.
41+
/// All log messages are timestamped
42+
/// Note: logs passed to this method are NOT printed to console
43+
static void logDebug(String message) async {
44+
final List<dynamic> params = <dynamic>[message];
45+
await _channel.invokeMethod<Object>('logDebug:', params);
46+
}
47+
48+
/// Appends a log [message] to Instabug internal log
49+
/// These logs are then sent along the next uploaded report.
50+
/// All log messages are timestamped
51+
/// Note: logs passed to this method are NOT printed to console
52+
static void logInfo(String message) async {
53+
final List<dynamic> params = <dynamic>[message];
54+
await _channel.invokeMethod<Object>('logInfo:', params);
55+
}
56+
57+
58+
/// Clears Instabug internal log
59+
static void clearAllLogs() async {
60+
await _channel.invokeMethod<Object>('clearAllLogs');
61+
}
62+
}

test/instabug_flutter_test.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'dart:io';
22

3-
import 'package:instabug_flutter/instabug_flutter.dart';
3+
import 'package:instabug_flutter/Instabug.dart';
4+
import 'package:instabug_flutter/BugReporting.dart';
5+
import 'package:instabug_flutter/InstabugLog.dart';
46
import 'package:flutter/services.dart';
57
import 'package:flutter_test/flutter_test.dart';
68

@@ -96,7 +98,7 @@ test('startWithToken:invocationEvents: Test', () async {
9698

9799

98100
test('logVerbose: Test', () async {
99-
Instabug.logVerbose(message);
101+
InstabugLog.logVerbose(message);
100102
final List<dynamic> args = <dynamic>[message];
101103
expect(log, <Matcher>[
102104
isMethodCall('logVerbose:',
@@ -106,7 +108,7 @@ test('startWithToken:invocationEvents: Test', () async {
106108
});
107109

108110
test('logDebug: Test', () async {
109-
Instabug.logDebug(message);
111+
InstabugLog.logDebug(message);
110112
final List<dynamic> args = <dynamic>[message];
111113
expect(log, <Matcher>[
112114
isMethodCall('logDebug:',
@@ -116,7 +118,7 @@ test('startWithToken:invocationEvents: Test', () async {
116118
});
117119

118120
test('logInfo: Test', () async {
119-
Instabug.logInfo(message);
121+
InstabugLog.logInfo(message);
120122
final List<dynamic> args = <dynamic>[message];
121123
expect(log, <Matcher>[
122124
isMethodCall('logInfo:',
@@ -126,7 +128,7 @@ test('startWithToken:invocationEvents: Test', () async {
126128
});
127129

128130
test('clearAllLogs: Test', () async {
129-
Instabug.clearAllLogs();
131+
InstabugLog.clearAllLogs();
130132
expect(log, <Matcher>[
131133
isMethodCall('clearAllLogs',
132134
arguments: null
@@ -135,7 +137,7 @@ test('startWithToken:invocationEvents: Test', () async {
135137
});
136138

137139
test('logError: Test', () async {
138-
Instabug.logError(message);
140+
InstabugLog.logError(message);
139141
final List<dynamic> args = <dynamic>[message];
140142
expect(log, <Matcher>[
141143
isMethodCall('logError:',
@@ -145,7 +147,7 @@ test('startWithToken:invocationEvents: Test', () async {
145147
});
146148

147149
test('logWarn: Test', () async {
148-
Instabug.logWarn(message);
150+
InstabugLog.logWarn(message);
149151
final List<dynamic> args = <dynamic>[message];
150152
expect(log, <Matcher>[
151153
isMethodCall('logWarn:',
@@ -250,7 +252,7 @@ test('startWithToken:invocationEvents: Test', () async {
250252

251253

252254
test('invokeWithMode:options: Test', () async {
253-
Instabug.invokeWithMode(InvocationMode.BUG, [InvocationOption.COMMENT_FIELD_REQUIRED]);
255+
BugReporting.invokeWithMode(InvocationMode.BUG, [InvocationOption.COMMENT_FIELD_REQUIRED]);
254256
final List<dynamic> args = <dynamic>[InvocationMode.BUG.toString(), <String>[InvocationOption.COMMENT_FIELD_REQUIRED.toString()]];
255257
expect(log, <Matcher>[
256258
isMethodCall('invokeWithMode:options:',

0 commit comments

Comments
 (0)