diff --git a/examples/alice_http_client/analysis_options.yaml b/examples/alice_http_client/analysis_options.yaml index 01f89e9c..d4e71cb5 100644 --- a/examples/alice_http_client/analysis_options.yaml +++ b/examples/alice_http_client/analysis_options.yaml @@ -1,16 +1,12 @@ -1include: package:very_good_analysis/analysis_options.yaml +analyzer: + exclude: + - "lib/generated_plugin_registrant.dart" + - "**.g.dart" + - "**.mocks.dart" + - "**.gen.dart" + +include: package:flutter_lints/flutter.yaml linter: rules: - public_member_api_docs: false - flutter_style_todos: false - avoid_final_parameters: false - sort_constructors_first: false - avoid_function_literals_in_foreach_calls: false - avoid_positional_boolean_parameters: false - use_if_null_to_convert_nulls_to_bools: false - use_build_context_synchronously: false - prefer_constructors_over_static_methods: false - use_setters_to_change_properties: false - avoid_print: false - sort_pub_dependencies: false \ No newline at end of file + #library_annotations: false diff --git a/examples/alice_http_client/lib/main.dart b/examples/alice_http_client/lib/main.dart index 659c0100..ee35496c 100644 --- a/examples/alice_http_client/lib/main.dart +++ b/examples/alice_http_client/lib/main.dart @@ -6,31 +6,26 @@ import 'package:alice_http_client/alice_http_client_adapter.dart'; import 'package:alice_http_client/alice_http_client_extensions.dart'; import 'package:flutter/material.dart'; -void main() => runApp(MyApp()); +void main() => runApp(const MyApp()); class MyApp extends StatefulWidget { + const MyApp({super.key}); + @override - _MyAppState createState() => _MyAppState(); + State createState() => _MyAppState(); } class _MyAppState extends State { - late Alice _alice; - late HttpClient _httpClient; - late AliceHttpClientAdapter _httpClientAdapter; + late final HttpClient _httpClient = HttpClient(); - @override - void initState() { - _alice = Alice( - showNotification: true, - showInspectorOnShake: true, - maxCallsCount: 1000, - ); - _httpClient = HttpClient(); - _httpClientAdapter = AliceHttpClientAdapter(); - _alice.addAdapter(_httpClientAdapter); + late final AliceHttpClientAdapter _httpClientAdapter = + AliceHttpClientAdapter(); - super.initState(); - } + late final Alice _alice = Alice( + showNotification: true, + showInspectorOnShake: true, + maxCallsCount: 1000, + )..addAdapter(_httpClientAdapter); @override Widget build(BuildContext context) { @@ -42,27 +37,27 @@ class _MyAppState extends State { title: const Text('Alice + HTTP Client - Example'), ), body: Container( - padding: EdgeInsets.all(16), + padding: const EdgeInsets.all(16), child: ListView( children: [ const SizedBox(height: 8), - Text( + const Text( 'Welcome to example of Alice Http Inspector. Click buttons below to generate sample data.'), ElevatedButton( - child: Text( + onPressed: _runHttpHttpClientRequests, + child: const Text( 'Run HttpClient Requests', ), - onPressed: _runHttpHttpClientRequests, ), const SizedBox(height: 8), - Text( + const Text( 'After clicking on buttons above, you should receive notification.' ' Click on it to show inspector. You can also shake your device or click button below.'), ElevatedButton( - child: Text( + onPressed: _runHttpInspector, + child: const Text( 'Run HTTP Inspector', ), - onPressed: _runHttpInspector, ) ], ), @@ -72,79 +67,130 @@ class _MyAppState extends State { } void _runHttpHttpClientRequests() { - Map body = { + final Map body = { 'title': 'foo', 'body': 'bar', 'userId': '1' }; + _httpClient - .getUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts')) + .getUrl(Uri.https('jsonplaceholder.typicode.com', '/posts')) .interceptWithAlice(_httpClientAdapter); _httpClient - .postUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts')) - .interceptWithAlice(_httpClientAdapter, - body: body, headers: {}); + .postUrl(Uri.https('jsonplaceholder.typicode.com', '/posts')) + .interceptWithAlice(_httpClientAdapter, body: body, headers: {}); _httpClient - .putUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts/1')) + .putUrl(Uri.https('jsonplaceholder.typicode.com', '/posts/1')) .interceptWithAlice(_httpClientAdapter, body: body); _httpClient - .getUrl(Uri.parse('https://jsonplaceholder.typicode.com/test/test/')) + .getUrl(Uri.https('jsonplaceholder.typicode.com', '/test/test/')) .interceptWithAlice(_httpClientAdapter); _httpClient - .postUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts')) - .then((request) async { - _httpClientAdapter.onRequest(request, body: body); - request.write(body); - var httpResponse = await request.close(); - var responseBody = await utf8.decoder.bind(httpResponse).join(); - _httpClientAdapter.onResponse(httpResponse, request, body: responseBody); - }); + .postUrl(Uri.https('jsonplaceholder.typicode.com', '/posts')) + .then( + (HttpClientRequest request) async { + _httpClientAdapter.onRequest(request, body: body); + + request.write(body); + + final HttpClientResponse httpResponse = await request.close(); + + final String responseBody = + await utf8.decoder.bind(httpResponse).join(); + + _httpClientAdapter.onResponse( + httpResponse, + request, + body: responseBody, + ); + }, + ); _httpClient - .putUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts/1')) - .then((request) async { - _httpClientAdapter.onRequest(request, body: body); - request.write(body); - var httpResponse = await request.close(); - var responseBody = await utf8.decoder.bind(httpResponse).join(); - _httpClientAdapter.onResponse(httpResponse, request, body: responseBody); - }); + .putUrl(Uri.https('jsonplaceholder.typicode.com', '/posts/1')) + .then( + (HttpClientRequest request) async { + _httpClientAdapter.onRequest(request, body: body); + + request.write(body); + + final HttpClientResponse httpResponse = await request.close(); + + final String responseBody = + await utf8.decoder.bind(httpResponse).join(); + + _httpClientAdapter.onResponse( + httpResponse, + request, + body: responseBody, + ); + }, + ); _httpClient - .patchUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts/1')) - .then((request) async { - _httpClientAdapter.onRequest(request, body: body); - request.write(body); - var httpResponse = await request.close(); - var responseBody = await utf8.decoder.bind(httpResponse).join(); - _httpClientAdapter.onResponse(httpResponse, request, body: responseBody); - }); + .patchUrl(Uri.https('jsonplaceholder.typicode.com', '/posts/1')) + .then( + (HttpClientRequest request) async { + _httpClientAdapter.onRequest(request, body: body); + + request.write(body); + + final HttpClientResponse httpResponse = await request.close(); + final String responseBody = + await utf8.decoder.bind(httpResponse).join(); + + _httpClientAdapter.onResponse( + httpResponse, + request, + body: responseBody, + ); + }, + ); _httpClient - .deleteUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts/1')) - .then((request) async { - _httpClientAdapter.onRequest(request); - var httpResponse = await request.close(); - var responseBody = await utf8.decoder.bind(httpResponse).join(); - _httpClientAdapter.onResponse(httpResponse, request, body: responseBody); - }); + .deleteUrl(Uri.https('jsonplaceholder.typicode.com', '/posts/1')) + .then( + (HttpClientRequest request) async { + _httpClientAdapter.onRequest(request); + + final HttpClientResponse httpResponse = await request.close(); + + final String responseBody = + await utf8.decoder.bind(httpResponse).join(); + + _httpClientAdapter.onResponse( + httpResponse, + request, + body: responseBody, + ); + }, + ); _httpClient - .getUrl(Uri.parse('https://jsonplaceholder.typicode.com/test/test/')) - .then((request) async { - _httpClientAdapter.onRequest(request); - var httpResponse = await request.close(); - var responseBody = await utf8.decoder.bind(httpResponse).join(); - _httpClientAdapter.onResponse(httpResponse, request, body: responseBody); - }); + .getUrl(Uri.https('jsonplaceholder.typicode.com', '/test/test/')) + .then( + (HttpClientRequest request) async { + _httpClientAdapter.onRequest(request); + + final HttpClientResponse httpResponse = await request.close(); + + final String responseBody = + await utf8.decoder.bind(httpResponse).join(); + + _httpClientAdapter.onResponse( + httpResponse, + request, + body: responseBody, + ); + }, + ); } void _runHttpInspector() { _alice.showInspector(); } } - diff --git a/examples/alice_http_client/pubspec.yaml b/examples/alice_http_client/pubspec.yaml index 63ee7dc8..e4dbea2a 100644 --- a/examples/alice_http_client/pubspec.yaml +++ b/examples/alice_http_client/pubspec.yaml @@ -13,6 +13,9 @@ dependencies: alice: alice_http_client: +dev_dependencies: + flutter_lints: ^4.0.0 + dependency_overrides: alice: path: ../../packages/alice