Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.0 - 16 May 2021
* Fix for Flutter 2 Null safety version
* Lint apply

## 0.5.2 - 30 Dec 2019

* Fix for Flutter 1.12.13+hotfix.5
Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,44 @@

A plugin that connects Flutter to the Chrome Dev Tools on Android devices via the [Stetho Android Library](http://facebook.github.io/stetho/).

## Bug on Inspector of Google Chrome

info: In the last update of Google Chrome, there is a bug in the inspect, so use other browsers based on the older versions of chrome, like [Brave](https://brave.com/download/).

## Install
Add `flutter_stetho` as dependency to your `pubspec.yaml`

```yaml
dev_dependencies:
flutter_stetho:
git:
url: git://github.com/irdevp/flutter_stetho.git
ref: master
```

Add on `main.dart`

```dart
import 'package:flutter_stetho/flutter_stetho.dart';

void main() {
Stetho.initialize();

runApp(MyApp());
}
```

## Tutorial Network Inspector on Brave

navigate to `chrome://inspect`

<img src="https://github.com/irdevp/flutter_stetho/raw/master/assets/example.gif" alt="Network Inspector Brave">

## Network Inspector

The main feature I was aiming to achieve was a Network Inspector.

<img src="https://github.com/brianegan/flutter_stetho/raw/master/assets/network_inspector.gif" alt="Network Inspector in Action">
<img src="https://github.com/irdevp/flutter_stetho/raw/master/assets/network_inspector.gif" alt="Network Inspector in Action">

## Getting Started

Expand All @@ -19,6 +52,7 @@ Add `flutter_stetho` to your dependencies in the `pubspec.yaml` file
- For Flutter 1.7.x, use version `0.3.x`
- For Flutter 1.8.x, use version `0.4.x`
- For Flutter 1.9.x, use version `0.5.x`
- For Flutter 2.x, use version `0.6.x`

### Install StethoHttpOverrides

Expand Down
Binary file added assets/example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 29 additions & 27 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,66 @@ import 'package:http/http.dart' as http;
void main() {
Stetho.initialize();

runApp(new FlutterStethoExample(
client: new http.Client(),
runApp(FlutterStethoExample(
client: http.Client(),
));
}

class FlutterStethoExample extends StatelessWidget {
final http.Client client;

FlutterStethoExample({Key key, this.client}) : super(key: key);
const FlutterStethoExample({Key? key, required this.client})
: super(key: key);

fetchImage() {
void Function()? fetchImage() {
client.get(
'https://flutter.dev/assets/404/dash_nest-c64796b59b65042a2b40fae5764c13b7477a592db79eaf04c86298dcb75b78ea.png',
Uri.parse(
'https://flutter.dev/assets/404/dash_nest-c64796b59b65042a2b40fae5764c13b7477a592db79eaf04c86298dcb75b78ea.png'),
headers: {'Authorization': 'token'},
);
}

fetchJson() {
void Function()? fetchJson() {
client.get(
'https://jsonplaceholder.typicode.com/posts/1',
Uri.parse('https://jsonplaceholder.typicode.com/posts/1'),
headers: {'Authorization': 'token'},
);
}

fetchError() {
client.get('https://jsonplaceholder.typicode.com/postadsass/1');
void Function()? fetchError() {
client.get(Uri.parse('https://jsonplaceholder.typicode.com/postadsass/1'));
}

@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('Plugin example app'),
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: new Center(
child: new Column(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Padding(
padding: new EdgeInsets.all(16.0),
child: new RaisedButton(
Padding(
padding: const EdgeInsets.all(16.0),
child: ElevatedButton(
onPressed: fetchJson,
child: new Text("Fetch json"),
child: const Text("Fetch json"),
),
),
new Padding(
padding: new EdgeInsets.all(16.0),
child: new RaisedButton(
Padding(
padding: const EdgeInsets.all(16.0),
child: ElevatedButton(
onPressed: fetchImage,
child: new Text("Fetch image"),
child: const Text("Fetch image"),
),
),
new Padding(
padding: new EdgeInsets.all(16.0),
child: new RaisedButton(
Padding(
padding: const EdgeInsets.all(16.0),
child: ElevatedButton(
onPressed: fetchError,
child: new Text("Fetch with Error"),
child: const Text("Fetch with Error"),
),
)
],
Expand Down
17 changes: 12 additions & 5 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
name: flutter_stetho_example
description: Demonstrates how to use the flutter_stetho plugin.
description: Demonstrates how to use the flutter_stetho plugin for flutter 2.0.

environment:
sdk: '>=2.12.0 <3.0.0'

dependencies:
flutter:
sdk: flutter
http: ^0.12.0
http: ^0.13.3


dev_dependencies:
flutter_test:
sdk: flutter
flutter_stetho:
path: ../
flutter_test:
sdk: flutter




flutter:
uses-material-design: true
uses-material-design: true
56 changes: 30 additions & 26 deletions lib/src/http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import 'package:flutter_stetho/src/method_channel_controller.dart';
import 'package:flutter_stetho/src/utils.dart';

class StethoHttpClient implements HttpClient {
final HttpClient client;
final HttpClient? client;

StethoHttpClient(this.client);
StethoHttpClient(
{required this.client,
this.autoUncompress = false,
this.idleTimeout = const Duration(seconds: 5)});

@override
bool autoUncompress;
Expand All @@ -18,21 +21,21 @@ class StethoHttpClient implements HttpClient {
Duration idleTimeout;

@override
Duration connectionTimeout;
Duration? connectionTimeout;

@override
int maxConnectionsPerHost;
int? maxConnectionsPerHost;

@override
String userAgent;
String? userAgent;

@override
void addCredentials(
Uri url,
String realm,
HttpClientCredentials credentials,
) {
client.addCredentials(url, realm, credentials);
client!.addCredentials(url, realm, credentials);
}

@override
Expand All @@ -42,33 +45,34 @@ class StethoHttpClient implements HttpClient {
String realm,
HttpClientCredentials credentials,
) {
client.addProxyCredentials(host, port, realm, credentials);
client!.addProxyCredentials(host, port, realm, credentials);
}

@override
set authenticate(
Future<bool> Function(Uri url, String scheme, String realm) f,
Future<bool> Function(Uri url, String scheme, String realm)? f,
) {
client.authenticate = f;
client!.authenticate = f;
}

@override
set authenticateProxy(
Future<bool> Function(String host, int port, String scheme, String realm) f,
Future<bool> Function(String host, int port, String scheme, String realm)?
f,
) {
client.authenticateProxy = f;
client!.authenticateProxy = f;
}

@override
set badCertificateCallback(
bool Function(X509Certificate cert, String host, int port) callback,
bool Function(X509Certificate cert, String host, int port)? callback,
) {
client.badCertificateCallback = callback;
client!.badCertificateCallback = callback;
}

@override
void close({bool force: false}) {
client.close();
void close({bool force = false}) {
client!.close();
}

@override
Expand Down Expand Up @@ -114,7 +118,7 @@ class StethoHttpClient implements HttpClient {
Future<HttpClientRequest> patchUrl(Uri url) => openUrl("patch", url);

@override
set findProxy(String Function(Uri url) f) => client.findProxy = f;
set findProxy(String Function(Uri url)? f) => client!.findProxy = f;

@override
Future<HttpClientRequest> open(
Expand All @@ -123,19 +127,19 @@ class StethoHttpClient implements HttpClient {
int port,
String path,
) async {
Uri uri = Uri(host: host,port: port, path: path);
return await openUrl(method, uri);
final Uri uri = Uri(host: host, port: port, path: path);
return openUrl(method, uri);
}

@override
Future<HttpClientRequest> openUrl(String method, Uri url) async {
return client.openUrl(method, url).then((request) {
return client!.openUrl(method, url).then((request) {
final wrapped = _wrapResponse(request);
List<int> body = [];
if (method.toLowerCase() != 'post' && method.toLowerCase() != 'put'){
final List<int> body = [];
if (method.toLowerCase() != 'post' && method.toLowerCase() != 'put') {
scheduleMicrotask(() {
MethodChannelController.requestWillBeSent(
new FlutterStethoInspectorRequest(
FlutterStethoInspectorRequest(
url: request.uri.toString(),
headers: headersToMap(request.headers),
method: request.method,
Expand All @@ -146,10 +150,10 @@ class StethoHttpClient implements HttpClient {
});
} else {
wrapped.stream.listen((onData) {
body.addAll(onData);
body.addAll(onData as Iterable<int>);
scheduleMicrotask(() {
MethodChannelController.requestWillBeSent(
new FlutterStethoInspectorRequest(
FlutterStethoInspectorRequest(
url: request.uri.toString(),
headers: headersToMap(request.headers),
method: request.method,
Expand All @@ -166,8 +170,8 @@ class StethoHttpClient implements HttpClient {
}

StethoHttpClientRequest _wrapResponse(HttpClientRequest request) {
final id = new Uuid().generateV4();
final id = Uuid().generateV4();

return new StethoHttpClientRequest(request, id);
return StethoHttpClientRequest(request, id);
}
}
Loading