Skip to content
This repository was archived by the owner on Feb 13, 2023. It is now read-only.

Commit 4326d01

Browse files
committed
Refactor examples for CI
1 parent d01309b commit 4326d01

File tree

95 files changed

+184
-37
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+184
-37
lines changed

.github/workflows/example-app.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Example App
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop
8+
pull_request:
9+
branches:
10+
- main
11+
- develop
12+
13+
jobs:
14+
analyze:
15+
name: Analyze
16+
runs-on: ubuntu-latest
17+
defaults:
18+
run:
19+
working-directory: example_flutter_app
20+
steps:
21+
- uses: actions/checkout@v2
22+
- uses: subosito/flutter-action@v1
23+
with:
24+
channel: stable
25+
- run: flutter pub get
26+
- run: flutter analyze
27+
28+
format:
29+
name: Check formatting
30+
runs-on: ubuntu-latest
31+
defaults:
32+
run:
33+
working-directory: example_flutter_app
34+
steps:
35+
- uses: actions/checkout@v2
36+
- uses: subosito/flutter-action@v1
37+
with:
38+
channel: stable
39+
- run: flutter format --set-exit-if-changed .
40+
41+
build-android:
42+
name: Build Android
43+
runs-on: ubuntu-latest
44+
defaults:
45+
run:
46+
working-directory: example_flutter_app
47+
steps:
48+
- uses: actions/checkout@v2
49+
- uses: subosito/flutter-action@v1
50+
with:
51+
channel: stable
52+
- run: flutter pub get
53+
- run: flutter build apk

.github/workflows/example.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Example
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop
8+
pull_request:
9+
branches:
10+
- main
11+
- develop
12+
13+
jobs:
14+
analyze:
15+
name: Analyze
16+
runs-on: ubuntu-latest
17+
defaults:
18+
run:
19+
working-directory: example
20+
steps:
21+
- uses: actions/checkout@v2
22+
- uses: dart-lang/setup-dart@v1
23+
with:
24+
sdk: stable
25+
- run: pub get
26+
- run: dart analyze
27+
28+
format:
29+
name: Check formatting
30+
runs-on: ubuntu-latest
31+
defaults:
32+
run:
33+
working-directory: example
34+
steps:
35+
- uses: actions/checkout@v2
36+
- uses: dart-lang/setup-dart@v1
37+
with:
38+
sdk: stable
39+
- run: dart format --set-exit-if-changed .
40+
41+
tests:
42+
name: Unit tests
43+
runs-on: ubuntu-latest
44+
defaults:
45+
run:
46+
working-directory: example
47+
steps:
48+
- uses: actions/checkout@v2
49+
- uses: dart-lang/setup-dart@v1
50+
with:
51+
sdk: stable
52+
- run: pub get
53+
- run: dart test
54+
- name: Upload test report
55+
uses: actions/upload-artifact@v2
56+
if: always()
57+
with:
58+
name: test-results
59+
path: dio/build/reports/test-results.json

.github/workflows/test-report.yml

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
workflow_run:
55
workflows:
66
- Integration
7+
- Example
8+
- Example App
79
types:
810
- completed
911

File renamed without changes.
File renamed without changes.
File renamed without changes.

example/cookie_mgr.dart renamed to example/lib/cookie_mgr.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import 'package:cookie_jar/cookie_jar.dart';
12
import 'package:dio/dio.dart';
23
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
3-
import 'package:cookie_jar/cookie_jar.dart';
44

55
void main() async {
66
var dio = Dio();
77
var cookieJar = CookieJar();
8-
dio.interceptors..add(LogInterceptor())..add(CookieManager(cookieJar));
8+
dio.interceptors
9+
..add(LogInterceptor())
10+
..add(CookieManager(cookieJar));
911
await dio.get('https://baidu.com/');
1012
// Print cookies
1113
print(cookieJar.loadForRequest(Uri.parse('https://baidu.com/')));
File renamed without changes.
File renamed without changes.

example/download_with_trunks.dart renamed to example/lib/download_with_trunks.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ Future downloadWithChunks(
6565

6666
var response = await downloadChunk(url, 0, firstChunkSize, 0);
6767
if (response.statusCode == 206) {
68-
total = int.parse(
69-
response.headers.value(HttpHeaders.contentRangeHeader)!.split('/').last);
68+
total = int.parse(response.headers
69+
.value(HttpHeaders.contentRangeHeader)!
70+
.split('/')
71+
.last);
7072
var reserved =
7173
total - int.parse(response.headers.value(Headers.contentLengthHeader)!);
7274
var chunk = (reserved / firstChunkSize).ceil() + 1;
File renamed without changes.
File renamed without changes.

example/generic.dart renamed to example/lib/generic.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void main() async {
3030
// it will cause a Error (type 'String' is not a subtype of type 'Map<dynamic, dynamic>')
3131
try {
3232
response = await dio.get<Map>('https://baidu.com');
33-
} on DioError catch(e){
33+
} on DioError catch (e) {
3434
print(e.message);
3535
}
3636

File renamed without changes.
File renamed without changes.

example/post_stream_and_bytes.dart renamed to example/lib/post_stream_and_bytes.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ void main() async {
2828

2929
// Sending bytes with Stream(Just an example, you can send json(Map) directly in action)
3030
var postData = utf8.encode('{"userName":"wendux"}');
31-
await dio.post('post',
31+
await dio.post(
32+
'post',
3233
data: Stream.fromIterable([postData]),
33-
onSendProgress: (a,b)=>print(a),
34+
onSendProgress: (a, b) => print(a),
3435
options: Options(
3536
headers: {
3637
HttpHeaders.contentLengthHeader: postData.length, // Set content-length
File renamed without changes.
File renamed without changes.

example/test.dart renamed to example/lib/test.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import 'package:dio/dio.dart';
2020
// getHttp();
2121
// }
2222

23-
import 'package:dio/dio.dart';
24-
2523
void main() async {
2624
final dio = Dio()..interceptors.add(ProblemInterceptor());
2725
await dio.get('https://baidu.com/');
@@ -32,4 +30,4 @@ class ProblemInterceptor extends Interceptor {
3230
void onResponse(Response response, ResponseInterceptorHandler handler) {
3331
throw Exception('Unexpected problem inside onResponse');
3432
}
35-
}
33+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

example/pubspec.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: dio_example
2+
description: A powerful Http client for Dart, which supports Interceptors, FormData, Request Cancellation, File Downloading, Timeout etc.
3+
version: 0.0.1
4+
publish_to: "none"
5+
homepage: https://github.com/flutterchina/dio
6+
7+
environment:
8+
sdk: ">=2.12.0 <3.0.0"
9+
10+
dependencies:
11+
dio:
12+
dio_cookie_manager:
13+
path: ../plugins/cookie_manager
14+
dio_http2_adapter:
15+
path: ../plugins/http2_adapter
16+
17+
dependency_overrides:
18+
dio:
19+
path: ../dio
20+
21+
dev_dependencies:
22+
lints: ^1.0.1
23+
test: ^1.5.1

example/test/examples_test.dart

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// ignore_for_file: unused_import
2+
3+
import 'package:dio_example/adapter.dart';
4+
import 'package:dio_example/cancel_request.dart';
5+
import 'package:dio_example/cookie_mgr.dart';
6+
import 'package:dio_example/custom_cache_interceptor.dart';
7+
import 'package:dio_example/dio.dart';
8+
import 'package:dio_example/download.dart';
9+
import 'package:dio_example/download_with_trunks.dart';
10+
import 'package:dio_example/extend_dio.dart';
11+
import 'package:dio_example/formdata.dart';
12+
import 'package:dio_example/generic.dart';
13+
import 'package:dio_example/http2_adapter.dart';
14+
import 'package:dio_example/options.dart';
15+
import 'package:dio_example/post_stream_and_bytes.dart';
16+
import 'package:dio_example/proxy.dart';
17+
import 'package:dio_example/queue_interceptors.dart';
18+
import 'package:dio_example/queued_interceptor_crsftoken.dart';
19+
import 'package:dio_example/request_interceptors.dart';
20+
import 'package:dio_example/response_interceptor.dart';
21+
import 'package:dio_example/test.dart';
22+
import 'package:dio_example/transformer.dart';
23+
import 'package:test/test.dart';
24+
25+
void main() {
26+
// This test is only used to ensure all samples are compiled
27+
test('dummy', () {});
28+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

example/flutter_app/lib/main.dart renamed to example_flutter_app/lib/main.dart

+5-3
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,17 @@ class _MyHomePageState extends State<MyHomePage> {
6969
child: Column(children: [
7070
ElevatedButton(
7171
child: Text("Request"),
72-
onPressed: ()async {
72+
onPressed: () async {
7373
try {
74-
await dio.get<String>("http://httpbin.org/status/404").then((r) {
74+
await dio
75+
.get<String>("http://httpbin.org/status/404")
76+
.then((r) {
7577
setState(() {
7678
print(r.data);
7779
_text = r.data!.replaceAll(RegExp(r"\s"), "");
7880
});
7981
});
80-
}catch(e){
82+
} catch (e) {
8183
print("sss");
8284
print(e);
8385
}

example/flutter_app/pubspec.yaml renamed to example_flutter_app/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies:
2424
flutter:
2525
sdk: flutter
2626
dio:
27-
path: ../../dio
27+
path: ../dio
2828

2929

3030
# The following adds the Cupertino Icons font to your application.

pubspec.yaml

-23
This file was deleted.

0 commit comments

Comments
 (0)