diff --git a/examples/alice_dio/analysis_options.yaml b/examples/alice_dio/analysis_options.yaml index 01f89e9c..d4e71cb5 100644 --- a/examples/alice_dio/analysis_options.yaml +++ b/examples/alice_dio/analysis_options.yaml @@ -1,16 +1,12 @@ -1include: package:very_good_analysis/analysis_options.yaml +analyzer: + exclude: + - "lib/generated_plugin_registrant.dart" + - "**.g.dart" + - "**.mocks.dart" + - "**.gen.dart" + +include: package:flutter_lints/flutter.yaml linter: rules: - public_member_api_docs: false - flutter_style_todos: false - avoid_final_parameters: false - sort_constructors_first: false - avoid_function_literals_in_foreach_calls: false - avoid_positional_boolean_parameters: false - use_if_null_to_convert_nulls_to_bools: false - use_build_context_synchronously: false - prefer_constructors_over_static_methods: false - use_setters_to_change_properties: false - avoid_print: false - sort_pub_dependencies: false \ No newline at end of file + #library_annotations: false diff --git a/examples/alice_dio/lib/main.dart b/examples/alice_dio/lib/main.dart index 089a4b22..c1913b67 100644 --- a/examples/alice_dio/lib/main.dart +++ b/examples/alice_dio/lib/main.dart @@ -5,40 +5,31 @@ import 'package:alice_dio/alice_dio_adapter.dart'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:path/path.dart' as p; -void main() => runApp(MyApp()); +void main() => runApp(const MyApp()); class MyApp extends StatefulWidget { + const MyApp({super.key}); + @override - _MyAppState createState() => _MyAppState(); + State createState() => _MyAppState(); } class _MyAppState extends State { - late Alice _alice; - late Dio _dio; - late AliceDioAdapter _aliceDioAdapter; - - @override - void initState() { - _alice = Alice( - showNotification: true, - showInspectorOnShake: true, - maxCallsCount: 1000, - ); - _aliceDioAdapter = AliceDioAdapter(); - _dio = Dio(BaseOptions( - followRedirects: false, - )); + late final AliceDioAdapter _aliceDioAdapter = AliceDioAdapter(); - _dio.interceptors.add(_aliceDioAdapter); - _alice.addAdapter(_aliceDioAdapter); + late final Alice _alice = Alice( + showNotification: true, + showInspectorOnShake: true, + maxCallsCount: 1000, + )..addAdapter(_aliceDioAdapter); - super.initState(); - } + late final Dio _dio = Dio(BaseOptions(followRedirects: false)) + ..interceptors.add(_aliceDioAdapter); @override Widget build(BuildContext context) { - return MaterialApp( navigatorKey: _alice.getNavigatorKey(), debugShowCheckedModeBanner: false, @@ -47,28 +38,31 @@ class _MyAppState extends State { title: const Text('Alice + Dio - Example'), ), body: Container( - padding: EdgeInsets.all(16), + padding: const EdgeInsets.all(16), child: ListView( children: [ const SizedBox(height: 8), - Text( - 'Welcome to example of Alice + Dio Example. Click buttons below to generate sample data.'), + const Text( + style: TextStyle(fontSize: 14), + 'Welcome to example of Alice + Dio Example. ' + 'Click buttons below to generate sample data.', + ), ElevatedButton( - child: Text( + onPressed: _runDioRequests, + child: const Text( 'Run Dio HTTP Requests', ), - onPressed: _runDioRequests, ), - - Text( + const SizedBox(height: 8), + const Text( + style: TextStyle(fontSize: 14), 'After clicking on buttons above, you should receive notification.' ' Click on it to show inspector. You can also shake your device or click button below.'), ElevatedButton( - child: Text( + onPressed: _runHttpInspector, + child: const Text( 'Run HTTP Inspector', ), - onPressed: _runHttpInspector, - ) ], ), @@ -77,23 +71,25 @@ class _MyAppState extends State { ); } - void _runDioRequests() async { - Map body = { + final Map body = { 'title': 'foo', 'body': 'bar', 'userId': '1' }; _dio.get( - 'https://httpbin.org/redirect-to?url=https%3A%2F%2Fhttpbin.org'); + '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.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'); @@ -101,33 +97,40 @@ class _MyAppState extends State { _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'); + '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'); - final directory = await getApplicationDocumentsDirectory(); - File file = File('${directory.path}/test.txt'); - file.create(); - file.writeAsStringSync('123456789'); + final Directory directory = await getApplicationDocumentsDirectory(); + final File file = File(p.join(directory.path, 'test.txt')); + if (!await file.exists()) { + await file.create(); + } + await file.writeAsString('123456789'); - String fileName = file.path.split('/').last; - FormData formData = FormData.fromMap({ + final String fileName = file.path.split('/').last; + final FormData formData = FormData.fromMap({ 'file': await MultipartFile.fromFile(file.path, filename: fileName), }); - _dio.post('https://jsonplaceholder.typicode.com/photos', - data: formData); + _dio.post( + 'https://jsonplaceholder.typicode.com/photos', + data: formData, + ); _dio.get('http://dummy.restapiexample.com/api/v1/employees'); } - void _runHttpInspector() { _alice.showInspector(); } diff --git a/examples/alice_dio/pubspec.yaml b/examples/alice_dio/pubspec.yaml index 5a6d0d4b..bb7623f9 100644 --- a/examples/alice_dio/pubspec.yaml +++ b/examples/alice_dio/pubspec.yaml @@ -12,8 +12,13 @@ dependencies: sdk: flutter alice: alice_dio: + path_provider: ^2.1.3 + path: ^1.9.0 dio: ^5.4.3+1 +dev_dependencies: + flutter_lints: ^4.0.0 + dependency_overrides: alice: path: ../../packages/alice