diff --git a/analysis_options.yaml b/analysis_options.yaml index 7a89bf52..6b181fb5 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,24 +1,16 @@ -#include: package:lint/analysis_options.yaml - -analyzer: - strong-mode: - implicit-dynamic: false - exclude: - - "**/*.chopper.dart" +include: package:very_good_analysis/analysis_options.yaml linter: rules: - close_sinks: true + public_member_api_docs: false + flutter_style_todos: false + avoid_final_parameters: false sort_constructors_first: false - avoid_classes_with_only_static_members: false - avoid_void_async: false - avoid_positional_boolean_parameters: 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 - sort_unnamed_constructors_first: false - sized_box_for_whitespace: false - invalid_dependency: false - sort_pub_dependencies: false - directives_ordering: false - noop_primitive_operations: false - use_build_context_synchronously: false \ No newline at end of file + use_setters_to_change_properties: false + avoid_print: false + sort_pub_dependencies: false \ No newline at end of file diff --git a/example/lib/main.dart b/example/lib/main.dart index 450f1b69..ad07bc00 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -70,38 +70,38 @@ class _MyAppState extends State { children: [ const SizedBox(height: 8), _getTextWidget( - "Welcome to example of Alice Http Inspector. Click buttons below to generate sample data."), + 'Welcome to example of Alice Http Inspector. Click buttons below to generate sample data.'), ElevatedButton( - child: Text("Run Dio HTTP Requests"), + child: Text('Run Dio HTTP Requests'), onPressed: _runDioRequests, style: _buttonStyle, ), ElevatedButton( - child: Text("Run http/http HTTP Requests"), + child: Text('Run http/http HTTP Requests'), onPressed: _runHttpHttpRequests, style: _buttonStyle, ), ElevatedButton( - child: Text("Run HttpClient Requests"), + child: Text('Run HttpClient Requests'), onPressed: _runHttpHttpClientRequests, style: _buttonStyle, ), ElevatedButton( - child: Text("Run Chopper HTTP Requests"), + child: Text('Run Chopper HTTP Requests'), onPressed: _runChopperHttpRequests, style: _buttonStyle, ), ElevatedButton( - child: Text("Log example data"), + child: Text('Log example data'), onPressed: _logExampleData, style: _buttonStyle, ), const SizedBox(height: 24), _getTextWidget( - "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."), + '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("Run HTTP Inspector"), + child: Text('Run HTTP Inspector'), onPressed: _runHttpInspector, style: _buttonStyle, ) @@ -162,70 +162,70 @@ class _MyAppState extends State { void _runChopperHttpRequests() async { String body = jsonEncode( - {"title": "foo", "body": "bar", "userId": "1"}); - _postsService.getPost("1"); + {'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.putPost('1', body); + _postsService.putPost('1231923', body); + _postsService.putPost('1', null); _postsService.postPost(null); - _postsService.getPost("123456"); + _postsService.getPost('123456'); } void _runDioRequests() async { Map body = { - "title": "foo", - "body": "bar", - "userId": "1" + 'title': 'foo', + 'body': 'bar', + 'userId': '1' }; _dio.get( - "https://httpbin.org/redirect-to?url=https%3A%2F%2Fhttpbin.org"); - _dio.delete("https://httpbin.org/status/500"); - _dio.delete("https://httpbin.org/status/400"); - _dio.delete("https://httpbin.org/status/300"); - _dio.delete("https://httpbin.org/status/200"); - _dio.delete("https://httpbin.org/status/100"); - _dio.post("https://jsonplaceholder.typicode.com/posts", data: body); - _dio.get("https://jsonplaceholder.typicode.com/posts", - queryParameters: {"test": 1}); - _dio.put("https://jsonplaceholder.typicode.com/posts/1", data: body); - _dio.put("https://jsonplaceholder.typicode.com/posts/1", data: body); - _dio.delete("https://jsonplaceholder.typicode.com/posts/1"); - _dio.get("http://jsonplaceholder.typicode.com/test/test"); - - _dio.get("https://jsonplaceholder.typicode.com/photos"); + 'https://httpbin.org/redirect-to?url=https%3A%2F%2Fhttpbin.org'); + _dio.delete('https://httpbin.org/status/500'); + _dio.delete('https://httpbin.org/status/400'); + _dio.delete('https://httpbin.org/status/300'); + _dio.delete('https://httpbin.org/status/200'); + _dio.delete('https://httpbin.org/status/100'); + _dio.post('https://jsonplaceholder.typicode.com/posts', data: body); + _dio.get('https://jsonplaceholder.typicode.com/posts', + queryParameters: {'test': 1}); + _dio.put('https://jsonplaceholder.typicode.com/posts/1', data: body); + _dio.put('https://jsonplaceholder.typicode.com/posts/1', data: body); + _dio.delete('https://jsonplaceholder.typicode.com/posts/1'); + _dio.get('http://jsonplaceholder.typicode.com/test/test'); + + _dio.get('https://jsonplaceholder.typicode.com/photos'); _dio.get( - "https://icons.iconarchive.com/icons/paomedia/small-n-flat/256/sign-info-icon.png"); + 'https://icons.iconarchive.com/icons/paomedia/small-n-flat/256/sign-info-icon.png'); _dio.get( - "https://images.unsplash.com/photo-1542736705-53f0131d1e98?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80"); + 'https://images.unsplash.com/photo-1542736705-53f0131d1e98?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80'); _dio.get( - "https://findicons.com/files/icons/1322/world_of_aqua_5/128/bluetooth.png"); + 'https://findicons.com/files/icons/1322/world_of_aqua_5/128/bluetooth.png'); _dio.get( - "https://upload.wikimedia.org/wikipedia/commons/4/4e/Pleiades_large.jpg"); - _dio.get("http://techslides.com/demos/sample-videos/small.mp4"); + 'https://upload.wikimedia.org/wikipedia/commons/4/4e/Pleiades_large.jpg'); + _dio.get('http://techslides.com/demos/sample-videos/small.mp4'); - _dio.get("https://www.cse.wustl.edu/~jain/cis677-97/ftp/e_3dlc2.pdf"); + _dio.get('https://www.cse.wustl.edu/~jain/cis677-97/ftp/e_3dlc2.pdf'); final directory = await getApplicationDocumentsDirectory(); - File file = File("${directory.path}/test.txt"); + File file = File('${directory.path}/test.txt'); file.create(); - file.writeAsStringSync("123456789"); + file.writeAsStringSync('123456789'); String fileName = file.path.split('/').last; FormData formData = FormData.fromMap({ - "file": await MultipartFile.fromFile(file.path, filename: fileName), + 'file': await MultipartFile.fromFile(file.path, filename: fileName), }); - _dio.post("https://jsonplaceholder.typicode.com/photos", + _dio.post('https://jsonplaceholder.typicode.com/photos', data: formData); - _dio.get("http://dummy.restapiexample.com/api/v1/employees"); + _dio.get('http://dummy.restapiexample.com/api/v1/employees'); } void _runHttpHttpRequests() async { Map body = { - "title": "foo", - "body": "bar", - "userId": "1" + 'title': 'foo', + 'body': 'bar', + 'userId': '1' }; http .post(Uri.tryParse('https://jsonplaceholder.typicode.com/posts')!, @@ -317,28 +317,28 @@ class _MyAppState extends State { void _runHttpHttpClientRequests() { Map body = { - "title": "foo", - "body": "bar", - "userId": "1" + 'title': 'foo', + 'body': 'bar', + 'userId': '1' }; _httpClient - .getUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts")) + .getUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts')) .interceptWithAlice(_alice); _httpClient - .postUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts")) + .postUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts')) .interceptWithAlice(_alice, body: body, headers: {}); _httpClient - .putUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts/1")) + .putUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts/1')) .interceptWithAlice(_alice, body: body); _httpClient - .getUrl(Uri.parse("https://jsonplaceholder.typicode.com/test/test/")) + .getUrl(Uri.parse('https://jsonplaceholder.typicode.com/test/test/')) .interceptWithAlice(_alice); _httpClient - .postUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts")) + .postUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts')) .then((request) async { _alice.onHttpClientRequest(request, body: body); request.write(body); @@ -348,7 +348,7 @@ class _MyAppState extends State { }); _httpClient - .putUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts/1")) + .putUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts/1')) .then((request) async { _alice.onHttpClientRequest(request, body: body); request.write(body); @@ -358,7 +358,7 @@ class _MyAppState extends State { }); _httpClient - .patchUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts/1")) + .patchUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts/1')) .then((request) async { _alice.onHttpClientRequest(request, body: body); request.write(body); @@ -368,7 +368,7 @@ class _MyAppState extends State { }); _httpClient - .deleteUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts/1")) + .deleteUrl(Uri.parse('https://jsonplaceholder.typicode.com/posts/1')) .then((request) async { _alice.onHttpClientRequest(request); var httpResponse = await request.close(); @@ -377,7 +377,7 @@ class _MyAppState extends State { }); _httpClient - .getUrl(Uri.parse("https://jsonplaceholder.typicode.com/test/test/")) + .getUrl(Uri.parse('https://jsonplaceholder.typicode.com/test/test/')) .then((request) async { _alice.onHttpClientRequest(request); var httpResponse = await request.close(); diff --git a/example/lib/posts_service.dart b/example/lib/posts_service.dart index ba838830..53f05d10 100644 --- a/example/lib/posts_service.dart +++ b/example/lib/posts_service.dart @@ -1,10 +1,11 @@ import "dart:async"; + import 'package:chopper/chopper.dart'; // this is necessary for the generated code to find your class -part "posts_service.chopper.dart"; +part 'posts_service.chopper.dart'; -@ChopperApi(baseUrl: "https://jsonplaceholder.typicode.com/posts") +@ChopperApi(baseUrl: 'https://jsonplaceholder.typicode.com/posts') abstract class PostsService extends ChopperService { // helper methods that help you instantiate your service static PostsService create([ChopperClient? client]) => diff --git a/example/pubspec.lock b/example/pubspec.lock deleted file mode 100644 index 6b6a8987..00000000 --- a/example/pubspec.lock +++ /dev/null @@ -1,868 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - _fe_analyzer_shared: - dependency: transitive - description: - name: _fe_analyzer_shared - sha256: ae92f5d747aee634b87f89d9946000c2de774be1d6ac3e58268224348cd0101a - url: "https://pub.dev" - source: hosted - version: "61.0.0" - alice: - dependency: "direct dev" - description: - path: ".." - relative: true - source: path - version: "0.3.3" - analyzer: - dependency: transitive - description: - name: analyzer - sha256: ea3d8652bda62982addfd92fdc2d0214e5f82e43325104990d4f4c4a2a313562 - url: "https://pub.dev" - source: hosted - version: "5.13.0" - args: - dependency: transitive - description: - name: args - sha256: c372bb384f273f0c2a8aaaa226dad84dc27c8519a691b888725dec59518ad53a - url: "https://pub.dev" - source: hosted - version: "2.4.1" - async: - dependency: transitive - description: - name: async - sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" - url: "https://pub.dev" - source: hosted - version: "2.11.0" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" - url: "https://pub.dev" - source: hosted - version: "2.1.1" - build: - dependency: transitive - description: - name: build - sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0" - url: "https://pub.dev" - source: hosted - version: "2.4.1" - build_config: - dependency: transitive - description: - name: build_config - sha256: bf80fcfb46a29945b423bd9aad884590fb1dc69b330a4d4700cac476af1708d1 - url: "https://pub.dev" - source: hosted - version: "1.1.1" - build_daemon: - dependency: transitive - description: - name: build_daemon - sha256: "5f02d73eb2ba16483e693f80bee4f088563a820e47d1027d4cdfe62b5bb43e65" - url: "https://pub.dev" - source: hosted - version: "4.0.0" - build_resolvers: - dependency: transitive - description: - name: build_resolvers - sha256: db49b8609ef8c81cca2b310618c3017c00f03a92af44c04d310b907b2d692d95 - url: "https://pub.dev" - source: hosted - version: "2.2.0" - build_runner: - dependency: "direct dev" - description: - name: build_runner - sha256: "220ae4553e50d7c21a17c051afc7b183d28a24a420502e842f303f8e4e6edced" - url: "https://pub.dev" - source: hosted - version: "2.4.4" - build_runner_core: - dependency: transitive - description: - name: build_runner_core - sha256: "88a57f2ac99849362e73878334caa9f06ee25f31d2adced882b8337838c84e1e" - url: "https://pub.dev" - source: hosted - version: "7.2.9" - built_collection: - dependency: transitive - description: - name: built_collection - sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100" - url: "https://pub.dev" - source: hosted - version: "5.1.1" - built_value: - dependency: transitive - description: - name: built_value - sha256: "7dd62d9faf105c434f3d829bbe9c4be02ec67f5ed94832222116122df67c5452" - url: "https://pub.dev" - source: hosted - version: "8.6.0" - characters: - dependency: transitive - description: - name: characters - sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" - url: "https://pub.dev" - source: hosted - version: "1.3.0" - checked_yaml: - dependency: transitive - description: - name: checked_yaml - sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff - url: "https://pub.dev" - source: hosted - version: "2.0.3" - chopper: - dependency: "direct main" - description: - name: chopper - sha256: "4ba5b590f4dc04b948024efdf4d85fd484d6c81eb83cefc36f29cf83f6e50ae5" - url: "https://pub.dev" - source: hosted - version: "7.0.9" - chopper_generator: - dependency: "direct dev" - description: - name: chopper_generator - sha256: "89d40e458fa21eb1e8f2f87961548d834f24d287e23fcac17b57ab58978ccd06" - url: "https://pub.dev" - source: hosted - version: "7.0.6" - clock: - dependency: transitive - description: - name: clock - sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf - url: "https://pub.dev" - source: hosted - version: "1.1.1" - code_builder: - dependency: transitive - description: - name: code_builder - sha256: "4ad01d6e56db961d29661561effde45e519939fdaeb46c351275b182eac70189" - url: "https://pub.dev" - source: hosted - version: "4.5.0" - collection: - dependency: transitive - description: - name: collection - sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 - url: "https://pub.dev" - source: hosted - version: "1.17.2" - convert: - dependency: transitive - description: - name: convert - sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" - url: "https://pub.dev" - source: hosted - version: "3.1.1" - cross_file: - dependency: transitive - description: - name: cross_file - sha256: "0b0036e8cccbfbe0555fd83c1d31a6f30b77a96b598b35a5d36dd41f718695e9" - url: "https://pub.dev" - source: hosted - version: "0.3.3+4" - crypto: - dependency: transitive - description: - name: crypto - sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab - url: "https://pub.dev" - source: hosted - version: "3.0.3" - dart_style: - dependency: transitive - description: - name: dart_style - sha256: "1efa911ca7086affd35f463ca2fc1799584fb6aa89883cf0af8e3664d6a02d55" - url: "https://pub.dev" - source: hosted - version: "2.3.2" - dbus: - dependency: transitive - description: - name: dbus - sha256: "6f07cba3f7b3448d42d015bfd3d53fe12e5b36da2423f23838efc1d5fb31a263" - url: "https://pub.dev" - source: hosted - version: "0.7.8" - dio: - dependency: transitive - description: - name: dio - sha256: "417e2a6f9d83ab396ec38ff4ea5da6c254da71e4db765ad737a42af6930140b7" - url: "https://pub.dev" - source: hosted - version: "5.3.3" - equatable: - dependency: transitive - description: - name: equatable - sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2 - url: "https://pub.dev" - source: hosted - version: "2.0.5" - ffi: - dependency: transitive - description: - name: ffi - sha256: ed5337a5660c506388a9f012be0288fb38b49020ce2b45fe1f8b8323fe429f99 - url: "https://pub.dev" - source: hosted - version: "2.0.2" - file: - dependency: transitive - description: - name: file - sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d" - url: "https://pub.dev" - source: hosted - version: "6.1.4" - fixnum: - dependency: transitive - description: - name: fixnum - sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" - url: "https://pub.dev" - source: hosted - version: "1.1.0" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_local_notifications: - dependency: transitive - description: - name: flutter_local_notifications - sha256: "6d11ea777496061e583623aaf31923f93a9409ef8fcaeeefdd6cd78bf4fe5bb3" - url: "https://pub.dev" - source: hosted - version: "16.1.0" - flutter_local_notifications_linux: - dependency: transitive - description: - name: flutter_local_notifications_linux - sha256: "33f741ef47b5f63cc7f78fe75eeeac7e19f171ff3c3df054d84c1e38bedb6a03" - url: "https://pub.dev" - source: hosted - version: "4.0.0+1" - flutter_local_notifications_platform_interface: - dependency: transitive - description: - name: flutter_local_notifications_platform_interface - sha256: "7cf643d6d5022f3baed0be777b0662cce5919c0a7b86e700299f22dc4ae660ef" - url: "https://pub.dev" - source: hosted - version: "7.0.0+1" - flutter_web_plugins: - dependency: transitive - description: flutter - source: sdk - version: "0.0.0" - frontend_server_client: - dependency: transitive - description: - name: frontend_server_client - sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612" - url: "https://pub.dev" - source: hosted - version: "3.2.0" - glob: - dependency: transitive - description: - name: glob - sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" - url: "https://pub.dev" - source: hosted - version: "2.1.2" - graphs: - dependency: transitive - description: - name: graphs - sha256: aedc5a15e78fc65a6e23bcd927f24c64dd995062bcd1ca6eda65a3cff92a4d19 - url: "https://pub.dev" - source: hosted - version: "2.3.1" - http: - dependency: transitive - description: - name: http - sha256: "759d1a329847dd0f39226c688d3e06a6b8679668e350e2891a6474f8b4bb8525" - url: "https://pub.dev" - source: hosted - version: "1.1.0" - http_multi_server: - dependency: transitive - description: - name: http_multi_server - sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b" - url: "https://pub.dev" - source: hosted - version: "3.2.1" - http_parser: - dependency: transitive - description: - name: http_parser - sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" - url: "https://pub.dev" - source: hosted - version: "4.0.2" - io: - dependency: transitive - description: - name: io - sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" - url: "https://pub.dev" - source: hosted - version: "1.0.4" - js: - dependency: transitive - description: - name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 - url: "https://pub.dev" - source: hosted - version: "0.6.7" - json_annotation: - dependency: transitive - description: - name: json_annotation - sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467 - url: "https://pub.dev" - source: hosted - version: "4.8.1" - logging: - dependency: transitive - description: - name: logging - sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" - url: "https://pub.dev" - source: hosted - version: "1.2.0" - matcher: - dependency: transitive - description: - name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" - url: "https://pub.dev" - source: hosted - version: "0.12.16" - material_color_utilities: - dependency: transitive - description: - name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" - url: "https://pub.dev" - source: hosted - version: "0.5.0" - meta: - dependency: transitive - description: - name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" - url: "https://pub.dev" - source: hosted - version: "1.9.1" - mime: - dependency: transitive - description: - name: mime - sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e - url: "https://pub.dev" - source: hosted - version: "1.0.4" - open_filex: - dependency: transitive - description: - name: open_filex - sha256: a6c95237767c5647e68b71a476602fcf4f1bfc530c126265e53addae22ef5fc2 - url: "https://pub.dev" - source: hosted - version: "4.3.4" - package_config: - dependency: transitive - description: - name: package_config - sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd" - url: "https://pub.dev" - source: hosted - version: "2.1.0" - package_info_plus: - dependency: transitive - description: - name: package_info_plus - sha256: "7e76fad405b3e4016cd39d08f455a4eb5199723cf594cd1b8916d47140d93017" - url: "https://pub.dev" - source: hosted - version: "4.2.0" - package_info_plus_platform_interface: - dependency: transitive - description: - name: package_info_plus_platform_interface - sha256: "9bc8ba46813a4cc42c66ab781470711781940780fd8beddd0c3da62506d3a6c6" - url: "https://pub.dev" - source: hosted - version: "2.0.1" - path: - dependency: transitive - description: - name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" - url: "https://pub.dev" - source: hosted - version: "1.8.3" - path_provider: - dependency: "direct main" - description: - name: path_provider - sha256: a1aa8aaa2542a6bc57e381f132af822420216c80d4781f7aa085ca3229208aaa - url: "https://pub.dev" - source: hosted - version: "2.1.1" - path_provider_android: - dependency: transitive - description: - name: path_provider_android - sha256: e595b98692943b4881b219f0a9e3945118d3c16bd7e2813f98ec6e532d905f72 - url: "https://pub.dev" - source: hosted - version: "2.2.1" - path_provider_foundation: - dependency: transitive - description: - name: path_provider_foundation - sha256: "19314d595120f82aca0ba62787d58dde2cc6b5df7d2f0daf72489e38d1b57f2d" - url: "https://pub.dev" - source: hosted - version: "2.3.1" - path_provider_linux: - dependency: transitive - description: - name: path_provider_linux - sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279 - url: "https://pub.dev" - source: hosted - version: "2.2.1" - path_provider_platform_interface: - dependency: transitive - description: - name: path_provider_platform_interface - sha256: "94b1e0dd80970c1ce43d5d4e050a9918fce4f4a775e6142424c30a29a363265c" - url: "https://pub.dev" - source: hosted - version: "2.1.1" - path_provider_windows: - dependency: transitive - description: - name: path_provider_windows - sha256: "8bc9f22eee8690981c22aa7fc602f5c85b497a6fb2ceb35ee5a5e5ed85ad8170" - url: "https://pub.dev" - source: hosted - version: "2.2.1" - permission_handler: - dependency: transitive - description: - name: permission_handler - sha256: "284a66179cabdf942f838543e10413246f06424d960c92ba95c84439154fcac8" - url: "https://pub.dev" - source: hosted - version: "11.0.1" - permission_handler_android: - dependency: transitive - description: - name: permission_handler_android - sha256: f9fddd3b46109bd69ff3f9efa5006d2d309b7aec0f3c1c5637a60a2d5659e76e - url: "https://pub.dev" - source: hosted - version: "11.1.0" - permission_handler_apple: - dependency: transitive - description: - name: permission_handler_apple - sha256: "99e220bce3f8877c78e4ace901082fb29fa1b4ebde529ad0932d8d664b34f3f5" - url: "https://pub.dev" - source: hosted - version: "9.1.4" - permission_handler_platform_interface: - dependency: transitive - description: - name: permission_handler_platform_interface - sha256: "6760eb5ef34589224771010805bea6054ad28453906936f843a8cc4d3a55c4a4" - url: "https://pub.dev" - source: hosted - version: "3.12.0" - permission_handler_windows: - dependency: transitive - description: - name: permission_handler_windows - sha256: cc074aace208760f1eee6aa4fae766b45d947df85bc831cde77009cdb4720098 - url: "https://pub.dev" - source: hosted - version: "0.1.3" - petitparser: - dependency: transitive - description: - name: petitparser - sha256: cb3798bef7fc021ac45b308f4b51208a152792445cce0448c9a4ba5879dd8750 - url: "https://pub.dev" - source: hosted - version: "5.4.0" - platform: - dependency: transitive - description: - name: platform - sha256: "4a451831508d7d6ca779f7ac6e212b4023dd5a7d08a27a63da33756410e32b76" - url: "https://pub.dev" - source: hosted - version: "3.1.0" - plugin_platform_interface: - dependency: transitive - description: - name: plugin_platform_interface - sha256: "6a2128648c854906c53fa8e33986fc0247a1116122f9534dd20e3ab9e16a32bc" - url: "https://pub.dev" - source: hosted - version: "2.1.4" - pool: - dependency: transitive - description: - name: pool - sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a" - url: "https://pub.dev" - source: hosted - version: "1.5.1" - process: - dependency: transitive - description: - name: process - sha256: "53fd8db9cec1d37b0574e12f07520d582019cb6c44abf5479a01505099a34a09" - url: "https://pub.dev" - source: hosted - version: "4.2.4" - pub_semver: - dependency: transitive - description: - name: pub_semver - sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c" - url: "https://pub.dev" - source: hosted - version: "2.1.4" - pubspec_parse: - dependency: transitive - description: - name: pubspec_parse - sha256: c63b2876e58e194e4b0828fcb080ad0e06d051cb607a6be51a9e084f47cb9367 - url: "https://pub.dev" - source: hosted - version: "1.2.3" - rxdart: - dependency: transitive - description: - name: rxdart - sha256: "0c7c0cedd93788d996e33041ffecda924cc54389199cde4e6a34b440f50044cb" - url: "https://pub.dev" - source: hosted - version: "0.27.7" - sensors_plus: - dependency: transitive - description: - name: sensors_plus - sha256: a1e461f28a8e8d3f81feb07d5c4e87e948379ea91f0b5131266bb79f72b38acb - url: "https://pub.dev" - source: hosted - version: "3.1.0" - sensors_plus_platform_interface: - dependency: transitive - description: - name: sensors_plus_platform_interface - sha256: "95f0cc08791b8bf0c41c5fa99c84be2a7d5bf60a811ddc17e1438b1e68caf0d3" - url: "https://pub.dev" - source: hosted - version: "1.1.3" - share_plus: - dependency: transitive - description: - name: share_plus - sha256: f74fc3f1cbd99f39760182e176802f693fa0ec9625c045561cfad54681ea93dd - url: "https://pub.dev" - source: hosted - version: "7.2.1" - share_plus_platform_interface: - dependency: transitive - description: - name: share_plus_platform_interface - sha256: df08bc3a07d01f5ea47b45d03ffcba1fa9cd5370fb44b3f38c70e42cced0f956 - url: "https://pub.dev" - source: hosted - version: "3.3.1" - shelf: - dependency: transitive - description: - name: shelf - sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4 - url: "https://pub.dev" - source: hosted - version: "1.4.1" - shelf_web_socket: - dependency: transitive - description: - name: shelf_web_socket - sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1" - url: "https://pub.dev" - source: hosted - version: "1.0.4" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - source_gen: - dependency: transitive - description: - name: source_gen - sha256: fc0da689e5302edb6177fdd964efcb7f58912f43c28c2047a808f5bfff643d16 - url: "https://pub.dev" - source: hosted - version: "1.4.0" - source_span: - dependency: transitive - description: - name: source_span - sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" - url: "https://pub.dev" - source: hosted - version: "1.10.0" - stack_trace: - dependency: transitive - description: - name: stack_trace - sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 - url: "https://pub.dev" - source: hosted - version: "1.11.0" - stream_channel: - dependency: transitive - description: - name: stream_channel - sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" - url: "https://pub.dev" - source: hosted - version: "2.1.1" - stream_transform: - dependency: transitive - description: - name: stream_transform - sha256: "14a00e794c7c11aa145a170587321aedce29769c08d7f58b1d141da75e3b1c6f" - url: "https://pub.dev" - source: hosted - version: "2.1.0" - string_scanner: - dependency: transitive - description: - name: string_scanner - sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" - url: "https://pub.dev" - source: hosted - version: "1.2.0" - term_glyph: - dependency: transitive - description: - name: term_glyph - sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 - url: "https://pub.dev" - source: hosted - version: "1.2.1" - test_api: - dependency: transitive - description: - name: test_api - sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" - url: "https://pub.dev" - source: hosted - version: "0.6.0" - timezone: - dependency: transitive - description: - name: timezone - sha256: "1cfd8ddc2d1cfd836bc93e67b9be88c3adaeca6f40a00ca999104c30693cdca0" - url: "https://pub.dev" - source: hosted - version: "0.9.2" - timing: - dependency: transitive - description: - name: timing - sha256: "70a3b636575d4163c477e6de42f247a23b315ae20e86442bebe32d3cabf61c32" - url: "https://pub.dev" - source: hosted - version: "1.0.1" - typed_data: - dependency: transitive - description: - name: typed_data - sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c - url: "https://pub.dev" - source: hosted - version: "1.3.2" - url_launcher: - dependency: transitive - description: - name: url_launcher - sha256: b1c9e98774adf8820c96fbc7ae3601231d324a7d5ebd8babe27b6dfac91357ba - url: "https://pub.dev" - source: hosted - version: "6.2.1" - url_launcher_android: - dependency: transitive - description: - name: url_launcher_android - sha256: "31222ffb0063171b526d3e569079cf1f8b294075ba323443fdc690842bfd4def" - url: "https://pub.dev" - source: hosted - version: "6.2.0" - url_launcher_ios: - dependency: transitive - description: - name: url_launcher_ios - sha256: "4ac97281cf60e2e8c5cc703b2b28528f9b50c8f7cebc71df6bdf0845f647268a" - url: "https://pub.dev" - source: hosted - version: "6.2.0" - url_launcher_linux: - dependency: transitive - description: - name: url_launcher_linux - sha256: "9f2d390e096fdbe1e6e6256f97851e51afc2d9c423d3432f1d6a02a8a9a8b9fd" - url: "https://pub.dev" - source: hosted - version: "3.1.0" - url_launcher_macos: - dependency: transitive - description: - name: url_launcher_macos - sha256: b7244901ea3cf489c5335bdacda07264a6e960b1c1b1a9f91e4bc371d9e68234 - url: "https://pub.dev" - source: hosted - version: "3.1.0" - url_launcher_platform_interface: - dependency: transitive - description: - name: url_launcher_platform_interface - sha256: "980e8d9af422f477be6948bdfb68df8433be71f5743a188968b0c1b887807e50" - url: "https://pub.dev" - source: hosted - version: "2.2.0" - url_launcher_web: - dependency: transitive - description: - name: url_launcher_web - sha256: "7fd2f55fe86cea2897b963e864dc01a7eb0719ecc65fcef4c1cc3d686d718bb2" - url: "https://pub.dev" - source: hosted - version: "2.2.0" - url_launcher_windows: - dependency: transitive - description: - name: url_launcher_windows - sha256: "7754a1ad30ee896b265f8d14078b0513a4dba28d358eabb9d5f339886f4a1adc" - url: "https://pub.dev" - source: hosted - version: "3.1.0" - uuid: - dependency: transitive - description: - name: uuid - sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313" - url: "https://pub.dev" - source: hosted - version: "3.0.7" - vector_math: - dependency: transitive - description: - name: vector_math - sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" - url: "https://pub.dev" - source: hosted - version: "2.1.4" - watcher: - dependency: transitive - description: - name: watcher - sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8" - url: "https://pub.dev" - source: hosted - version: "1.1.0" - web: - dependency: transitive - description: - name: web - sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 - url: "https://pub.dev" - source: hosted - version: "0.1.4-beta" - web_socket_channel: - dependency: transitive - description: - name: web_socket_channel - sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b - url: "https://pub.dev" - source: hosted - version: "2.4.0" - win32: - dependency: transitive - description: - name: win32 - sha256: "5a751eddf9db89b3e5f9d50c20ab8612296e4e8db69009788d6c8b060a84191c" - url: "https://pub.dev" - source: hosted - version: "4.1.4" - xdg_directories: - dependency: transitive - description: - name: xdg_directories - sha256: ee1505df1426458f7f60aac270645098d318a8b4766d85fde75f76f2e21807d1 - url: "https://pub.dev" - source: hosted - version: "1.0.0" - xml: - dependency: transitive - description: - name: xml - sha256: "5bc72e1e45e941d825fd7468b9b4cc3b9327942649aeb6fc5cdbf135f0a86e84" - url: "https://pub.dev" - source: hosted - version: "6.3.0" - yaml: - dependency: transitive - description: - name: yaml - sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" - url: "https://pub.dev" - source: hosted - version: "3.1.2" -sdks: - dart: ">=3.1.0 <4.0.0" - flutter: ">=3.13.0" diff --git a/lib/alice.dart b/lib/alice.dart index a84d20fe..26b75dbf 100644 --- a/lib/alice.dart +++ b/lib/alice.dart @@ -33,7 +33,8 @@ class Alice { ///method queue will be used to remove elements. final int maxCallsCount; - ///Directionality of app. Directionality of the app will be used if set to null. + ///Directionality of app. Directionality of the app will be used if set to + ///null. final TextDirection? directionality; ///Flag used to show/hide share button @@ -50,7 +51,7 @@ class Alice { this.showNotification = true, this.showInspectorOnShake = false, this.darkTheme = false, - this.notificationIcon = "@mipmap/ic_launcher", + this.notificationIcon = '@mipmap/ic_launcher', this.maxCallsCount = 1000, this.directionality, this.showShareButton = true, diff --git a/lib/core/alice_chopper_response_interceptor.dart b/lib/core/alice_chopper_response_interceptor.dart index 1ae3042a..24d9fabf 100644 --- a/lib/core/alice_chopper_response_interceptor.dart +++ b/lib/core/alice_chopper_response_interceptor.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:convert'; +import 'package:alice/core/alice_core.dart'; import 'package:alice/core/alice_utils.dart'; import 'package:alice/model/alice_http_call.dart'; import 'package:alice/model/alice_http_request.dart'; @@ -8,8 +9,6 @@ import 'package:alice/model/alice_http_response.dart'; import 'package:chopper/chopper.dart' as chopper; import 'package:http/http.dart'; -import 'alice_core.dart'; - class AliceChopperInterceptor implements chopper.ResponseInterceptor, chopper.RequestInterceptor { /// AliceCore instance @@ -20,7 +19,7 @@ class AliceChopperInterceptor /// Creates hashcode based on request int getRequestHashCode(BaseRequest baseRequest) { - int hashCodeSum = 0; + var hashCodeSum = 0; hashCodeSum += baseRequest.url.hashCode; hashCodeSum += baseRequest.method.hashCode; if (baseRequest.headers.isNotEmpty) { @@ -41,52 +40,58 @@ class AliceChopperInterceptor FutureOr onRequest(chopper.Request request) async { try { final baseRequest = await request.toBaseRequest(); - final AliceHttpCall call = AliceHttpCall(getRequestHashCode(baseRequest)); - String endpoint = ""; - String server = ""; + final call = AliceHttpCall(getRequestHashCode(baseRequest)); + var endpoint = ''; + var server = ''; - final List split = request.url.toString().split("/"); + final split = request.url.toString().split('/'); if (split.length > 2) { server = split[1] + split[2]; } if (split.length > 4) { - endpoint = "/"; - for (int splitIndex = 3; splitIndex < split.length; splitIndex++) { + endpoint = '/'; + for (var splitIndex = 3; splitIndex < split.length; splitIndex++) { // ignore: use_string_buffers - endpoint += "${split[splitIndex]}/"; + endpoint += '${split[splitIndex]}/'; } endpoint = endpoint.substring(0, endpoint.length - 1); } - call.method = request.method; - call.endpoint = endpoint; - call.server = server; - call.client = "Chopper"; - if (request.url.toString().contains("https")) { + call + ..method = request.method + ..endpoint = endpoint + ..server = server + ..client = 'Chopper'; + if (request.url.toString().contains('https')) { call.secure = true; } - final AliceHttpRequest aliceHttpRequest = AliceHttpRequest(); + final aliceHttpRequest = AliceHttpRequest(); if (request.body == null) { - aliceHttpRequest.size = 0; - aliceHttpRequest.body = ""; + aliceHttpRequest + ..size = 0 + ..body = ''; } else { - aliceHttpRequest.size = utf8.encode(request.body as String).length; - aliceHttpRequest.body = request.body; + aliceHttpRequest + ..size = utf8.encode(request.body as String).length + ..body = request.body; } - aliceHttpRequest.time = DateTime.now(); - aliceHttpRequest.headers = request.headers; + aliceHttpRequest + ..time = DateTime.now() + ..headers = request.headers; - String? contentType = "unknown"; - if (request.headers.containsKey("Content-Type")) { - contentType = request.headers["Content-Type"]; + String? contentType = 'unknown'; + if (request.headers.containsKey('Content-Type')) { + contentType = request.headers['Content-Type']; } - aliceHttpRequest.contentType = contentType; - aliceHttpRequest.queryParameters = request.parameters; + aliceHttpRequest + ..contentType = contentType + ..queryParameters = request.parameters; - call.request = aliceHttpRequest; - call.response = AliceHttpResponse(); + call + ..request = aliceHttpRequest + ..response = AliceHttpResponse(); aliceCore.addCall(call); } catch (exception) { @@ -97,21 +102,23 @@ class AliceChopperInterceptor /// Handles chopper response and adds data to existing alice http call @override + // ignore: strict_raw_type FutureOr onResponse(chopper.Response response) { - final httpResponse = AliceHttpResponse(); - httpResponse.status = response.statusCode; + final httpResponse = AliceHttpResponse()..status = response.statusCode; if (response.body == null) { - httpResponse.body = ""; - httpResponse.size = 0; + httpResponse + ..body = '' + ..size = 0; } else { - httpResponse.body = response.body; - httpResponse.size = utf8.encode(response.body.toString()).length; + httpResponse + ..body = response.body + ..size = utf8.encode(response.body.toString()).length; } httpResponse.time = DateTime.now(); - final Map headers = {}; + final headers = {}; response.headers.forEach((header, values) { - headers[header] = values.toString(); + headers[header] = values; }); httpResponse.headers = headers; diff --git a/lib/core/alice_core.dart b/lib/core/alice_core.dart index a9f5904b..9af7187a 100644 --- a/lib/core/alice_core.dart +++ b/lib/core/alice_core.dart @@ -50,7 +50,7 @@ class AliceCore { Brightness _brightness = Brightness.light; bool _isInspectorOpened = false; ShakeDetector? _shakeDetector; - StreamSubscription? _callsSubscription; + StreamSubscription? _callsSubscription; String? _notificationMessage; String? _notificationMessageShown; bool _notificationProcessing = false; @@ -106,19 +106,20 @@ class AliceCore { ); } - void _onCallsChanged() async { + Future _onCallsChanged() async { if (callsSubject.value.isNotEmpty) { _notificationMessage = _getNotificationMessage(); if (_notificationMessage != _notificationMessageShown && !_notificationProcessing) { await _showLocalNotification(); - _onCallsChanged(); + await _onCallsChanged(); } } } Future _onDidReceiveNotificationResponse( - NotificationResponse response) async { + NotificationResponse response, + ) async { assert(response.payload != null, "payload can't be null"); navigateToCallListScreen(); return; @@ -130,7 +131,8 @@ class AliceCore { final context = getContext(); if (context == null) { AliceUtils.log( - "Cant start Alice HTTP Inspector. Please add NavigatorKey to your application", + 'Cant start Alice HTTP Inspector. Please add NavigatorKey to your ' + 'application', ); return; } @@ -149,8 +151,8 @@ class AliceCore { BuildContext? getContext() => navigatorKey?.currentState?.overlay?.context; String _getNotificationMessage() { - final List calls = callsSubject.value; - final int successCalls = calls + final calls = callsSubject.value; + final successCalls = calls .where( (call) => call.response != null && @@ -160,7 +162,7 @@ class AliceCore { .toList() .length; - final int redirectCalls = calls + final redirectCalls = calls .where( (call) => call.response != null && @@ -170,7 +172,7 @@ class AliceCore { .toList() .length; - final int errorCalls = calls + final errorCalls = calls .where( (call) => call.response != null && @@ -180,27 +182,29 @@ class AliceCore { .toList() .length; - final int loadingCalls = - calls.where((call) => call.loading).toList().length; + final loadingCalls = calls.where((call) => call.loading).toList().length; - final StringBuffer notificationsMessage = StringBuffer(); + final notificationsMessage = StringBuffer(); if (loadingCalls > 0) { - notificationsMessage.write("Loading: $loadingCalls"); - notificationsMessage.write(" | "); + notificationsMessage + ..write('Loading: $loadingCalls') + ..write(' | '); } if (successCalls > 0) { - notificationsMessage.write("Success: $successCalls"); - notificationsMessage.write(" | "); + notificationsMessage + ..write('Success: $successCalls') + ..write(' | '); } if (redirectCalls > 0) { - notificationsMessage.write("Redirect: $redirectCalls"); - notificationsMessage.write(" | "); + notificationsMessage + ..write('Redirect: $redirectCalls') + ..write(' | '); } if (errorCalls > 0) { - notificationsMessage.write("Error: $errorCalls"); + notificationsMessage.write('Error: $errorCalls'); } - String notificationMessageString = notificationsMessage.toString(); - if (notificationMessageString.endsWith(" | ")) { + var notificationMessageString = notificationsMessage.toString(); + if (notificationMessageString.endsWith(' | ')) { notificationMessageString = notificationMessageString.substring( 0, notificationMessageString.length - 3, @@ -210,11 +214,11 @@ class AliceCore { return notificationMessageString; } - Future _showLocalNotification() async { + Future _showLocalNotification() async { _notificationProcessing = true; - const channelId = "Alice"; - const channelName = "Alice"; - const channelDescription = "Alice"; + const channelId = 'Alice'; + const channelName = 'Alice'; + const channelDescription = 'Alice'; final androidPlatformChannelSpecifics = AndroidNotificationDetails( channelId, channelName, @@ -229,13 +233,13 @@ class AliceCore { android: androidPlatformChannelSpecifics, iOS: iOSPlatformChannelSpecifics, ); - final String? message = _notificationMessage; + final message = _notificationMessage; await _flutterLocalNotificationsPlugin.show( 0, - "Alice (total: ${callsSubject.value.length} requests)", + 'Alice (total: ${callsSubject.value.length} requests)', message, platformChannelSpecifics, - payload: "", + payload: '', ); _notificationMessageShown = message; _notificationProcessing = false; @@ -247,10 +251,10 @@ class AliceCore { final callsCount = callsSubject.value.length; if (callsCount >= maxCallsCount) { final originalCalls = callsSubject.value; - final calls = List.from(originalCalls); - calls.sort( - (call1, call2) => call1.createdTime.compareTo(call2.createdTime), - ); + final calls = List.from(originalCalls) + ..sort( + (call1, call2) => call1.createdTime.compareTo(call2.createdTime), + ); final indexToReplace = originalCalls.indexOf(calls.first); originalCalls[indexToReplace] = call; @@ -262,10 +266,10 @@ class AliceCore { /// Add error to existing alice http call void addError(AliceHttpError error, int requestId) { - final AliceHttpCall? selectedCall = _selectCall(requestId); + final selectedCall = _selectCall(requestId); if (selectedCall == null) { - AliceUtils.log("Selected call is null"); + AliceUtils.log('Selected call is null'); return; } @@ -275,16 +279,17 @@ class AliceCore { /// Add response to existing alice http call void addResponse(AliceHttpResponse response, int requestId) { - final AliceHttpCall? selectedCall = _selectCall(requestId); + final selectedCall = _selectCall(requestId); if (selectedCall == null) { - AliceUtils.log("Selected call is null"); + AliceUtils.log('Selected call is null'); return; } - selectedCall.loading = false; - selectedCall.response = response; - selectedCall.duration = response.time.millisecondsSinceEpoch - - selectedCall.request!.time.millisecondsSinceEpoch; + selectedCall + ..loading = false + ..response = response + ..duration = response.time.millisecondsSinceEpoch - + selectedCall.request!.time.millisecondsSinceEpoch; callsSubject.add([...callsSubject.value]); } diff --git a/lib/core/alice_dio_interceptor.dart b/lib/core/alice_dio_interceptor.dart index 67292676..1d5ae697 100644 --- a/lib/core/alice_dio_interceptor.dart +++ b/lib/core/alice_dio_interceptor.dart @@ -19,42 +19,45 @@ class AliceDioInterceptor extends InterceptorsWrapper { /// Handles dio request and creates alice http call based on it @override void onRequest(RequestOptions options, RequestInterceptorHandler handler) { - final AliceHttpCall call = AliceHttpCall(options.hashCode); + final call = AliceHttpCall(options.hashCode); - final Uri uri = options.uri; + final uri = options.uri; call.method = options.method; var path = options.uri.path; if (path.isEmpty) { - path = "/"; + path = '/'; } - call.endpoint = path; - call.server = uri.host; - call.client = "Dio"; - call.uri = options.uri.toString(); + call + ..endpoint = path + ..server = uri.host + ..client = 'Dio' + ..uri = options.uri.toString(); - if (uri.scheme == "https") { + if (uri.scheme == 'https') { call.secure = true; } - final AliceHttpRequest request = AliceHttpRequest(); + final request = AliceHttpRequest(); final dynamic data = options.data; if (data == null) { - request.size = 0; - request.body = ""; + request + ..size = 0 + ..body = ''; } else { if (data is FormData) { - request.body += "Form data"; + // ignore: avoid_dynamic_calls + request.body += 'Form data'; if (data.fields.isNotEmpty == true) { - final List fields = []; + final fields = []; data.fields.forEach((entry) { fields.add(AliceFormDataField(entry.key, entry.value)); }); request.formDataFields = fields; } if (data.files.isNotEmpty == true) { - final List files = []; + final files = []; data.files.forEach((entry) { files.add( AliceFormDataFile( @@ -68,18 +71,21 @@ class AliceDioInterceptor extends InterceptorsWrapper { request.formDataFiles = files; } } else { - request.size = utf8.encode(data.toString()).length; - request.body = data; + request + ..size = utf8.encode(data.toString()).length + ..body = data; } } - request.time = DateTime.now(); - request.headers = options.headers; - request.contentType = options.contentType.toString(); - request.queryParameters = options.queryParameters; + request + ..time = DateTime.now() + ..headers = options.headers + ..contentType = options.contentType.toString() + ..queryParameters = options.queryParameters; - call.request = request; - call.response = AliceHttpResponse(); + call + ..request = request + ..response = AliceHttpResponse(); aliceCore.addCall(call); handler.next(options); @@ -87,20 +93,24 @@ class AliceDioInterceptor extends InterceptorsWrapper { /// Handles dio response and adds data to alice http call @override - void onResponse(Response response, ResponseInterceptorHandler handler) { - final httpResponse = AliceHttpResponse(); - httpResponse.status = response.statusCode; + void onResponse( + Response response, + ResponseInterceptorHandler handler, + ) { + final httpResponse = AliceHttpResponse()..status = response.statusCode; if (response.data == null) { - httpResponse.body = ""; - httpResponse.size = 0; + httpResponse + ..body = '' + ..size = 0; } else { - httpResponse.body = response.data; - httpResponse.size = utf8.encode(response.data.toString()).length; + httpResponse + ..body = response.data + ..size = utf8.encode(response.data.toString()).length; } httpResponse.time = DateTime.now(); - final Map headers = {}; + final headers = {}; response.headers.forEach((header, values) { headers[header] = values.toString(); }); @@ -112,17 +122,15 @@ class AliceDioInterceptor extends InterceptorsWrapper { /// Handles error and adds data to alice http call @override - void onError(DioError error, ErrorInterceptorHandler handler) { - final httpError = AliceHttpError(); - httpError.error = error.toString(); + void onError(DioException error, ErrorInterceptorHandler handler) { + final httpError = AliceHttpError()..error = error.toString(); if (error is Error) { final basicError = error as Error; httpError.stackTrace = basicError.stackTrace; } aliceCore.addError(httpError, error.requestOptions.hashCode); - final httpResponse = AliceHttpResponse(); - httpResponse.time = DateTime.now(); + final httpResponse = AliceHttpResponse()..time = DateTime.now(); if (error.response == null) { httpResponse.status = -1; aliceCore.addResponse(httpResponse, error.requestOptions.hashCode); @@ -130,13 +138,15 @@ class AliceDioInterceptor extends InterceptorsWrapper { httpResponse.status = error.response!.statusCode; if (error.response!.data == null) { - httpResponse.body = ""; - httpResponse.size = 0; + httpResponse + ..body = '' + ..size = 0; } else { - httpResponse.body = error.response!.data; - httpResponse.size = utf8.encode(error.response!.data.toString()).length; + httpResponse + ..body = error.response!.data + ..size = utf8.encode(error.response!.data.toString()).length; } - final Map headers = {}; + final headers = {}; error.response!.headers.forEach((header, values) { headers[header] = values.toString(); }); diff --git a/lib/core/alice_http_adapter.dart b/lib/core/alice_http_adapter.dart index beb2b4b6..f090e8e3 100644 --- a/lib/core/alice_http_adapter.dart +++ b/lib/core/alice_http_adapter.dart @@ -20,23 +20,23 @@ class AliceHttpAdapter { } final request = response.request!; - final AliceHttpCall call = AliceHttpCall(response.request.hashCode); - call.loading = true; - call.client = "HttpClient (http package)"; - call.uri = request.url.toString(); - call.method = request.method; + final call = AliceHttpCall(response.request.hashCode) + ..loading = true + ..client = 'HttpClient (http package)' + ..uri = request.url.toString() + ..method = request.method; var path = request.url.path; if (path.isEmpty) { - path = "/"; + path = '/'; } - call.endpoint = path; - - call.server = request.url.host; - if (request.url.scheme == "https") { + call + ..endpoint = path + ..server = request.url.host; + if (request.url.scheme == 'https') { call.secure = true; } - final AliceHttpRequest httpRequest = AliceHttpRequest(); + final httpRequest = AliceHttpRequest(); if (response.request is http.Request) { // we are guaranteed` the existence of body and headers @@ -44,47 +44,49 @@ class AliceHttpAdapter { httpRequest.body = body; } // ignore: cast_nullable_to_non_nullable - httpRequest.body = body ?? (response.request as http.Request).body ?? ""; - httpRequest.size = utf8.encode(httpRequest.body.toString()).length; - httpRequest.headers = - Map.from(response.request!.headers); + httpRequest + ..body = body ?? (response.request! as http.Request).body ?? '' + ..size = utf8.encode(httpRequest.body.toString()).length + ..headers = Map.from(response.request!.headers); } else if (body == null) { - httpRequest.size = 0; - httpRequest.body = ""; + httpRequest + ..size = 0 + ..body = ''; } else { - httpRequest.size = utf8.encode(body.toString()).length; - httpRequest.body = body; + httpRequest + ..size = utf8.encode(body.toString()).length + ..body = body; } httpRequest.time = DateTime.now(); - String? contentType = "unknown"; - if (httpRequest.headers.containsKey("Content-Type")) { - contentType = httpRequest.headers["Content-Type"] as String?; + String? contentType = 'unknown'; + if (httpRequest.headers.containsKey('Content-Type')) { + contentType = httpRequest.headers['Content-Type'] as String?; } - httpRequest.contentType = contentType; - - httpRequest.queryParameters = response.request!.url.queryParameters; - - final AliceHttpResponse httpResponse = AliceHttpResponse(); - httpResponse.status = response.statusCode; - httpResponse.body = response.body; - - httpResponse.size = utf8.encode(response.body.toString()).length; - httpResponse.time = DateTime.now(); - final Map responseHeaders = {}; + httpRequest + ..contentType = contentType + ..queryParameters = response.request!.url.queryParameters; + + final httpResponse = AliceHttpResponse() + ..status = response.statusCode + ..body = response.body + // ignore: noop_primitive_operations + ..size = utf8.encode(response.body.toString()).length + ..time = DateTime.now(); + final responseHeaders = {}; response.headers.forEach((header, values) { - responseHeaders[header] = values.toString(); + responseHeaders[header] = values; }); httpResponse.headers = responseHeaders; - call.request = httpRequest; - call.response = httpResponse; - - call.loading = false; - call.duration = httpResponse.time.millisecondsSinceEpoch - - httpRequest.time!.millisecondsSinceEpoch; + call + ..request = httpRequest + ..response = httpResponse + ..loading = false + ..duration = httpResponse.time.millisecondsSinceEpoch - + httpRequest.time.millisecondsSinceEpoch; aliceCore.addCall(call); } } diff --git a/lib/core/alice_http_client_adapter.dart b/lib/core/alice_http_client_adapter.dart index 0598fa2a..9b13e9ff 100644 --- a/lib/core/alice_http_client_adapter.dart +++ b/lib/core/alice_http_client_adapter.dart @@ -15,69 +15,75 @@ class AliceHttpClientAdapter { /// Handles httpClientRequest and creates http alice call from it void onRequest(HttpClientRequest request, {dynamic body}) { - final AliceHttpCall call = AliceHttpCall(request.hashCode); - call.loading = true; - call.client = "HttpClient (io package)"; - call.method = request.method; - call.uri = request.uri.toString(); + final call = AliceHttpCall(request.hashCode) + ..loading = true + ..client = 'HttpClient (io package)' + ..method = request.method + ..uri = request.uri.toString(); var path = request.uri.path; if (path.isEmpty) { - path = "/"; + path = '/'; } - call.endpoint = path; - call.server = request.uri.host; - if (request.uri.scheme == "https") { + call + ..endpoint = path + ..server = request.uri.host; + if (request.uri.scheme == 'https') { call.secure = true; } - final AliceHttpRequest httpRequest = AliceHttpRequest(); + final httpRequest = AliceHttpRequest(); if (body == null) { - httpRequest.size = 0; - httpRequest.body = ""; + httpRequest + ..size = 0 + ..body = ''; } else { - httpRequest.size = utf8.encode(body.toString()).length; - httpRequest.body = body; + httpRequest + ..size = utf8.encode(body.toString()).length + ..body = body; } httpRequest.time = DateTime.now(); - final Map headers = {}; + final headers = {}; httpRequest.headers.forEach((header, dynamic value) { headers[header] = value; }); httpRequest.headers = headers; - String? contentType = "unknown"; - if (headers.containsKey("Content-Type")) { - contentType = headers["Content-Type"] as String?; + String? contentType = 'unknown'; + if (headers.containsKey('Content-Type')) { + contentType = headers['Content-Type'] as String?; } - httpRequest.contentType = contentType; - httpRequest.cookies = request.cookies; + httpRequest + ..contentType = contentType + ..cookies = request.cookies; - call.request = httpRequest; - call.response = AliceHttpResponse(); + call + ..request = httpRequest + ..response = AliceHttpResponse(); aliceCore.addCall(call); } /// Handles httpClientRequest and adds response to http alice call - void onResponse( + Future onResponse( HttpClientResponse response, HttpClientRequest request, { dynamic body, }) async { - final AliceHttpResponse httpResponse = AliceHttpResponse(); - httpResponse.status = response.statusCode; + final httpResponse = AliceHttpResponse()..status = response.statusCode; if (body != null) { - httpResponse.body = body; - httpResponse.size = utf8.encode(body.toString()).length; + httpResponse + ..body = body + ..size = utf8.encode(body.toString()).length; } else { - httpResponse.body = ""; - httpResponse.size = 0; + httpResponse + ..body = '' + ..size = 0; } httpResponse.time = DateTime.now(); - final Map headers = {}; + final headers = {}; response.headers.forEach((header, values) { headers[header] = values.toString(); }); diff --git a/lib/core/alice_http_client_extensions.dart b/lib/core/alice_http_client_extensions.dart index 39a42464..5b478f68 100644 --- a/lib/core/alice_http_client_extensions.dart +++ b/lib/core/alice_http_client_extensions.dart @@ -5,14 +5,14 @@ import 'dart:io'; import 'package:alice/alice.dart'; extension AliceHttpClientExtensions on Future { - /// Intercept http client with alice. This extension method provides additional - /// helpful method to intercept httpClientResponse. + /// Intercept http client with alice. This extension method provides + /// additional helpful method to intercept httpClientResponse. Future interceptWithAlice( Alice alice, { dynamic body, Map? headers, }) async { - final HttpClientRequest request = await this; + final request = await this; if (body != null) { request.write(body); } diff --git a/lib/core/alice_http_extensions.dart b/lib/core/alice_http_extensions.dart index 0f1d8504..ddf0b000 100644 --- a/lib/core/alice_http_extensions.dart +++ b/lib/core/alice_http_extensions.dart @@ -2,10 +2,10 @@ import 'package:alice/alice.dart'; import 'package:http/http.dart'; extension AliceHttpExtensions on Future { - /// Intercept http request with alice. This extension method provides additional - /// helpful method to intercept https' response. + /// Intercept http request with alice. This extension method provides + /// additional helpful method to intercept https' response. Future interceptWithAlice(Alice alice, {dynamic body}) async { - final Response response = await this; + final response = await this; alice.onHttpResponse(response, body: body); return response; } diff --git a/lib/core/alice_logger.dart b/lib/core/alice_logger.dart index 19908590..13877734 100644 --- a/lib/core/alice_logger.dart +++ b/lib/core/alice_logger.dart @@ -16,8 +16,8 @@ class AliceLogger { /// The maximum number of logs to store or `null` for unlimited storage. /// - /// If more logs arrive, the oldest ones (based on their [AliceLog.timestamp]) will - /// be removed. + /// If more logs arrive, the oldest ones (based on their [ + /// AliceLog.timestamp]) will be removed. int? get maximumSize => _maximumSize; set maximumSize(int? value) { @@ -46,7 +46,7 @@ class AliceLogger { min = mid + 1; } } - assert(min == max); + assert(min == max, ''); index = min; } diff --git a/lib/helper/alice_alert_helper.dart b/lib/helper/alice_alert_helper.dart index a293d824..e0b69c60 100644 --- a/lib/helper/alice_alert_helper.dart +++ b/lib/helper/alice_alert_helper.dart @@ -6,31 +6,28 @@ class AliceAlertHelper { BuildContext context, String title, String description, { - String firstButtonTitle = "Accept", + String firstButtonTitle = 'Accept', String? secondButtonTitle, Function? firstButtonAction, Function? secondButtonAction, Brightness? brightness, }) { - final List actions = []; - actions.add( + final actions = [ TextButton( onPressed: () { - if (firstButtonAction != null) { - firstButtonAction(); - } + // ignore: avoid_dynamic_calls + firstButtonAction?.call(); Navigator.of(context).pop(); }, child: Text(firstButtonTitle), ), - ); + ]; if (secondButtonTitle != null) { actions.add( TextButton( onPressed: () { - if (secondButtonAction != null) { - secondButtonAction(); - } + // ignore: avoid_dynamic_calls + secondButtonAction?.call(); Navigator.of(context).pop(); }, child: Text(secondButtonTitle), diff --git a/lib/helper/alice_conversion_helper.dart b/lib/helper/alice_conversion_helper.dart index e16e2b01..b67d371a 100644 --- a/lib/helper/alice_conversion_helper.dart +++ b/lib/helper/alice_conversion_helper.dart @@ -7,16 +7,16 @@ class AliceConversionHelper { /// Format bytes text static String formatBytes(int bytes) { if (bytes < 0) { - return "-1 B"; + return '-1 B'; } if (bytes <= _kilobyteAsByte) { - return "$bytes B"; + return '$bytes B'; } if (bytes <= _megabyteAsByte) { - return "${_formatDouble(bytes / _kilobyteAsByte)} kB"; + return '${_formatDouble(bytes / _kilobyteAsByte)} kB'; } - return "${_formatDouble(bytes / _megabyteAsByte)} MB"; + return '${_formatDouble(bytes / _megabyteAsByte)} MB'; } static String _formatDouble(double value) => value.toStringAsFixed(2); @@ -24,18 +24,18 @@ class AliceConversionHelper { /// Format time in milliseconds static String formatTime(int timeInMillis) { if (timeInMillis < 0) { - return "-1 ms"; + return '-1 ms'; } if (timeInMillis <= _secondAsMillisecond) { - return "$timeInMillis ms"; + return '$timeInMillis ms'; } if (timeInMillis <= _minuteAsMillisecond) { - return "${_formatDouble(timeInMillis / _secondAsMillisecond)} s"; + return '${_formatDouble(timeInMillis / _secondAsMillisecond)} s'; } - final Duration duration = Duration(milliseconds: timeInMillis); + final duration = Duration(milliseconds: timeInMillis); - return "${duration.inMinutes} min ${duration.inSeconds.remainder(60)} s " - "${duration.inMilliseconds.remainder(1000)} ms"; + return '${duration.inMinutes} min ${duration.inSeconds.remainder(60)} s ' + '${duration.inMilliseconds.remainder(1000)} ms'; } } diff --git a/lib/helper/alice_save_helper.dart b/lib/helper/alice_save_helper.dart index 7d2510df..5bed4df8 100644 --- a/lib/helper/alice_save_helper.dart +++ b/lib/helper/alice_save_helper.dart @@ -25,14 +25,14 @@ class AliceSaveHelper { _checkPermissions(context, calls, brightness); } - static void _checkPermissions( + static Future _checkPermissions( BuildContext context, List calls, Brightness brightness, ) async { final status = await Permission.storage.status; if (status.isGranted) { - _saveToFile( + await _saveToFile( context, calls, brightness, @@ -41,11 +41,11 @@ class AliceSaveHelper { final status = await Permission.storage.request(); if (status.isGranted) { - _saveToFile(context, calls, brightness); + await _saveToFile(context, calls, brightness); } else { AliceAlertHelper.showAlert( context, - "Permission error", + 'Permission error', "Permission not granted. Couldn't save logs.", brightness: brightness, ); @@ -62,13 +62,13 @@ class AliceSaveHelper { if (calls.isEmpty) { AliceAlertHelper.showAlert( context, - "Error", - "There are no logs to save", + 'Error', + 'There are no logs to save', brightness: brightness, ); - return ""; + return ''; } - final bool isAndroid = Platform.isAndroid; + final isAndroid = Platform.isAndroid; Directory? externalDir; if (isAndroid) { @@ -77,12 +77,11 @@ class AliceSaveHelper { externalDir = await getApplicationDocumentsDirectory(); } if (externalDir != null) { - final String fileName = - "alice_log_${DateTime.now().millisecondsSinceEpoch}.txt"; - final File file = File("${externalDir.path}/$fileName"); - file.createSync(); - final IOSink sink = file.openWrite(mode: FileMode.append); - sink.write(await _buildAliceLog()); + final fileName = + 'alice_log_${DateTime.now().millisecondsSinceEpoch}.txt'; + final file = File('${externalDir.path}/$fileName')..createSync(); + final sink = file.openWrite(mode: FileMode.append) + ..write(await _buildAliceLog()); calls.forEach((AliceHttpCall call) { sink.write(_buildCallLog(call)); }); @@ -90,9 +89,9 @@ class AliceSaveHelper { await sink.close(); AliceAlertHelper.showAlert( context, - "Success", - "Successfully saved logs in ${file.path}", - secondButtonTitle: isAndroid ? "View file" : null, + 'Success', + 'Successfully saved logs in ${file.path}', + secondButtonTitle: isAndroid ? 'View file' : null, secondButtonAction: () => isAndroid ? OpenFilex.open(file.path) : null, brightness: brightness, @@ -101,102 +100,112 @@ class AliceSaveHelper { } else { AliceAlertHelper.showAlert( context, - "Error", - "Failed to save http calls to file", + 'Error', + 'Failed to save http calls to file', ); } } catch (exception) { AliceAlertHelper.showAlert( context, - "Error", - "Failed to save http calls to file", + 'Error', + 'Failed to save http calls to file', brightness: brightness, ); AliceUtils.log(exception.toString()); } - return ""; + return ''; } static Future _buildAliceLog() async { - final StringBuffer stringBuffer = StringBuffer(); + final stringBuffer = StringBuffer(); final packageInfo = await PackageInfo.fromPlatform(); - stringBuffer.write("Alice - HTTP Inspector\n"); - stringBuffer.write("App name: ${packageInfo.appName}\n"); - stringBuffer.write("Package: ${packageInfo.packageName}\n"); - stringBuffer.write("Version: ${packageInfo.version}\n"); - stringBuffer.write("Build number: ${packageInfo.buildNumber}\n"); - stringBuffer.write("Generated: ${DateTime.now().toIso8601String()}\n"); - stringBuffer.write("\n"); + stringBuffer + ..write('Alice - HTTP Inspector\n') + ..write('App name: ${packageInfo.appName}\n') + ..write('Package: ${packageInfo.packageName}\n') + ..write('Version: ${packageInfo.version}\n') + ..write('Build number: ${packageInfo.buildNumber}\n') + ..write('Generated: ${DateTime.now().toIso8601String()}\n') + ..write('\n'); return stringBuffer.toString(); } static String _buildCallLog(AliceHttpCall call) { - final StringBuffer stringBuffer = StringBuffer(); - stringBuffer.write("===========================================\n"); - stringBuffer.write("Id: ${call.id}\n"); - stringBuffer.write("============================================\n"); - stringBuffer.write("--------------------------------------------\n"); - stringBuffer.write("General data\n"); - stringBuffer.write("--------------------------------------------\n"); - stringBuffer.write("Server: ${call.server} \n"); - stringBuffer.write("Method: ${call.method} \n"); - stringBuffer.write("Endpoint: ${call.endpoint} \n"); - stringBuffer.write("Client: ${call.client} \n"); - stringBuffer - .write("Duration ${AliceConversionHelper.formatTime(call.duration)}\n"); - stringBuffer.write("Secured connection: ${call.secure}\n"); - stringBuffer.write("Completed: ${!call.loading} \n"); - stringBuffer.write("--------------------------------------------\n"); - stringBuffer.write("Request\n"); - stringBuffer.write("--------------------------------------------\n"); - stringBuffer.write("Request time: ${call.request!.time}\n"); - stringBuffer.write("Request content type: ${call.request!.contentType}\n"); - stringBuffer - .write("Request cookies: ${_encoder.convert(call.request!.cookies)}\n"); - stringBuffer - .write("Request headers: ${_encoder.convert(call.request!.headers)}\n"); + final stringBuffer = StringBuffer() + ..write('===========================================\n') + ..write('Id: ${call.id}\n') + ..write('============================================\n') + ..write('--------------------------------------------\n') + ..write('General data\n') + ..write('--------------------------------------------\n') + ..write('Server: ${call.server} \n') + ..write('Method: ${call.method} \n') + ..write('Endpoint: ${call.endpoint} \n') + ..write('Client: ${call.client} \n') + ..write('Duration ${AliceConversionHelper.formatTime(call.duration)}\n') + ..write('Secured connection: ${call.secure}\n') + ..write('Completed: ${!call.loading} \n') + ..write('--------------------------------------------\n') + ..write('Request\n') + ..write('--------------------------------------------\n') + ..write('Request time: ${call.request!.time}\n') + ..write('Request content type: ${call.request!.contentType}\n') + ..write('Request cookies: ${_encoder.convert(call.request!.cookies)}\n') + ..write('Request headers: ${_encoder.convert(call.request!.headers)}\n'); if (call.request!.queryParameters.isNotEmpty) { stringBuffer.write( - "Request query params: ${_encoder.convert(call.request!.queryParameters)}\n", + 'Request query params: ' + '${_encoder.convert(call.request!.queryParameters)}\n', ); } - stringBuffer.write( - "Request size: ${AliceConversionHelper.formatBytes(call.request!.size)}\n", - ); - stringBuffer.write( - "Request body: ${AliceParser.formatBody(call.request!.body, AliceParser.getContentType(call.request!.headers))}\n", - ); - stringBuffer.write("--------------------------------------------\n"); - stringBuffer.write("Response\n"); - stringBuffer.write("--------------------------------------------\n"); - stringBuffer.write("Response time: ${call.response!.time}\n"); - stringBuffer.write("Response status: ${call.response!.status}\n"); - stringBuffer.write( - "Response size: ${AliceConversionHelper.formatBytes(call.response!.size)}\n", - ); - stringBuffer.write( - "Response headers: ${_encoder.convert(call.response!.headers)}\n", - ); - stringBuffer.write( - "Response body: ${AliceParser.formatBody(call.response!.body, AliceParser.getContentType(call.response!.headers))}\n", - ); + stringBuffer + ..write( + 'Request size: ' + '${AliceConversionHelper.formatBytes(call.request!.size)}\n', + ) + ..write( + 'Request body: ${AliceParser.formatBody( + call.request!.body, + AliceParser.getContentType(call.request!.headers), + )}\n', + ) + ..write('--------------------------------------------\n') + ..write('Response\n') + ..write('--------------------------------------------\n') + ..write('Response time: ${call.response!.time}\n') + ..write('Response status: ${call.response!.status}\n') + ..write( + 'Response size: ' + '${AliceConversionHelper.formatBytes(call.response!.size)}\n', + ) + ..write( + 'Response headers: ${_encoder.convert(call.response!.headers)}\n', + ) + ..write( + 'Response body: ${AliceParser.formatBody( + call.response!.body, + AliceParser.getContentType(call.response!.headers), + )}\n', + ); if (call.error != null) { - stringBuffer.write("--------------------------------------------\n"); - stringBuffer.write("Error\n"); - stringBuffer.write("--------------------------------------------\n"); - stringBuffer.write("Error: ${call.error!.error}\n"); + stringBuffer + ..write('--------------------------------------------\n') + ..write('Error\n') + ..write('--------------------------------------------\n') + ..write('Error: ${call.error!.error}\n'); if (call.error!.stackTrace != null) { - stringBuffer.write("Error stacktrace: ${call.error!.stackTrace}\n"); + stringBuffer.write('Error stacktrace: ${call.error!.stackTrace}\n'); } } - stringBuffer.write("--------------------------------------------\n"); - stringBuffer.write("Curl\n"); - stringBuffer.write("--------------------------------------------\n"); - stringBuffer.write(call.getCurlCommand()); - stringBuffer.write("\n"); - stringBuffer.write("==============================================\n"); - stringBuffer.write("\n"); + stringBuffer + ..write('--------------------------------------------\n') + ..write('Curl\n') + ..write('--------------------------------------------\n') + ..write(call.getCurlCommand()) + ..write('\n') + ..write('==============================================\n') + ..write('\n'); return stringBuffer.toString(); } @@ -205,7 +214,7 @@ class AliceSaveHelper { try { return await _buildAliceLog() + _buildCallLog(call); } catch (exception) { - return "Failed to generate call log"; + return 'Failed to generate call log'; } } } diff --git a/lib/model/alice_http_call.dart b/lib/model/alice_http_call.dart index 217530ab..2193a765 100644 --- a/lib/model/alice_http_call.dart +++ b/lib/model/alice_http_call.dart @@ -5,13 +5,13 @@ import 'package:alice/model/alice_http_response.dart'; class AliceHttpCall { final int id; late DateTime createdTime; - String client = ""; + String client = ''; bool loading = true; bool secure = false; - String method = ""; - String endpoint = ""; - String server = ""; - String uri = ""; + String method = ''; + String endpoint = ''; + String server = ''; + String uri = ''; int duration = 0; AliceHttpRequest? request; @@ -30,45 +30,45 @@ class AliceHttpCall { String getCurlCommand() { var compressed = false; - var curlCmd = "curl"; - curlCmd += " -X $method"; - final headers = request!.headers; - headers.forEach((key, dynamic value) { - if ("Accept-Encoding" == key && "gzip" == value) { + var curlCmd = 'curl'; + curlCmd += ' -X $method'; + request!.headers.forEach((key, dynamic value) { + if ('Accept-Encoding' == key && 'gzip' == value) { compressed = true; } curlCmd += " -H '$key: $value'"; }); - final String requestBody = request!.body.toString(); + final requestBody = request!.body.toString(); if (requestBody != '') { - // try to keep to a single line and use a subshell to preserve any line breaks - curlCmd += " --data \$'${requestBody.replaceAll("\n", "\\n")}'"; + // try to keep to a single line and use a subshell to preserve any line + // breaks + curlCmd += " --data \$'${requestBody.replaceAll("\n", r"\n")}'"; } final queryParamMap = request!.queryParameters; - int paramCount = queryParamMap.keys.length; - var queryParams = ""; + var paramCount = queryParamMap.keys.length; + var queryParams = ''; if (paramCount > 0) { - queryParams += "?"; + queryParams += '?'; queryParamMap.forEach((key, dynamic value) { queryParams += '$key=$value'; paramCount -= 1; if (paramCount > 0) { - queryParams += "&"; + queryParams += '&'; } }); } // If server already has http(s) don't add it again - if (server.contains("http://") || server.contains("https://")) { + if (server.contains('http://') || server.contains('https://')) { // ignore: join_return_with_assignment - curlCmd += - "${compressed ? " --compressed " : " "}${"'$server$endpoint$queryParams'"}"; + curlCmd += "${compressed ? " --compressed " : " "}${"'$server" + "$endpoint$queryParams'"}"; } else { // ignore: join_return_with_assignment - curlCmd += - "${compressed ? " --compressed " : " "}${"'${secure ? 'https://' : 'http://'}$server$endpoint$queryParams'"}"; + curlCmd += "${compressed ? " --compressed " : " "}${"'" + "${secure ? 'https://' : 'http://'}$server$endpoint$queryParams'"}"; } return curlCmd; diff --git a/lib/model/alice_http_request.dart b/lib/model/alice_http_request.dart index 49715a5f..d9298ccb 100644 --- a/lib/model/alice_http_request.dart +++ b/lib/model/alice_http_request.dart @@ -7,8 +7,8 @@ class AliceHttpRequest { int size = 0; DateTime time = DateTime.now(); Map headers = {}; - dynamic body = ""; - String? contentType = ""; + dynamic body = ''; + String? contentType = ''; List cookies = []; Map queryParameters = {}; List? formDataFiles; diff --git a/lib/model/alice_log.dart b/lib/model/alice_log.dart index 87392930..4f367ada 100644 --- a/lib/model/alice_log.dart +++ b/lib/model/alice_log.dart @@ -3,17 +3,16 @@ import 'package:flutter/foundation.dart'; @immutable class AliceLog { AliceLog({ + required this.message, this.level = DiagnosticLevel.info, DateTime? timestamp, - required this.message, this.error, this.stackTrace, }) : assert( - level != DiagnosticLevel.off, - '`DiagnosticLevel.off` is a "[special] level indicating that no ' - 'diagnostics should be shown" and should not be used as a value.', - ), - assert(timestamp == null || !timestamp.isUtc), + level != DiagnosticLevel.off, + "`DiagnosticLevel.off` is a '[special] level indicating that no " + "diagnostics should be shown' and should not be used as a value."), + assert(timestamp == null || !timestamp.isUtc, 'Invalid timestamp'), timestamp = timestamp ?? DateTime.now(); final DiagnosticLevel level; diff --git a/lib/model/alice_sort_option.dart b/lib/model/alice_sort_option.dart index 3c1c009c..c82c26c2 100644 --- a/lib/model/alice_sort_option.dart +++ b/lib/model/alice_sort_option.dart @@ -11,15 +11,15 @@ extension AliceSortOptionsExtension on AliceSortOption { String get name { switch (this) { case AliceSortOption.time: - return "Create time (default)"; + return 'Create time (default)'; case AliceSortOption.responseTime: - return "Response time"; + return 'Response time'; case AliceSortOption.responseCode: - return "Response code"; + return 'Response code'; case AliceSortOption.responseSize: - return "Response size"; + return 'Response size'; case AliceSortOption.endpoint: - return "Endpoint"; + return 'Endpoint'; } } } diff --git a/lib/ui/page/alice_call_details_screen.dart b/lib/ui/page/alice_call_details_screen.dart index c2ea944d..60c81bb0 100644 --- a/lib/ui/page/alice_call_details_screen.dart +++ b/lib/ui/page/alice_call_details_screen.dart @@ -1,11 +1,11 @@ import 'package:alice/core/alice_core.dart'; import 'package:alice/helper/alice_save_helper.dart'; import 'package:alice/model/alice_http_call.dart'; -import 'package:alice/utils/alice_constants.dart'; import 'package:alice/ui/widget/alice_call_error_widget.dart'; import 'package:alice/ui/widget/alice_call_overview_widget.dart'; import 'package:alice/ui/widget/alice_call_request_widget.dart'; import 'package:alice/ui/widget/alice_call_response_widget.dart'; +import 'package:alice/utils/alice_constants.dart'; import 'package:collection/collection.dart' show IterableExtension; import 'package:flutter/material.dart'; import 'package:share_plus/share_plus.dart'; @@ -14,10 +14,12 @@ class AliceCallDetailsScreen extends StatefulWidget { final AliceHttpCall call; final AliceCore core; - const AliceCallDetailsScreen(this.call, this.core); + const AliceCallDetailsScreen(this.call, this.core, {super.key}); @override - _AliceCallDetailsScreenState createState() => _AliceCallDetailsScreenState(); + State createState() { + return _AliceCallDetailsScreenState(); + } } class _AliceCallDetailsScreenState extends State @@ -43,7 +45,7 @@ class _AliceCallDetailsScreenState extends State initialData: [widget.call], builder: (context, callsSnapshot) { if (callsSnapshot.hasData) { - final AliceHttpCall? call = callsSnapshot.data!.firstWhereOrNull( + final call = callsSnapshot.data!.firstWhereOrNull( (snapshotCall) => snapshotCall.id == widget.call.id, ); if (call != null) { @@ -69,7 +71,7 @@ class _AliceCallDetailsScreenState extends State backgroundColor: AliceConstants.lightRed, key: const Key('share_key'), onPressed: () async { - Share.share( + await Share.share( await _getSharableResponseString(), subject: 'Request Details', ); @@ -95,7 +97,7 @@ class _AliceCallDetailsScreenState extends State } Widget _buildErrorWidget() { - return const Center(child: Text("Failed to load data")); + return const Center(child: Text('Failed to load data')); } Future _getSharableResponseString() async { @@ -103,25 +105,23 @@ class _AliceCallDetailsScreenState extends State } List _getTabBars() { - final List widgets = []; - widgets.add(const Tab(icon: Icon(Icons.info_outline), text: "Overview")); - widgets.add(const Tab(icon: Icon(Icons.arrow_upward), text: "Request")); - widgets.add(const Tab(icon: Icon(Icons.arrow_downward), text: "Response")); - widgets.add( + return [ + const Tab(icon: Icon(Icons.info_outline), text: 'Overview'), + const Tab(icon: Icon(Icons.arrow_upward), text: 'Request'), + const Tab(icon: Icon(Icons.arrow_downward), text: 'Response'), const Tab( icon: Icon(Icons.warning), - text: "Error", + text: 'Error', ), - ); - return widgets; + ]; } List _getTabBarViewList() { - final List widgets = []; - widgets.add(AliceCallOverviewWidget(widget.call)); - widgets.add(AliceCallRequestWidget(widget.call)); - widgets.add(AliceCallResponseWidget(widget.call)); - widgets.add(AliceCallErrorWidget(widget.call)); - return widgets; + return [ + AliceCallOverviewWidget(widget.call), + AliceCallRequestWidget(widget.call), + AliceCallResponseWidget(widget.call), + AliceCallErrorWidget(widget.call), + ]; } } diff --git a/lib/ui/page/alice_calls_list_screen.dart b/lib/ui/page/alice_calls_list_screen.dart index 498acc48..21d96ca6 100644 --- a/lib/ui/page/alice_calls_list_screen.dart +++ b/lib/ui/page/alice_calls_list_screen.dart @@ -6,22 +6,23 @@ import 'package:alice/model/alice_menu_item.dart'; import 'package:alice/model/alice_sort_option.dart'; import 'package:alice/model/alice_tab_item.dart'; import 'package:alice/ui/page/alice_call_details_screen.dart'; +import 'package:alice/ui/page/alice_stats_screen.dart'; import 'package:alice/ui/widget/alice_call_list_item_widget.dart'; import 'package:alice/ui/widget/alice_log_list_widget.dart'; import 'package:alice/ui/widget/alice_raw_log_list_widger.dart'; import 'package:alice/utils/alice_constants.dart'; import 'package:flutter/material.dart'; -import 'alice_stats_screen.dart'; - class AliceCallsListScreen extends StatefulWidget { final AliceCore _aliceCore; final AliceLogger? _aliceLogger; - const AliceCallsListScreen(this._aliceCore, this._aliceLogger); + const AliceCallsListScreen(this._aliceCore, this._aliceLogger, {super.key}); @override - _AliceCallsListScreenState createState() => _AliceCallsListScreenState(); + State createState() { + return _AliceCallsListScreenState(); + } } class _AliceCallsListScreenState extends State @@ -43,10 +44,12 @@ class _AliceCallsListScreenState extends State AliceCore get aliceCore => widget._aliceCore; _AliceCallsListScreenState() { - _menuItems.add(AliceMenuItem("Sort", Icons.sort)); - _menuItems.add(AliceMenuItem("Delete", Icons.delete)); - _menuItems.add(AliceMenuItem("Stats", Icons.insert_chart)); - _menuItems.add(AliceMenuItem("Save", Icons.save)); + _menuItems.addAll([ + AliceMenuItem('Sort', Icons.sort), + AliceMenuItem('Delete', Icons.delete), + AliceMenuItem('Stats', Icons.insert_chart), + AliceMenuItem('Save', Icons.save), + ]); } @override @@ -92,7 +95,7 @@ class _AliceCallsListScreenState extends State indicatorColor: AliceConstants.orange, tabs: [ for (final item in _tabItems) - Tab(text: item.title.toUpperCase()) + Tab(text: item.title.toUpperCase()), ], ), ), @@ -127,21 +130,22 @@ class _AliceCallsListScreenState extends State mainAxisAlignment: MainAxisAlignment.end, children: [ FloatingActionButton( - heroTag: 'h1', - child: Icon(Icons.arrow_upward, color: AliceConstants.white), - backgroundColor: AliceConstants.orange, - onPressed: () { - _scrollLogsList(true); - }), + heroTag: 'h1', + backgroundColor: AliceConstants.orange, + onPressed: () { + _scrollLogsList(true); + }, + child: Icon(Icons.arrow_upward, color: AliceConstants.white), + ), const SizedBox(height: 8), FloatingActionButton( - heroTag: 'h2', - child: - Icon(Icons.arrow_downward, color: AliceConstants.white), - backgroundColor: AliceConstants.orange, - onPressed: () { - _scrollLogsList(false); - }), + heroTag: 'h2', + backgroundColor: AliceConstants.orange, + onPressed: () { + _scrollLogsList(false); + }, + child: Icon(Icons.arrow_downward, color: AliceConstants.white), + ), ], ) : const SizedBox(); @@ -171,10 +175,10 @@ class _AliceCallsListScreenState extends State void _showClearLogsDialog() { AliceAlertHelper.showAlert( context, - "Delete logs", - "Do you want to clear logs?", - firstButtonTitle: "No", - secondButtonTitle: "Yes", + 'Delete logs', + 'Do you want to clear logs?', + firstButtonTitle: 'No', + secondButtonTitle: 'Yes', secondButtonAction: _onLogsClearClicked, ); } @@ -199,7 +203,7 @@ class _AliceCallsListScreenState extends State setState(() { _searchEnabled = !_searchEnabled; if (!_searchEnabled) { - _queryTextEditingController.text = ""; + _queryTextEditingController.text = ''; } }); } @@ -209,14 +213,14 @@ class _AliceCallsListScreenState extends State _selectedIndex = index; if (_selectedIndex == 1) { _searchEnabled = false; - _queryTextEditingController.text = ""; + _queryTextEditingController.text = ''; } }); } Widget _buildMenuButton() { return PopupMenuButton( - onSelected: (AliceMenuItem item) => _onMenuItemSelected(item), + onSelected: _onMenuItemSelected, itemBuilder: (BuildContext context) { return _menuItems.map((AliceMenuItem item) { return PopupMenuItem( @@ -230,7 +234,7 @@ class _AliceCallsListScreenState extends State const Padding( padding: EdgeInsets.only(left: 10), ), - Text(item.title) + Text(item.title), ], ), ); @@ -240,7 +244,7 @@ class _AliceCallsListScreenState extends State } Widget _buildTitleWidget() { - return const Text("Alice"); + return const Text('Alice'); } Widget _buildSearchField() { @@ -248,26 +252,26 @@ class _AliceCallsListScreenState extends State controller: _queryTextEditingController, autofocus: true, decoration: InputDecoration( - hintText: "Search http request...", - hintStyle: TextStyle(fontSize: 16.0, color: AliceConstants.grey), + hintText: 'Search http request...', + hintStyle: TextStyle(fontSize: 16, color: AliceConstants.grey), border: InputBorder.none, ), - style: const TextStyle(fontSize: 16.0), + style: const TextStyle(fontSize: 16), onChanged: _updateSearchQuery, ); } void _onMenuItemSelected(AliceMenuItem menuItem) { - if (menuItem.title == "Sort") { + if (menuItem.title == 'Sort') { _showSortDialog(); } - if (menuItem.title == "Delete") { + if (menuItem.title == 'Delete') { _showRemoveDialog(); } - if (menuItem.title == "Stats") { + if (menuItem.title == 'Stats') { _showStatsScreen(); } - if (menuItem.title == "Save") { + if (menuItem.title == 'Save') { _saveToFile(); } } @@ -276,8 +280,8 @@ class _AliceCallsListScreenState extends State return StreamBuilder>( stream: aliceCore.callsSubject, builder: (context, snapshot) { - List calls = snapshot.data ?? []; - final String query = _queryTextEditingController.text.trim(); + var calls = snapshot.data ?? []; + final query = _queryTextEditingController.text.trim(); if (query.isNotEmpty) { calls = calls .where( @@ -308,30 +312,30 @@ class _AliceCallsListScreenState extends State ), const SizedBox(height: 6), const Text( - "There are no calls to show", + 'There are no calls to show', style: TextStyle(fontSize: 18), ), const SizedBox(height: 12), - Column( + const Column( crossAxisAlignment: CrossAxisAlignment.start, - children: const [ + children: [ Text( - "• Check if you send any http request", + '• Check if you send any http request', style: TextStyle(fontSize: 12), textAlign: TextAlign.center, ), Text( - "• Check your Alice configuration", + '• Check your Alice configuration', style: TextStyle(fontSize: 12), textAlign: TextAlign.center, ), Text( - "• Check search filters", + '• Check search filters', style: TextStyle(fontSize: 12), textAlign: TextAlign.center, - ) + ), ], - ) + ), ], ), ), @@ -339,7 +343,7 @@ class _AliceCallsListScreenState extends State } Widget _buildCallsListWidget(List calls) { - final List callsSorted = List.of(calls); + final callsSorted = List.of(calls); switch (_sortOption) { case AliceSortOption.time: if (_sortAscending) { @@ -351,21 +355,20 @@ class _AliceCallsListScreenState extends State (call1, call2) => call2.createdTime.compareTo(call1.createdTime), ); } - break; case AliceSortOption.responseTime: if (_sortAscending) { - callsSorted.sort(); - callsSorted.sort( - (call1, call2) => - call1.response?.time.compareTo(call2.response!.time) ?? -1, - ); + callsSorted + ..sort() + ..sort( + (call1, call2) => + call1.response?.time.compareTo(call2.response!.time) ?? -1, + ); } else { callsSorted.sort( (call1, call2) => call2.response?.time.compareTo(call1.response!.time) ?? -1, ); } - break; case AliceSortOption.responseCode: if (_sortAscending) { callsSorted.sort( @@ -380,7 +383,6 @@ class _AliceCallsListScreenState extends State -1, ); } - break; case AliceSortOption.responseSize: if (_sortAscending) { callsSorted.sort( @@ -393,7 +395,6 @@ class _AliceCallsListScreenState extends State call2.response?.size.compareTo(call1.response!.size) ?? -1, ); } - break; case AliceSortOption.endpoint: if (_sortAscending) { callsSorted @@ -402,9 +403,8 @@ class _AliceCallsListScreenState extends State callsSorted .sort((call1, call2) => call2.endpoint.compareTo(call1.endpoint)); } - break; - default: - break; + + case null: } return ListView.builder( @@ -427,12 +427,12 @@ class _AliceCallsListScreenState extends State void _showRemoveDialog() { AliceAlertHelper.showAlert( context, - "Delete calls", - "Do you want to delete http calls?", - firstButtonTitle: "No", + 'Delete calls', + 'Do you want to delete http calls?', + firstButtonTitle: 'No', firstButtonAction: () => {}, - secondButtonTitle: "Yes", - secondButtonAction: () => _removeCalls(), + secondButtonTitle: 'Yes', + secondButtonAction: _removeCalls, ); } @@ -449,7 +449,7 @@ class _AliceCallsListScreenState extends State ); } - void _saveToFile() async { + Future _saveToFile() async { aliceCore.saveHttpRequests(context); } @@ -466,30 +466,28 @@ class _AliceCallsListScreenState extends State brightness: Brightness.light, ), child: AlertDialog( - title: const Text("Select filter"), + title: const Text('Select filter'), content: StatefulBuilder( builder: (context, setState) { return Wrap( children: [ - ...AliceSortOption.values - .map( - (AliceSortOption sortOption) => - RadioListTile( - title: Text(sortOption.name), - value: sortOption, - groupValue: _sortOption, - onChanged: (AliceSortOption? value) { - setState(() { - _sortOption = value; - }); - }, - ), - ) - .toList(), + ...AliceSortOption.values.map( + (AliceSortOption sortOption) => + RadioListTile( + title: Text(sortOption.name), + value: sortOption, + groupValue: _sortOption, + onChanged: (AliceSortOption? value) { + setState(() { + _sortOption = value; + }); + }, + ), + ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Text("Descending"), + const Text('Descending'), Switch( value: _sortAscending, onChanged: (value) { @@ -500,9 +498,9 @@ class _AliceCallsListScreenState extends State activeTrackColor: Colors.grey, activeColor: Colors.white, ), - const Text("Ascending") + const Text('Ascending'), ], - ) + ), ], ); }, @@ -512,14 +510,14 @@ class _AliceCallsListScreenState extends State onPressed: () { Navigator.of(context).pop(); }, - child: const Text("Cancel"), + child: const Text('Cancel'), ), TextButton( onPressed: () { Navigator.of(context).pop(); sortCalls(); }, - child: const Text("Use filter"), + child: const Text('Use filter'), ), ], ), @@ -566,7 +564,7 @@ class _AliceCallsListScreenState extends State ), const SizedBox(height: 6), const Text( - "There are no logs to show", + 'There are no logs to show', style: TextStyle(fontSize: 18), ), ], diff --git a/lib/ui/page/alice_stats_screen.dart b/lib/ui/page/alice_stats_screen.dart index c4ce0069..d264ff91 100644 --- a/lib/ui/page/alice_stats_screen.dart +++ b/lib/ui/page/alice_stats_screen.dart @@ -7,7 +7,7 @@ import 'package:flutter/material.dart'; class AliceStatsScreen extends StatelessWidget { final AliceCore aliceCore; - const AliceStatsScreen(this.aliceCore); + const AliceStatsScreen(this.aliceCore, {super.key}); @override Widget build(BuildContext context) { @@ -20,7 +20,7 @@ class AliceStatsScreen extends StatelessWidget { ), child: Scaffold( appBar: AppBar( - title: const Text("Alice - HTTP Inspector - Stats"), + title: const Text('Alice - HTTP Inspector - Stats'), ), body: Container( padding: const EdgeInsets.all(8), @@ -35,38 +35,38 @@ class AliceStatsScreen extends StatelessWidget { List _buildMainListWidgets() { return [ - _getRow("Total requests:", "${_getTotalRequests()}"), - _getRow("Pending requests:", "${_getPendingRequests()}"), - _getRow("Success requests:", "${_getSuccessRequests()}"), - _getRow("Redirection requests:", "${_getRedirectionRequests()}"), - _getRow("Error requests:", "${_getErrorRequests()}"), + _getRow('Total requests:', '${_getTotalRequests()}'), + _getRow('Pending requests:', '${_getPendingRequests()}'), + _getRow('Success requests:', '${_getSuccessRequests()}'), + _getRow('Redirection requests:', '${_getRedirectionRequests()}'), + _getRow('Error requests:', '${_getErrorRequests()}'), _getRow( - "Bytes send:", + 'Bytes send:', AliceConversionHelper.formatBytes(_getBytesSent()), ), _getRow( - "Bytes received:", + 'Bytes received:', AliceConversionHelper.formatBytes(_getBytesReceived()), ), _getRow( - "Average request time:", + 'Average request time:', AliceConversionHelper.formatTime(_getAverageRequestTime()), ), _getRow( - "Max request time:", + 'Max request time:', AliceConversionHelper.formatTime(_getMaxRequestTime()), ), _getRow( - "Min request time:", + 'Min request time:', AliceConversionHelper.formatTime(_getMinRequestTime()), ), - _getRow("Get requests:", "${_getRequests("GET")} "), - _getRow("Post requests:", "${_getRequests("POST")} "), - _getRow("Delete requests:", "${_getRequests("DELETE")} "), - _getRow("Put requests:", "${_getRequests("PUT")} "), - _getRow("Patch requests:", "${_getRequests("PATCH")} "), - _getRow("Secured requests:", "${_getSecuredRequests()}"), - _getRow("Unsecured requests:", "${_getUnsecuredRequests()}"), + _getRow('Get requests:', '${_getRequests('GET')} '), + _getRow('Post requests:', '${_getRequests('POST')} '), + _getRow('Delete requests:', '${_getRequests('DELETE')} '), + _getRow('Put requests:', '${_getRequests('PUT')} '), + _getRow('Patch requests:', '${_getRequests('PATCH')} '), + _getRow('Secured requests:', '${_getSecuredRequests()}'), + _getRow('Unsecured requests:', '${_getUnsecuredRequests()}'), ]; } @@ -83,7 +83,7 @@ class AliceStatsScreen extends StatelessWidget { Text( value, style: _getValueTextStyle(), - ) + ), ], ); } @@ -134,7 +134,7 @@ class AliceStatsScreen extends StatelessWidget { calls.where((call) => call.loading).toList().length; int _getBytesSent() { - int bytes = 0; + var bytes = 0; calls.forEach((AliceHttpCall call) { bytes += call.request!.size; }); @@ -142,7 +142,7 @@ class AliceStatsScreen extends StatelessWidget { } int _getBytesReceived() { - int bytes = 0; + var bytes = 0; calls.forEach((AliceHttpCall call) { if (call.response != null) { bytes += call.response!.size; @@ -152,8 +152,8 @@ class AliceStatsScreen extends StatelessWidget { } int _getAverageRequestTime() { - int requestTimeSum = 0; - int requestsWithDurationCount = 0; + var requestTimeSum = 0; + var requestsWithDurationCount = 0; calls.forEach((AliceHttpCall call) { if (call.duration != 0) { requestTimeSum = call.duration; @@ -167,7 +167,7 @@ class AliceStatsScreen extends StatelessWidget { } int _getMaxRequestTime() { - int maxRequestTime = 0; + var maxRequestTime = 0; calls.forEach((AliceHttpCall call) { if (call.duration > maxRequestTime) { maxRequestTime = call.duration; @@ -177,7 +177,7 @@ class AliceStatsScreen extends StatelessWidget { } int _getMinRequestTime() { - int minRequestTime = 10000000; + var minRequestTime = 10000000; if (calls.isEmpty) { minRequestTime = 0; } else { diff --git a/lib/ui/widget/alice_base_call_details_widget.dart b/lib/ui/widget/alice_base_call_details_widget.dart index ddef1b2a..8fe487c8 100644 --- a/lib/ui/widget/alice_base_call_details_widget.dart +++ b/lib/ui/widget/alice_base_call_details_widget.dart @@ -26,7 +26,7 @@ abstract class AliceBaseCallDetailsWidgetState ), const Padding( padding: EdgeInsets.only(bottom: 18), - ) + ), ], ); } diff --git a/lib/ui/widget/alice_call_error_widget.dart b/lib/ui/widget/alice_call_error_widget.dart index 4137f9a3..323e1c36 100644 --- a/lib/ui/widget/alice_call_error_widget.dart +++ b/lib/ui/widget/alice_call_error_widget.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; class AliceCallErrorWidget extends StatefulWidget { final AliceHttpCall call; - const AliceCallErrorWidget(this.call); + const AliceCallErrorWidget(this.call, {super.key}); @override State createState() { @@ -20,20 +20,20 @@ class _AliceCallErrorWidgetState @override Widget build(BuildContext context) { if (_call.error != null) { - final List rows = []; + final rows = []; final dynamic error = _call.error!.error; - var errorText = "Error is empty"; + var errorText = 'Error is empty'; if (error != null) { errorText = error.toString(); } - rows.add(getListRow("Error:", errorText)); + rows.add(getListRow('Error:', errorText)); return Container( padding: const EdgeInsets.all(6), child: ListView(children: rows), ); } else { - return const Center(child: Text("Nothing to display here")); + return const Center(child: Text('Nothing to display here')); } } } diff --git a/lib/ui/widget/alice_call_list_item_widget.dart b/lib/ui/widget/alice_call_list_item_widget.dart index 8b588ed9..087736de 100644 --- a/lib/ui/widget/alice_call_list_item_widget.dart +++ b/lib/ui/widget/alice_call_list_item_widget.dart @@ -11,11 +11,12 @@ class AliceCallListItemWidget extends StatelessWidget { final AliceHttpCall call; final Function itemClickAction; - const AliceCallListItemWidget(this.call, this.itemClickAction); + const AliceCallListItemWidget(this.call, this.itemClickAction, {super.key}); @override Widget build(BuildContext context) { return InkWell( + // ignore: avoid_dynamic_calls onTap: () => itemClickAction(call), child: Column( children: [ @@ -32,22 +33,22 @@ class AliceCallListItemWidget extends StatelessWidget { const SizedBox(height: 4), _buildServerRow(), const SizedBox(height: 4), - _buildStatsRow() + _buildStatsRow(), ], ), ), - _buildResponseColumn(context) + _buildResponseColumn(context), ], ), ), - _buildDivider() + _buildDivider(), ], ), ); } Widget _buildMethodAndEndpointRow(BuildContext context) { - final Color? textColor = _getEndpointTextColor(context); + final textColor = _getEndpointTextColor(context); return Row( children: [ Text( @@ -70,7 +71,7 @@ class AliceCallListItemWidget extends StatelessWidget { ), ), ), - ) + ), ], ); } @@ -111,11 +112,11 @@ class AliceCallListItemWidget extends StatelessWidget { ), Flexible( child: Text( - "${AliceConversionHelper.formatBytes(call.request!.size)} / " - "${AliceConversionHelper.formatBytes(call.response!.size)}", + '${AliceConversionHelper.formatBytes(call.request!.size)} / ' + '${AliceConversionHelper.formatBytes(call.response!.size)}', style: const TextStyle(fontSize: 12), ), - ) + ), ], ); } @@ -125,33 +126,35 @@ class AliceCallListItemWidget extends StatelessWidget { } String _formatTime(DateTime time) { - return "${formatTimeUnit(time.hour)}:" - "${formatTimeUnit(time.minute)}:" - "${formatTimeUnit(time.second)}:" - "${formatTimeUnit(time.millisecond)}"; + return '${formatTimeUnit(time.hour)}:' + '${formatTimeUnit(time.minute)}:' + '${formatTimeUnit(time.second)}:' + '${formatTimeUnit(time.millisecond)}'; } String formatTimeUnit(int timeUnit) { - return (timeUnit < 10) ? "0$timeUnit" : "$timeUnit"; + return (timeUnit < 10) ? '0$timeUnit' : '$timeUnit'; } Widget _buildResponseColumn(BuildContext context) { - final List widgets = []; + final widgets = []; if (call.loading) { - widgets.add( - SizedBox( - width: 20, - height: 20, - child: CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation(AliceConstants.lightRed), + widgets + ..add( + SizedBox( + width: 20, + height: 20, + child: CircularProgressIndicator( + valueColor: + AlwaysStoppedAnimation(AliceConstants.lightRed), + ), ), - ), - ); - widgets.add( - const SizedBox( - height: 4, - ), - ); + ) + ..add( + const SizedBox( + height: 4, + ), + ); } widgets.add( Text( @@ -162,7 +165,7 @@ class AliceCallListItemWidget extends StatelessWidget { ), ), ); - return Container( + return SizedBox( width: 50, child: Column( children: widgets, @@ -171,11 +174,11 @@ class AliceCallListItemWidget extends StatelessWidget { } Color? _getStatusTextColor(BuildContext context) { - final int? status = call.response!.status; + final status = call.response!.status; if (status == -1) { return AliceConstants.red; } else if (status! < 200) { - return Theme.of(context).textTheme.bodyText1!.color; + return Theme.of(context).textTheme.bodyLarge!.color; } else if (status >= 200 && status < 300) { return AliceConstants.green; } else if (status >= 300 && status < 400) { @@ -183,7 +186,7 @@ class AliceCallListItemWidget extends StatelessWidget { } else if (status >= 400 && status < 600) { return AliceConstants.red; } else { - return Theme.of(context).textTheme.bodyText1!.color; + return Theme.of(context).textTheme.bodyLarge!.color; } } @@ -197,11 +200,11 @@ class AliceCallListItemWidget extends StatelessWidget { String _getStatus(AliceHttpResponse response) { if (response.status == -1) { - return "ERR"; + return 'ERR'; } else if (response.status == 0) { - return "???"; + return '???'; } else { - return "${response.status}"; + return '${response.status}'; } } diff --git a/lib/ui/widget/alice_call_overview_widget.dart b/lib/ui/widget/alice_call_overview_widget.dart index 846c4ba3..d9e9b2c2 100644 --- a/lib/ui/widget/alice_call_overview_widget.dart +++ b/lib/ui/widget/alice_call_overview_widget.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; class AliceCallOverviewWidget extends StatefulWidget { final AliceHttpCall call; - const AliceCallOverviewWidget(this.call); + const AliceCallOverviewWidget(this.call, {super.key}); @override State createState() { @@ -19,17 +19,19 @@ class _AliceCallOverviewWidget @override Widget build(BuildContext context) { - final List rows = []; - rows.add(getListRow("Method: ", _call.method)); - rows.add(getListRow("Server: ", _call.server)); - rows.add(getListRow("Endpoint: ", _call.endpoint)); - rows.add(getListRow("Started:", _call.request!.time.toString())); - rows.add(getListRow("Finished:", _call.response!.time.toString())); - rows.add(getListRow("Duration:", formatDuration(_call.duration))); - rows.add(getListRow("Bytes sent:", formatBytes(_call.request!.size))); - rows.add(getListRow("Bytes received:", formatBytes(_call.response!.size))); - rows.add(getListRow("Client:", _call.client)); - rows.add(getListRow("Secure:", _call.secure.toString())); + final rows = [ + getListRow('Method: ', _call.method), + getListRow('Server: ', _call.server), + getListRow('Endpoint: ', _call.endpoint), + getListRow('Started:', _call.request!.time.toString()), + getListRow('Finished:', _call.response!.time.toString()), + getListRow('Duration:', formatDuration(_call.duration)), + getListRow('Bytes sent:', formatBytes(_call.request!.size)), + getListRow('Bytes received:', formatBytes(_call.response!.size)), + getListRow('Client:', _call.client), + getListRow('Secure:', _call.secure.toString()), + ]; + return Container( padding: const EdgeInsets.all(6), child: ListView(children: rows), diff --git a/lib/ui/widget/alice_call_request_widget.dart b/lib/ui/widget/alice_call_request_widget.dart index 56aba597..f54bc1c0 100644 --- a/lib/ui/widget/alice_call_request_widget.dart +++ b/lib/ui/widget/alice_call_request_widget.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; class AliceCallRequestWidget extends StatefulWidget { final AliceHttpCall call; - const AliceCallRequestWidget(this.call); + const AliceCallRequestWidget(this.call, {super.key}); @override State createState() { @@ -19,37 +19,36 @@ class _AliceCallRequestWidget @override Widget build(BuildContext context) { - final List rows = []; - rows.add(getListRow("Started:", _call.request!.time.toString())); - rows.add(getListRow("Bytes sent:", formatBytes(_call.request!.size))); - rows.add( - getListRow("Content type:", getContentType(_call.request!.headers)!), - ); + final rows = [ + getListRow('Started:', _call.request!.time.toString()), + getListRow('Bytes sent:', formatBytes(_call.request!.size)), + getListRow('Content type:', getContentType(_call.request!.headers)!), + ]; final dynamic body = _call.request!.body; - var bodyContent = "Body is empty"; + var bodyContent = 'Body is empty'; if (body != null) { bodyContent = formatBody(body, getContentType(_call.request!.headers)); } - rows.add(getListRow("Body:", bodyContent)); + rows.add(getListRow('Body:', bodyContent)); final formDataFields = _call.request!.formDataFields; if (formDataFields?.isNotEmpty == true) { - rows.add(getListRow("Form data fields: ", "")); + rows.add(getListRow('Form data fields: ', '')); formDataFields!.forEach( (field) { - rows.add(getListRow(" • ${field.name}:", field.value)); + rows.add(getListRow(' • ${field.name}:', field.value)); }, ); } final formDataFiles = _call.request!.formDataFiles; if (formDataFiles?.isNotEmpty == true) { - rows.add(getListRow("Form data files: ", "")); + rows.add(getListRow('Form data files: ', '')); formDataFiles!.forEach( (field) { rows.add( getListRow( - " • ${field.fileName}:", - "${field.contentType} / ${field.length} B", + ' • ${field.fileName}:', + '${field.contentType} / ${field.length} B', ), ); }, @@ -57,22 +56,22 @@ class _AliceCallRequestWidget } final headers = _call.request!.headers; - var headersContent = "Headers are empty"; + var headersContent = 'Headers are empty'; if (headers.isNotEmpty) { - headersContent = ""; + headersContent = ''; } - rows.add(getListRow("Headers: ", headersContent)); + rows.add(getListRow('Headers: ', headersContent)); _call.request!.headers.forEach((header, dynamic value) { - rows.add(getListRow(" • $header:", value.toString())); + rows.add(getListRow(' • $header:', value.toString())); }); final queryParameters = _call.request!.queryParameters; - var queryParametersContent = "Query parameters are empty"; + var queryParametersContent = 'Query parameters are empty'; if (queryParameters.isNotEmpty) { - queryParametersContent = ""; + queryParametersContent = ''; } - rows.add(getListRow("Query Parameters: ", queryParametersContent)); + rows.add(getListRow('Query Parameters: ', queryParametersContent)); _call.request!.queryParameters.forEach((query, dynamic value) { - rows.add(getListRow(" • $query:", value.toString())); + rows.add(getListRow(' • $query:', value.toString())); }); return Container( diff --git a/lib/ui/widget/alice_call_response_widget.dart b/lib/ui/widget/alice_call_response_widget.dart index 2750cfad..932b611c 100644 --- a/lib/ui/widget/alice_call_response_widget.dart +++ b/lib/ui/widget/alice_call_response_widget.dart @@ -7,7 +7,7 @@ import 'package:url_launcher/url_launcher.dart'; class AliceCallResponseWidget extends StatefulWidget { final AliceHttpCall call; - const AliceCallResponseWidget(this.call); + const AliceCallResponseWidget(this.call, {super.key}); @override State createState() { @@ -17,11 +17,11 @@ class AliceCallResponseWidget extends StatefulWidget { class _AliceCallResponseWidgetState extends AliceBaseCallDetailsWidgetState { - static const _imageContentType = "image"; - static const _videoContentType = "video"; - static const _jsonContentType = "json"; - static const _xmlContentType = "xml"; - static const _textContentType = "text"; + static const _imageContentType = 'image'; + static const _videoContentType = 'video'; + static const _jsonContentType = 'json'; + static const _xmlContentType = 'xml'; + static const _textContentType = 'text'; static const _kLargeOutputSize = 100000; bool _showLargeBody = false; @@ -31,62 +31,61 @@ class _AliceCallResponseWidgetState @override Widget build(BuildContext context) { - final List rows = []; + final rows = []; if (!_call.loading) { - rows.addAll(_buildGeneralDataRows()); - rows.addAll(_buildHeadersRows()); - rows.addAll(_buildBodyRows()); + rows + ..addAll(_buildGeneralDataRows()) + ..addAll(_buildHeadersRows()) + ..addAll(_buildBodyRows()); return Container( padding: const EdgeInsets.all(6), child: ListView(children: rows), ); } else { - return Center( + return const Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, - children: const [ - CircularProgressIndicator(), - Text("Awaiting response...") - ], + children: [CircularProgressIndicator(), Text('Awaiting response...')], ), ); } } List _buildGeneralDataRows() { - final List rows = []; - rows.add(getListRow("Received:", _call.response!.time.toString())); - rows.add(getListRow("Bytes received:", formatBytes(_call.response!.size))); + final rows = [ + getListRow('Received:', _call.response!.time.toString()), + getListRow('Bytes received:', formatBytes(_call.response!.size)), + ]; final status = _call.response!.status; - var statusText = "$status"; + var statusText = '$status'; if (status == -1) { - statusText = "Error"; + statusText = 'Error'; } - rows.add(getListRow("Status:", statusText)); + rows.add(getListRow('Status:', statusText)); return rows; } List _buildHeadersRows() { - final List rows = []; + final rows = []; final headers = _call.response!.headers; - var headersContent = "Headers are empty"; + var headersContent = 'Headers are empty'; if (headers != null && headers.isNotEmpty) { - headersContent = ""; + headersContent = ''; } - rows.add(getListRow("Headers: ", headersContent)); + rows.add(getListRow('Headers: ', headersContent)); if (_call.response!.headers != null) { _call.response!.headers!.forEach((header, value) { - rows.add(getListRow(" • $header:", value.toString())); + rows.add(getListRow(' • $header:', value)); }); } return rows; } List _buildBodyRows() { - final List rows = []; + final rows = []; if (_isImageResponse()) { rows.addAll(_buildImageBodyRows()); } else if (_isVideoResponse()) { @@ -105,16 +104,15 @@ class _AliceCallResponseWidgetState } List _buildImageBodyRows() { - final List rows = []; - rows.add( + return [ Column( children: [ - Row( - children: const [ + const Row( + children: [ Text( - "Body: Image", + 'Body: Image', style: TextStyle(fontWeight: FontWeight.bold), - ) + ), ], ), const SizedBox(height: 8), @@ -141,113 +139,114 @@ class _AliceCallResponseWidgetState const SizedBox(height: 8), ], ), - ); - return rows; + ]; } List _buildLargeBodyTextRows() { - final List rows = []; + final rows = []; if (_showLargeBody) { return _buildTextBodyRows(); } else { - rows.add( - getListRow( - "Body:", - "Too large to show (${_call.response!.body.toString().length} Bytes)", - ), - ); - rows.add(const SizedBox(height: 8)); - rows.add( - ElevatedButton( - style: ButtonStyle( - backgroundColor: - MaterialStateProperty.all(AliceConstants.lightRed), + rows + ..add( + getListRow( + 'Body:', + 'Too large to show ' + '(${_call.response!.body.toString().length} Bytes)', ), - onPressed: () { - setState(() { - _showLargeBody = true; - }); - }, - child: const Text("Show body"), - ), - ); - rows.add(const SizedBox(height: 8)); - rows.add(const Text("Warning! It will take some time to render output.")); + ) + ..add(const SizedBox(height: 8)) + ..add( + ElevatedButton( + style: ButtonStyle( + backgroundColor: + MaterialStateProperty.all(AliceConstants.lightRed), + ), + onPressed: () { + setState(() { + _showLargeBody = true; + }); + }, + child: const Text('Show body'), + ), + ) + ..add(const SizedBox(height: 8)) + ..add(const Text('Warning! It will take some time to render output.')); } return rows; } List _buildTextBodyRows() { - final List rows = []; + final rows = []; final headers = _call.response!.headers; final bodyContent = formatBody(_call.response!.body, getContentType(headers)); - rows.add(getListRow("Body:", bodyContent)); + rows.add(getListRow('Body:', bodyContent)); return rows; } List _buildVideoBodyRows() { - final List rows = []; - rows.add( - Row( - children: const [ + final rows = [ + const Row( + children: [ Text( - "Body: Video", + 'Body: Video', style: TextStyle(fontWeight: FontWeight.bold), - ) + ), ], ), - ); - rows.add(const SizedBox(height: 8)); - rows.add(TextButton( - child: Text("Open video in web browser"), - onPressed: () async { - await launchUrl(Uri.parse(_call.uri)); - }, - )); - rows.add(const SizedBox(height: 8)); + const SizedBox(height: 8), + TextButton( + child: const Text('Open video in web browser'), + onPressed: () async { + await launchUrl(Uri.parse(_call.uri)); + }, + ), + const SizedBox(height: 8), + ]; + return rows; } List _buildUnknownBodyRows() { - final List rows = []; + final rows = []; final headers = _call.response!.headers; - final contentType = getContentType(headers) ?? ""; + final contentType = getContentType(headers) ?? ''; if (_showUnsupportedBody) { final bodyContent = formatBody(_call.response!.body, getContentType(headers)); - rows.add(getListRow("Body:", bodyContent)); + rows.add(getListRow('Body:', bodyContent)); } else { - rows.add( - getListRow( - "Body:", - "Unsupported body. Alice can render video/image/text body. " - "Response has Content-Type: $contentType which can't be handled. " - "If you're feeling lucky you can try button below to try render body" - " as text, but it may fail.", - ), - ); - rows.add( - ElevatedButton( - style: ButtonStyle( - backgroundColor: - MaterialStateProperty.all(AliceConstants.lightRed), + rows + ..add( + getListRow( + 'Body:', + 'Unsupported body. Alice can render video/image/text body. ' + "Response has Content-Type: $contentType which can't be " + "handled. If you're feeling lucky you can try button below " + 'to try render body as text, but it may fail.'), + ) + ..add( + ElevatedButton( + style: ButtonStyle( + backgroundColor: + MaterialStateProperty.all(AliceConstants.lightRed), + ), + onPressed: () { + setState(() { + _showUnsupportedBody = true; + }); + }, + child: const Text('Show unsupported body'), ), - onPressed: () { - setState(() { - _showUnsupportedBody = true; - }); - }, - child: const Text("Show unsupported body"), - ), - ); + ); } return rows; } Map _buildRequestHeaders() { - final Map requestHeaders = {}; + final requestHeaders = {}; if (_call.request?.headers != null) { requestHeaders.addAll( _call.request!.headers.map( @@ -273,7 +272,7 @@ class _AliceCallResponseWidgetState } bool _isTextResponse() { - final String responseContentTypeLowerCase = + final responseContentTypeLowerCase = _getContentTypeOfResponse()!.toLowerCase(); return responseContentTypeLowerCase.contains(_jsonContentType) || diff --git a/lib/ui/widget/alice_log_list_widget.dart b/lib/ui/widget/alice_log_list_widget.dart index a0b56a3a..04ada72a 100644 --- a/lib/ui/widget/alice_log_list_widget.dart +++ b/lib/ui/widget/alice_log_list_widget.dart @@ -11,6 +11,7 @@ class AliceLogListWidget extends StatefulWidget { required this.logsListenable, required this.scrollController, required this.emptyWidget, + super.key, }); final ValueListenable> logsListenable; @@ -22,7 +23,7 @@ class AliceLogListWidget extends StatefulWidget { } class _AliceLogListWidgetState extends State { - var _minLevel = DiagnosticLevel.debug; + final _minLevel = DiagnosticLevel.debug; @override Widget build(BuildContext context) { @@ -65,9 +66,9 @@ class AliceLogEntryWidget extends StatelessWidget { children: [ TextSpan( text: formattedTimestamp, - style: textTheme.caption!.copyWith( + style: textTheme.bodySmall!.copyWith( color: color.withOpacity(0.6), - fontFeatures: [FontFeature.tabularFigures()], + fontFeatures: [const FontFeature.tabularFigures()], ), ), TextSpan(text: ' ${log.message}'), @@ -86,7 +87,7 @@ class AliceLogEntryWidget extends StatelessWidget { return InkWell( onLongPress: () => _copyToClipboard(context), child: Padding( - padding: EdgeInsets.symmetric(horizontal: 16, vertical: 4), + padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -95,7 +96,7 @@ class AliceLogEntryWidget extends StatelessWidget { size: 16, color: color, ), - SizedBox(width: 4), + const SizedBox(width: 4), Expanded(child: content), ], ), @@ -115,7 +116,7 @@ class AliceLogEntryWidget extends StatelessWidget { return [ TextSpan( text: '\n$title:${addLineBreakAfterTitle ? '\n' : ' '}', - style: TextStyle(fontWeight: FontWeight.bold), + style: const TextStyle(fontWeight: FontWeight.bold), ), TextSpan(text: string), ]; @@ -139,7 +140,7 @@ class AliceLogEntryWidget extends StatelessWidget { case DiagnosticLevel.summary: return Colors.black; case DiagnosticLevel.error: - return theme.errorColor; + return theme.colorScheme.error; case DiagnosticLevel.off: return Colors.purple; } @@ -178,7 +179,7 @@ class AliceLogEntryWidget extends StatelessWidget { ].join('\n'); await Clipboard.setData(ClipboardData(text: text)); ScaffoldMessenger.of(context) - .showSnackBar(SnackBar(content: Text('Copied!'))); + .showSnackBar(const SnackBar(content: Text('Copied!'))); } String? _stringify(dynamic object) { @@ -187,11 +188,13 @@ class AliceLogEntryWidget extends StatelessWidget { if (object is DiagnosticsNode) return object.toStringDeep(); try { + // ignore: avoid_dynamic_calls object.toJson(); // It supports `toJson()`. dynamic toEncodable(dynamic object) { try { + // ignore: avoid_dynamic_calls return object.toJson(); } catch (_) { try { diff --git a/lib/ui/widget/alice_raw_log_list_widger.dart b/lib/ui/widget/alice_raw_log_list_widger.dart index c41e66f3..675418e9 100644 --- a/lib/ui/widget/alice_raw_log_list_widger.dart +++ b/lib/ui/widget/alice_raw_log_list_widger.dart @@ -3,11 +3,11 @@ import 'package:flutter/services.dart'; class AliceRawLogListWidget extends StatelessWidget { const AliceRawLogListWidget({ - Key? key, required this.scrollController, required this.getRawLogs, required this.emptyWidget, - }) : super(key: key); + super.key, + }); final ScrollController scrollController; final Future? getRawLogs; @@ -26,13 +26,13 @@ class AliceRawLogListWidget extends StatelessWidget { child: SingleChildScrollView( controller: scrollController, child: Padding( - padding: const EdgeInsets.all(8.0), + padding: const EdgeInsets.all(8), child: InkWell( onLongPress: () => _copyToClipboard(snapshot.data!, context), child: Text( snapshot.data ?? '', - style: TextStyle(fontSize: 10), + style: const TextStyle(fontSize: 10), ), ), ), @@ -41,7 +41,7 @@ class AliceRawLogListWidget extends StatelessWidget { } return emptyWidget; } - return Center(child: CircularProgressIndicator()); + return const Center(child: CircularProgressIndicator()); }, ); } @@ -49,7 +49,7 @@ class AliceRawLogListWidget extends StatelessWidget { Future _copyToClipboard(String text, BuildContext context) async { await Clipboard.setData(ClipboardData(text: text)); ScaffoldMessenger.of(context).showSnackBar( - SnackBar( + const SnackBar( content: Text('Copied!'), ), ); diff --git a/lib/utils/alice_parser.dart b/lib/utils/alice_parser.dart index fe518ca2..691a6711 100644 --- a/lib/utils/alice_parser.dart +++ b/lib/utils/alice_parser.dart @@ -1,13 +1,13 @@ import 'dart:convert'; class AliceParser { - static const String _emptyBody = "Body is empty"; - static const String _unknownContentType = "Unknown"; - static const String _jsonContentTypeSmall = "content-type"; - static const String _jsonContentTypeBig = "Content-Type"; - static const String _stream = "Stream"; - static const String _applicationJson = "application/json"; - static const String _parseFailedText = "Failed to parse "; + static const String _emptyBody = 'Body is empty'; + static const String _unknownContentType = 'Unknown'; + static const String _jsonContentTypeSmall = 'content-type'; + static const String _jsonContentTypeBig = 'Content-Type'; + static const String _stream = 'Stream'; + static const String _applicationJson = 'application/json'; + static const String _parseFailedText = 'Failed to parse '; static const JsonEncoder encoder = JsonEncoder.withIndent(' '); static String _parseJson(dynamic json) { @@ -42,12 +42,13 @@ class AliceParser { bodyContent = bodyTemp; } } else { - if (body is String && body.contains("\n")) { + if (body is String && body.contains('\n')) { bodyContent = body; } else { if (body is String) { if (body.isNotEmpty) { - //body is minified json, so decode it to a map and let the encoder pretty print this map + //body is minified json, so decode it to a map and let the + // encoder pretty print this map bodyContent = _parseJson(_decodeJson(body)); } } else if (body is Stream) { diff --git a/lib/utils/shake_detector.dart b/lib/utils/shake_detector.dart index 620b5e70..38f5e788 100644 --- a/lib/utils/shake_detector.dart +++ b/lib/utils/shake_detector.dart @@ -1,5 +1,7 @@ ///Code from https://github.com/deven98/shake ///Seems to be not maintained for almost 2 years... (01.03.2021). +library; + import 'dart:async'; import 'dart:math'; @@ -26,7 +28,7 @@ class ShakeDetector { int mShakeCount = 0; /// StreamSubscription for Accelerometer events - StreamSubscription? streamSubscription; + StreamSubscription? streamSubscription; /// This constructor waits until [startListening] is called ShakeDetector.waitForStart({ @@ -49,16 +51,16 @@ class ShakeDetector { /// Starts listening to accelerometer events void startListening() { streamSubscription = accelerometerEvents.listen((AccelerometerEvent event) { - final double x = event.x; - final double y = event.y; - final double z = event.z; + final x = event.x; + final y = event.y; + final z = event.z; - final double gX = x / 9.80665; - final double gY = y / 9.80665; - final double gZ = z / 9.80665; + final gX = x / 9.80665; + final gY = y / 9.80665; + final gZ = z / 9.80665; // gForce will be close to 1 when there is no movement. - final double gForce = sqrt(gX * gX + gY * gY + gZ * gZ); + final gForce = sqrt(gX * gX + gY * gY + gZ * gZ); if (gForce > shakeThresholdGravity) { final now = DateTime.now().millisecondsSinceEpoch; diff --git a/pubspec.lock b/pubspec.lock deleted file mode 100644 index a594447f..00000000 --- a/pubspec.lock +++ /dev/null @@ -1,573 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - args: - dependency: transitive - description: - name: args - sha256: "0bd9a99b6eb96f07af141f0eb53eace8983e8e5aa5de59777aca31684680ef22" - url: "https://pub.dev" - source: hosted - version: "2.3.0" - async: - dependency: transitive - description: - name: async - sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" - url: "https://pub.dev" - source: hosted - version: "2.11.0" - characters: - dependency: transitive - description: - name: characters - sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" - url: "https://pub.dev" - source: hosted - version: "1.3.0" - charcode: - dependency: transitive - description: - name: charcode - sha256: "8e36feea6de5ea69f2199f29cf42a450a855738c498b57c0b980e2d3cca9c362" - url: "https://pub.dev" - source: hosted - version: "1.2.0" - chopper: - dependency: "direct main" - description: - name: chopper - sha256: "4ba5b590f4dc04b948024efdf4d85fd484d6c81eb83cefc36f29cf83f6e50ae5" - url: "https://pub.dev" - source: hosted - version: "7.0.9" - clock: - dependency: transitive - description: - name: clock - sha256: "6021e0172ab6e6eaa1d391afed0a99353921f00c54385c574dc53e55d67c092c" - url: "https://pub.dev" - source: hosted - version: "1.1.0" - collection: - dependency: "direct main" - description: - name: collection - sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 - url: "https://pub.dev" - source: hosted - version: "1.17.2" - cross_file: - dependency: transitive - description: - name: cross_file - sha256: "0b0036e8cccbfbe0555fd83c1d31a6f30b77a96b598b35a5d36dd41f718695e9" - url: "https://pub.dev" - source: hosted - version: "0.3.3+4" - crypto: - dependency: transitive - description: - name: crypto - sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67 - url: "https://pub.dev" - source: hosted - version: "3.0.2" - dbus: - dependency: transitive - description: - name: dbus - sha256: "6f07cba3f7b3448d42d015bfd3d53fe12e5b36da2423f23838efc1d5fb31a263" - url: "https://pub.dev" - source: hosted - version: "0.7.8" - dio: - dependency: "direct main" - description: - name: dio - sha256: "417e2a6f9d83ab396ec38ff4ea5da6c254da71e4db765ad737a42af6930140b7" - url: "https://pub.dev" - source: hosted - version: "5.3.3" - equatable: - dependency: transitive - description: - name: equatable - sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2 - url: "https://pub.dev" - source: hosted - version: "2.0.5" - ffi: - dependency: transitive - description: - name: ffi - sha256: a38574032c5f1dd06c4aee541789906c12ccaab8ba01446e800d9c5b79c4a978 - url: "https://pub.dev" - source: hosted - version: "2.0.1" - file: - dependency: transitive - description: - name: file - sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d" - url: "https://pub.dev" - source: hosted - version: "6.1.4" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_local_notifications: - dependency: "direct main" - description: - name: flutter_local_notifications - sha256: "6d11ea777496061e583623aaf31923f93a9409ef8fcaeeefdd6cd78bf4fe5bb3" - url: "https://pub.dev" - source: hosted - version: "16.1.0" - flutter_local_notifications_linux: - dependency: transitive - description: - name: flutter_local_notifications_linux - sha256: "33f741ef47b5f63cc7f78fe75eeeac7e19f171ff3c3df054d84c1e38bedb6a03" - url: "https://pub.dev" - source: hosted - version: "4.0.0+1" - flutter_local_notifications_platform_interface: - dependency: transitive - description: - name: flutter_local_notifications_platform_interface - sha256: "7cf643d6d5022f3baed0be777b0662cce5919c0a7b86e700299f22dc4ae660ef" - url: "https://pub.dev" - source: hosted - version: "7.0.0+1" - flutter_web_plugins: - dependency: transitive - description: flutter - source: sdk - version: "0.0.0" - http: - dependency: "direct main" - description: - name: http - sha256: "759d1a329847dd0f39226c688d3e06a6b8679668e350e2891a6474f8b4bb8525" - url: "https://pub.dev" - source: hosted - version: "1.1.0" - http_parser: - dependency: transitive - description: - name: http_parser - sha256: e362d639ba3bc07d5a71faebb98cde68c05bfbcfbbb444b60b6f60bb67719185 - url: "https://pub.dev" - source: hosted - version: "4.0.0" - js: - dependency: transitive - description: - name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 - url: "https://pub.dev" - source: hosted - version: "0.6.7" - lint: - dependency: "direct dev" - description: - name: lint - sha256: f4bd4dbaa39f4ae8836f2d1275f2f32bc68b3a8cce0a0735dd1f7a601f06682a - url: "https://pub.dev" - source: hosted - version: "2.1.2" - logging: - dependency: transitive - description: - name: logging - sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" - url: "https://pub.dev" - source: hosted - version: "1.2.0" - material_color_utilities: - dependency: transitive - description: - name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" - url: "https://pub.dev" - source: hosted - version: "0.5.0" - meta: - dependency: transitive - description: - name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" - url: "https://pub.dev" - source: hosted - version: "1.9.1" - mime: - dependency: transitive - description: - name: mime - sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e - url: "https://pub.dev" - source: hosted - version: "1.0.4" - open_filex: - dependency: "direct main" - description: - name: open_filex - sha256: a6c95237767c5647e68b71a476602fcf4f1bfc530c126265e53addae22ef5fc2 - url: "https://pub.dev" - source: hosted - version: "4.3.4" - package_info_plus: - dependency: "direct main" - description: - name: package_info_plus - sha256: "7e76fad405b3e4016cd39d08f455a4eb5199723cf594cd1b8916d47140d93017" - url: "https://pub.dev" - source: hosted - version: "4.2.0" - package_info_plus_platform_interface: - dependency: transitive - description: - name: package_info_plus_platform_interface - sha256: "9bc8ba46813a4cc42c66ab781470711781940780fd8beddd0c3da62506d3a6c6" - url: "https://pub.dev" - source: hosted - version: "2.0.1" - path: - dependency: transitive - description: - name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" - url: "https://pub.dev" - source: hosted - version: "1.8.3" - path_provider: - dependency: "direct main" - description: - name: path_provider - sha256: a1aa8aaa2542a6bc57e381f132af822420216c80d4781f7aa085ca3229208aaa - url: "https://pub.dev" - source: hosted - version: "2.1.1" - path_provider_android: - dependency: transitive - description: - name: path_provider_android - sha256: e595b98692943b4881b219f0a9e3945118d3c16bd7e2813f98ec6e532d905f72 - url: "https://pub.dev" - source: hosted - version: "2.2.1" - path_provider_foundation: - dependency: transitive - description: - name: path_provider_foundation - sha256: "19314d595120f82aca0ba62787d58dde2cc6b5df7d2f0daf72489e38d1b57f2d" - url: "https://pub.dev" - source: hosted - version: "2.3.1" - path_provider_linux: - dependency: transitive - description: - name: path_provider_linux - sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279 - url: "https://pub.dev" - source: hosted - version: "2.2.1" - path_provider_platform_interface: - dependency: transitive - description: - name: path_provider_platform_interface - sha256: "94b1e0dd80970c1ce43d5d4e050a9918fce4f4a775e6142424c30a29a363265c" - url: "https://pub.dev" - source: hosted - version: "2.1.1" - path_provider_windows: - dependency: transitive - description: - name: path_provider_windows - sha256: "8bc9f22eee8690981c22aa7fc602f5c85b497a6fb2ceb35ee5a5e5ed85ad8170" - url: "https://pub.dev" - source: hosted - version: "2.2.1" - permission_handler: - dependency: "direct main" - description: - name: permission_handler - sha256: "284a66179cabdf942f838543e10413246f06424d960c92ba95c84439154fcac8" - url: "https://pub.dev" - source: hosted - version: "11.0.1" - permission_handler_android: - dependency: transitive - description: - name: permission_handler_android - sha256: f9fddd3b46109bd69ff3f9efa5006d2d309b7aec0f3c1c5637a60a2d5659e76e - url: "https://pub.dev" - source: hosted - version: "11.1.0" - permission_handler_apple: - dependency: transitive - description: - name: permission_handler_apple - sha256: "99e220bce3f8877c78e4ace901082fb29fa1b4ebde529ad0932d8d664b34f3f5" - url: "https://pub.dev" - source: hosted - version: "9.1.4" - permission_handler_platform_interface: - dependency: transitive - description: - name: permission_handler_platform_interface - sha256: "6760eb5ef34589224771010805bea6054ad28453906936f843a8cc4d3a55c4a4" - url: "https://pub.dev" - source: hosted - version: "3.12.0" - permission_handler_windows: - dependency: transitive - description: - name: permission_handler_windows - sha256: cc074aace208760f1eee6aa4fae766b45d947df85bc831cde77009cdb4720098 - url: "https://pub.dev" - source: hosted - version: "0.1.3" - petitparser: - dependency: transitive - description: - name: petitparser - sha256: "2ebb289dc4764ec397f5cd3ca9881c6d17196130a7d646ed022a0dd9c2e25a71" - url: "https://pub.dev" - source: hosted - version: "5.0.0" - platform: - dependency: transitive - description: - name: platform - sha256: ebc79f16b5f6b609aad4a5e63447d4795d16f7adee46e93ed03200848c006735 - url: "https://pub.dev" - source: hosted - version: "3.0.0" - plugin_platform_interface: - dependency: transitive - description: - name: plugin_platform_interface - sha256: da3fdfeccc4d4ff2da8f8c556704c08f912542c5fb3cf2233ed75372384a034d - url: "https://pub.dev" - source: hosted - version: "2.1.6" - process: - dependency: transitive - description: - name: process - sha256: dc3c073b5bc0db4e0f3dbc6b69f8e9cf2f336dafb3db996242ebdacf94c295dd - url: "https://pub.dev" - source: hosted - version: "4.2.1" - rxdart: - dependency: "direct main" - description: - name: rxdart - sha256: "0c7c0cedd93788d996e33041ffecda924cc54389199cde4e6a34b440f50044cb" - url: "https://pub.dev" - source: hosted - version: "0.27.7" - sensors_plus: - dependency: "direct main" - description: - name: sensors_plus - sha256: a1e461f28a8e8d3f81feb07d5c4e87e948379ea91f0b5131266bb79f72b38acb - url: "https://pub.dev" - source: hosted - version: "3.1.0" - sensors_plus_platform_interface: - dependency: transitive - description: - name: sensors_plus_platform_interface - sha256: "95f0cc08791b8bf0c41c5fa99c84be2a7d5bf60a811ddc17e1438b1e68caf0d3" - url: "https://pub.dev" - source: hosted - version: "1.1.3" - share_plus: - dependency: "direct main" - description: - name: share_plus - sha256: f74fc3f1cbd99f39760182e176802f693fa0ec9625c045561cfad54681ea93dd - url: "https://pub.dev" - source: hosted - version: "7.2.1" - share_plus_platform_interface: - dependency: transitive - description: - name: share_plus_platform_interface - sha256: df08bc3a07d01f5ea47b45d03ffcba1fa9cd5370fb44b3f38c70e42cced0f956 - url: "https://pub.dev" - source: hosted - version: "3.3.1" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - source_span: - dependency: transitive - description: - name: source_span - sha256: d5f89a9e52b36240a80282b3dc0667dd36e53459717bb17b8fb102d30496606a - url: "https://pub.dev" - source: hosted - version: "1.8.1" - sprintf: - dependency: transitive - description: - name: sprintf - sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23" - url: "https://pub.dev" - source: hosted - version: "7.0.0" - string_scanner: - dependency: transitive - description: - name: string_scanner - sha256: dd11571b8a03f7cadcf91ec26a77e02bfbd6bbba2a512924d3116646b4198fc4 - url: "https://pub.dev" - source: hosted - version: "1.1.0" - term_glyph: - dependency: transitive - description: - name: term_glyph - sha256: a88162591b02c1f3a3db3af8ce1ea2b374bd75a7bb8d5e353bcfbdc79d719830 - url: "https://pub.dev" - source: hosted - version: "1.2.0" - timezone: - dependency: transitive - description: - name: timezone - sha256: "2e59efc48e9f684c327c0498ac0b81411aee18b10c82f2db2c08f7f052493569" - url: "https://pub.dev" - source: hosted - version: "0.9.0" - typed_data: - dependency: transitive - description: - name: typed_data - sha256: "53bdf7e979cfbf3e28987552fd72f637e63f3c8724c9e56d9246942dc2fa36ee" - url: "https://pub.dev" - source: hosted - version: "1.3.0" - url_launcher: - dependency: "direct main" - description: - name: url_launcher - sha256: b1c9e98774adf8820c96fbc7ae3601231d324a7d5ebd8babe27b6dfac91357ba - url: "https://pub.dev" - source: hosted - version: "6.2.1" - url_launcher_android: - dependency: transitive - description: - name: url_launcher_android - sha256: "31222ffb0063171b526d3e569079cf1f8b294075ba323443fdc690842bfd4def" - url: "https://pub.dev" - source: hosted - version: "6.2.0" - url_launcher_ios: - dependency: transitive - description: - name: url_launcher_ios - sha256: "4ac97281cf60e2e8c5cc703b2b28528f9b50c8f7cebc71df6bdf0845f647268a" - url: "https://pub.dev" - source: hosted - version: "6.2.0" - url_launcher_linux: - dependency: transitive - description: - name: url_launcher_linux - sha256: "9f2d390e096fdbe1e6e6256f97851e51afc2d9c423d3432f1d6a02a8a9a8b9fd" - url: "https://pub.dev" - source: hosted - version: "3.1.0" - url_launcher_macos: - dependency: transitive - description: - name: url_launcher_macos - sha256: b7244901ea3cf489c5335bdacda07264a6e960b1c1b1a9f91e4bc371d9e68234 - url: "https://pub.dev" - source: hosted - version: "3.1.0" - url_launcher_platform_interface: - dependency: transitive - description: - name: url_launcher_platform_interface - sha256: "980e8d9af422f477be6948bdfb68df8433be71f5743a188968b0c1b887807e50" - url: "https://pub.dev" - source: hosted - version: "2.2.0" - url_launcher_web: - dependency: transitive - description: - name: url_launcher_web - sha256: "7fd2f55fe86cea2897b963e864dc01a7eb0719ecc65fcef4c1cc3d686d718bb2" - url: "https://pub.dev" - source: hosted - version: "2.2.0" - url_launcher_windows: - dependency: transitive - description: - name: url_launcher_windows - sha256: "7754a1ad30ee896b265f8d14078b0513a4dba28d358eabb9d5f339886f4a1adc" - url: "https://pub.dev" - source: hosted - version: "3.1.0" - uuid: - dependency: transitive - description: - name: uuid - sha256: df5a4d8f22ee4ccd77f8839ac7cb274ebc11ef9adcce8b92be14b797fe889921 - url: "https://pub.dev" - source: hosted - version: "4.2.1" - vector_math: - dependency: transitive - description: - name: vector_math - sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" - url: "https://pub.dev" - source: hosted - version: "2.1.4" - web: - dependency: transitive - description: - name: web - sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 - url: "https://pub.dev" - source: hosted - version: "0.1.4-beta" - win32: - dependency: transitive - description: - name: win32 - sha256: "5a751eddf9db89b3e5f9d50c20ab8612296e4e8db69009788d6c8b060a84191c" - url: "https://pub.dev" - source: hosted - version: "4.1.4" - xdg_directories: - dependency: transitive - description: - name: xdg_directories - sha256: "060b6e1c891d956f72b5ac9463466c37cce3fa962a921532fc001e86fe93438e" - url: "https://pub.dev" - source: hosted - version: "0.2.0+1" - xml: - dependency: transitive - description: - name: xml - sha256: ac0e3f4bf00ba2708c33fbabbbe766300e509f8c82dbd4ab6525039813f7e2fb - url: "https://pub.dev" - source: hosted - version: "6.1.0" -sdks: - dart: ">=3.1.0 <4.0.0" - flutter: ">=3.13.0" diff --git a/pubspec.yaml b/pubspec.yaml index 9a578c22..9bf5c184 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,20 +11,20 @@ environment: dependencies: flutter: sdk: flutter - http: ^1.1.0 - dio: ^5.3.3 - flutter_local_notifications: ^16.1.0 + http: ^1.0.0 + dio: ^5.1.2 + flutter_local_notifications: ^14.1.1 rxdart: ^0.27.7 - path_provider: ^2.1.1 - permission_handler: ^11.0.1 - package_info_plus: ^4.2.0 - open_filex: ^4.3.4 - sensors_plus: ^3.1.0 - share_plus: ^7.2.1 + path_provider: ^2.0.15 + permission_handler: ^10.2.0 + package_info_plus: ^4.0.2 + open_filex: ^4.3.2 + sensors_plus: ^3.0.2 + share_plus: ^7.0.2 chopper: ^7.0.9 - collection: ^1.17.2 - url_launcher: ^6.2.1 + collection: ^1.17.1 + url_launcher: ^6.1.6 dev_dependencies: lint: ^2.1.2