Skip to content

Commit 1d6b8b1

Browse files
authored
Merge pull request #46 from appspector/develop
Release 0.7.0
2 parents 9d71d0f + a77212d commit 1d6b8b1

21 files changed

+119
-111
lines changed

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
java-version: '12.x'
1717
- uses: subosito/flutter-action@v1
1818
with:
19-
flutter-version: '1.22.4'
19+
flutter-version: '2.0.3'
2020
- run: flutter pub get
2121
- run: flutter pub publish -n
2222
- run: ./test_ios.sh

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
java-version: '12.x'
1919
- uses: subosito/flutter-action@v1
2020
with:
21-
flutter-version: '1.22.6'
21+
flutter-version: '2.0.3'
2222
- run: mkdir -p $FLUTTER_HOME/.pub-cache && echo $CREDENTIALS_JSON > $FLUTTER_HOME/.pub-cache/credentials.json
2323
- run: flutter pub get
2424
- run: flutter pub publish -f

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.7.0 31 Mar 2021
2+
* Support Flutter 2 and Dart null-safety
3+
* Fix issue with missing OnSessionUrlListener
4+
15
## 0.6.2 30 Mar 2021
26
* Add internal updates
37

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ API keys required for the SDK initialisation will be available on the Apps setti
4343
## Add AppSpector plugin to pubspec.yaml
4444
```yaml
4545
dependencies
46-
appspector: '0.6.2'
46+
appspector: '0.7.0'
4747
```
4848
4949
## Initialize AppSpector plugin

example/lib/http/app_http_client.dart

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import 'dart:convert';
23
import 'dart:io' show HttpClient, HttpClientRequest, HttpHeaders;
34

@@ -28,14 +29,14 @@ abstract class AppHttpClient {
2829
class FlutterHttpClient extends AppHttpClient {
2930
@override
3031
Future<int> executeDelete(String url) {
31-
return http.delete(url).then((response) {
32+
return http.delete(Uri.parse(url)).then((response) {
3233
return response.statusCode;
3334
});
3435
}
3536

3637
@override
3738
Future<int> executeGet(String url) {
38-
return http.get(url).then((response) {
39+
return http.get(Uri.parse(url)).then((response) {
3940
return response.statusCode;
4041
});
4142
}
@@ -44,15 +45,15 @@ class FlutterHttpClient extends AppHttpClient {
4445
Future<int> executeGetImage() {
4546
return http
4647
.get(
47-
"https://raw.githubusercontent.com/appspector/android-sdk/master/images/github-cover.png")
48+
Uri.parse("https://raw.githubusercontent.com/appspector/android-sdk/master/images/github-cover.png"))
4849
.then((response) {
4950
return response.statusCode;
5051
});
5152
}
5253

5354
@override
5455
Future<int> executeHead(String url) {
55-
return http.head(url).then((response) {
56+
return http.head(Uri.parse(url)).then((response) {
5657
return response.statusCode;
5758
});
5859
}
@@ -65,7 +66,7 @@ class FlutterHttpClient extends AppHttpClient {
6566
@override
6667
Future<int> executePatch(String url) async {
6768
final body = await rootBundle.loadString("assets/patch.json");
68-
return http.patch(url, body: body).then((response) {
69+
return http.patch(Uri.parse(url), body: body).then((response) {
6970
return response.statusCode;
7071
});
7172
}
@@ -81,15 +82,15 @@ class FlutterHttpClient extends AppHttpClient {
8182
"fcmToken": "svsdfvdsvf"
8283
}""";
8384
final headers = {"Content-Type": "application/json; charset=utf-8"};
84-
return http.post(url, headers: headers, body: data).then((response) {
85+
return http.post(Uri.parse(url), headers: headers, body: data).then((response) {
8586
return response.statusCode;
8687
});
8788
}
8889

8990
@override
9091
Future<int> executePut(String url) async {
9192
final body = await rootBundle.loadString("assets/put.json");
92-
return http.put(url, body: body).then((response) {
93+
return http.put(Uri.parse(url), body: body).then((response) {
9394
return response.statusCode;
9495
});
9596
}
@@ -186,28 +187,28 @@ class DioHttpClient extends AppHttpClient {
186187
@override
187188
Future<int> executeDelete(String url) {
188189
return dio.delete(url).then((response) {
189-
return response.statusCode;
190+
return response.statusCode ?? 0;
190191
});
191192
}
192193

193194
@override
194195
Future<int> executeGet(String url) {
195196
return dio.get(url).then((response) {
196-
return response.statusCode;
197+
return response.statusCode ?? 0;
197198
});
198199
}
199200

200201
@override
201202
Future<int> executeGetImage() {
202203
return dio.get("https://raw.githubusercontent.com/appspector/android-sdk/master/images/github-cover.png").then((response) {
203-
return response.statusCode;
204+
return response.statusCode ?? 0;
204205
});
205206
}
206207

207208
@override
208209
Future<int> executeHead(String url) {
209210
return dio.head(url).then((response) {
210-
return response.statusCode;
211+
return response.statusCode ?? 0;
211212
});
212213
}
213214

@@ -219,7 +220,7 @@ class DioHttpClient extends AppHttpClient {
219220
@override
220221
Future<int> executePatch(String url) {
221222
return dio.patch(url).then((response) {
222-
return response.statusCode;
223+
return response.statusCode ?? 0;
223224
});
224225
}
225226

@@ -233,14 +234,14 @@ class DioHttpClient extends AppHttpClient {
233234
'fcmToken': 'svsdfvdsvf'
234235
};
235236
return dio.post(url, data: data).then((response) {
236-
return response.statusCode;
237+
return response.statusCode ?? 0;
237238
});
238239
}
239240

240241
@override
241242
Future<int> executePut(String url) {
242243
return dio.put(url).then((response) {
243-
return response.statusCode;
244+
return response.statusCode ?? 0;
244245
});
245246
}
246247

example/lib/http_page.dart

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:dio/dio.dart';
12
import 'package:flutter/material.dart';
23

34
import 'app_drawer.dart';
@@ -50,9 +51,9 @@ class HttpMonitorPageState extends State<HttpMonitorPage> {
5051
];
5152

5253
int _selectedClient = _CLIENT_HTTP_LIB;
53-
int _statusCode;
54-
String _error;
55-
int _requestDuration;
54+
int? _statusCode;
55+
String? _error;
56+
int? _requestDuration;
5657

5758
@override
5859
Widget build(BuildContext context) {
@@ -120,14 +121,10 @@ class HttpMonitorPageState extends State<HttpMonitorPage> {
120121
child: Text(item.title),
121122
onPressed: () {
122123
Stopwatch stopwatch = Stopwatch()..start();
123-
try {
124-
item.action(_provideClient(), _url).then((responseCode) {
125-
_onHttpResponse(
126-
responseCode, stopwatch.elapsedMilliseconds);
127-
});
128-
} catch(e) {
129-
_onHttpError(e);
130-
}
124+
item.action(_provideClient(), _url).then((responseCode) {
125+
_onHttpResponse(responseCode, stopwatch.elapsedMilliseconds);
126+
}).onError(
127+
(error, stackTrace) => _onHttpError(error as Exception, stopwatch.elapsedMilliseconds));
131128
}));
132129
}).toList();
133130
}
@@ -149,11 +146,11 @@ class HttpMonitorPageState extends State<HttpMonitorPage> {
149146
});
150147
}
151148

152-
_onHttpError(Exception e) {
149+
_onHttpError(Exception e, int requestDuration) {
153150
setState(() {
154151
_statusCode = null;
155-
_requestDuration = null;
156-
_error = e.toString();
152+
_requestDuration = requestDuration;
153+
_error = e is DioError ? e.message + " (" + requestDuration.toString() + " ms)" : e.toString();
157154
});
158155
}
159156

@@ -170,9 +167,9 @@ class HttpMonitorPageState extends State<HttpMonitorPage> {
170167
return [TextSpan(text: "Click any button")];
171168
}
172169

173-
_onClientSelectChanged(int newValue) {
170+
_onClientSelectChanged(int? newValue) {
174171
setState(() {
175-
_selectedClient = newValue;
172+
_selectedClient = newValue ?? _CLIENT_HTTP_LIB;
176173
});
177174
}
178175
}

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void runAppSpector(DataObservable<String> sessionObserver) {
4545
];
4646

4747
AppSpectorPlugin.run(config);
48-
AppSpectorPlugin.shared()?.sessionUrlListener =
48+
AppSpectorPlugin.shared().sessionUrlListener =
4949
(sessionUrl) => {sessionObserver.setValue(sessionUrl)};
5050
}
5151

example/lib/main_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'utils.dart';
99
class MyHomePage extends StatefulWidget {
1010
final DataObservable<String> _sessionUrlObserver;
1111

12-
MyHomePage(this._sessionUrlObserver, {Key key, this.title}) : super(key: key);
12+
MyHomePage(this._sessionUrlObserver, {Key? key, required this.title}) : super(key: key);
1313

1414
// This widget is the home page of your application. It is stateful, meaning
1515
// that it has a State object (defined below) that contains fields that affect
@@ -32,7 +32,7 @@ class _MyHomePageState extends State<MyHomePage> {
3232
int _counter = 0;
3333

3434
bool isSdkRunning = true;
35-
String _sessionUrl;
35+
late String _sessionUrl;
3636

3737
_MyHomePageState(DataObservable<String> sessionUrlObserver) {
3838
sessionUrlObserver.observer = (sessionUrl) => {

example/lib/sqlite/storage.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import 'dart:async';
23
import 'package:flutter/foundation.dart';
34
import 'package:sqflite/sqflite.dart';
@@ -10,24 +11,23 @@ abstract class RecordStorage {
1011
}
1112

1213
class RecordStorageImpl implements RecordStorage {
13-
static Database _db;
14+
static Database? _db;
1415
static const _tableName = "records";
1516
static const _columnId = "id";
1617
static const _columnName = "name";
1718
static const _columnAddress = "address";
1819
static const _columnPhone = "phone";
1920

2021
Future<Database> get db async {
21-
if (_db != null) return _db;
22-
_db = await initDb();
23-
return _db;
22+
return _db ?? await initDb();
2423
}
2524

2625
//Creating a database with name test.db in your directory
2726
initDb() async {
2827
var dbPath = await getDatabasesPath() + "/test.db";
29-
var theDb = await openDatabase(dbPath, version: 1, onCreate: _onCreate);
30-
return theDb;
28+
var db = await openDatabase(dbPath, version: 1, onCreate: _onCreate);
29+
_db = db;
30+
return db;
3131
}
3232

3333
// Creating a table name Employee with fields

example/lib/utils.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
class DataObservable<T> {
22

3-
T _value;
3+
T? _value;
44

5-
Function(T) observer;
5+
Function(T)? observer;
66

77
void setValue(T value) {
88
this._value = value;
99
if (observer != null) {
10-
observer(value);
10+
observer!(value);
1111
}
1212
}
1313

14-
T getValue() => _value;
14+
T? getValue() => _value;
1515

1616
}

0 commit comments

Comments
 (0)