Skip to content

Commit

Permalink
- Added Chopper support
Browse files Browse the repository at this point in the history
- Added AndroidX support
- 0.0.21 Release
  • Loading branch information
jhomlala committed Dec 22, 2019
1 parent ff02c9d commit e72fad9
Show file tree
Hide file tree
Showing 15 changed files with 561 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## 0.0.21
* Added Chopper support
* Added AndroidX support

## 0.0.20
* Updated dependencies

Expand Down
10 changes: 9 additions & 1 deletion README.md
Expand Up @@ -79,7 +79,7 @@ Alice is an HTTP Inspector tool for Flutter which helps debugging http requests.

```yaml
dependencies:
alice: ^0.0.20
alice: ^0.0.21
```

2. Install it
Expand Down Expand Up @@ -159,6 +159,14 @@ http.get('https://jsonplaceholder.typicode.com/posts').then((response) {
});
```

If you're using Chopper. you need to add interceptor:

```dart
chopper = ChopperClient(
interceptors: alice.getChopperInterceptor(),
);
```

To show inspector manually:

```dart
Expand Down
6 changes: 3 additions & 3 deletions android/build.gradle
Expand Up @@ -2,14 +2,14 @@ group 'com.jhomlala.alice'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.21'
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -32,7 +32,7 @@ android {
}
defaultConfig {
minSdkVersion 19
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'InvalidPackage'
Expand Down
2 changes: 2 additions & 0 deletions android/gradle.properties
@@ -1,2 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
4 changes: 2 additions & 2 deletions example/android/build.gradle
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.3.21'
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
24 changes: 23 additions & 1 deletion example/lib/main.dart
@@ -1,6 +1,8 @@
import 'dart:convert';
import 'dart:io';
import 'package:alice/alice.dart';
import 'package:alice_example/posts_service.dart';
import 'package:chopper/chopper.dart';
import 'package:http/http.dart' as http;

import 'package:dio/dio.dart';
Expand All @@ -17,13 +19,21 @@ class _MyAppState extends State<MyApp> {
Alice alice;
Dio dio;
HttpClient httpClient;
ChopperClient chopper;
PostsService postsService;

@override
void initState() {
alice = Alice(showNotification: true, showInspectorOnShake: true, darkTheme: true);
alice = Alice(
showNotification: true, showInspectorOnShake: true, darkTheme: true);
dio = Dio();
dio.interceptors.add(alice.getDioInterceptor());
httpClient = HttpClient();
chopper = ChopperClient(
interceptors: alice.getChopperInterceptor(),
);
postsService = PostsService.create(chopper);

super.initState();
}

Expand Down Expand Up @@ -52,7 +62,19 @@ class _MyAppState extends State<MyApp> {
);
}

void _runChopperHttpRequests() async {
Map<String, dynamic> body = {"title": "foo", "body": "bar", "userId": "1"};
postsService.getPost("1");
postsService.postPost(body);
postsService.putPost("1", body);
postsService.putPost("1231923", body);
postsService.putPost("1", null);
postsService.postPost(null);
postsService.getPost("123456");
}

void _runHttpRequests() async {
_runChopperHttpRequests();
Map<String, dynamic> body = {"title": "foo", "body": "bar", "userId": "1"};
http
.post('https://jsonplaceholder.typicode.com/posts', body: body)
Expand Down
23 changes: 23 additions & 0 deletions example/lib/posts_service.dart
@@ -0,0 +1,23 @@
// YOUR_FILE.dart

import "dart:async";
import 'package:chopper/chopper.dart';

// this is necessary for the generated code to find your class
part "posts_service.chopper.dart";

@ChopperApi(baseUrl: "https://jsonplaceholder.typicode.com/posts")
abstract class PostsService extends ChopperService {
// helper methods that help you instanciate your service
static PostsService create([ChopperClient client]) => _$PostsService(client);

@Get(path: '/{id}')
Future<Response> getPost(@Path() String id);

@Post(path: '/')
Future<Response> postPost(@Body() Map<String, dynamic> body);

@Put(path: '/{id}')
Future<Response> putPost(
@Path() String id, @Body() Map<String, dynamic> body);
}

0 comments on commit e72fad9

Please sign in to comment.