Repository: rrousselGit/flutter_hooks
Pull request #238 (2021-04-23 11:13:20)

async with stack trace
Add statck trace to async snapshot

rrousselGit: Thanks!

Could you add tests?
Goxiaoy: ```
Avoid annotating types for function expression parameters.dart(avoid_types_on_closure_parameters)
```

`onError: (dynamic error, StackTrace stackTrace) ` disobey the `avoid_types_on_closure_parameters` lint rule, should I disable that temporally?


And once `dynamic` or `StackTrace` removed, `implicit_dynamic_parameter` is triggered
```
Try adding an explicit type, or remove implicit-dynamic from your analysis options file.dart(implicit_dynamic_parameter)
```

codecov[bot]: # [Codecov](https://codecov.io/gh/rrousselGit/flutter_hooks/pull/238?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Remi+Rousselet) Report
> Merging [#238](https://codecov.io/gh/rrousselGit/flutter_hooks/pull/238?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Remi+Rousselet) (5d89ac7) into [master](https://codecov.io/gh/rrousselGit/flutter_hooks/commit/4b217bfd26da9419d8eef5208186d4a1c26c050b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Remi+Rousselet) (4b217bf) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/rrousselGit/flutter_hooks/pull/238/graphs/tree.svg?width=650&height=150&src=pr&token=9aGHUI8Y7c&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Remi+Rousselet)](https://codecov.io/gh/rrousselGit/flutter_hooks/pull/238?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Remi+Rousselet)

```diff
@@            Coverage Diff            @@
##            master      #238   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           11        11           
  Lines          610       610           
=========================================
  Hits           610       610           
```


| [Impacted Files](https://codecov.io/gh/rrousselGit/flutter_hooks/pull/238?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Remi+Rousselet) | Coverage Δ | |
|---|---|---|
| [packages/flutter\_hooks/lib/src/async.dart](https://codecov.io/gh/rrousselGit/flutter_hooks/pull/238/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Remi+Rousselet#diff-cGFja2FnZXMvZmx1dHRlcl9ob29rcy9saWIvc3JjL2FzeW5jLmRhcnQ=) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/rrousselGit/flutter_hooks/pull/238?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Remi+Rousselet).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Remi+Rousselet)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/rrousselGit/flutter_hooks/pull/238?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Remi+Rousselet). Last update [4b217bf...5d89ac7](https://codecov.io/gh/rrousselGit/flutter_hooks/pull/238?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Remi+Rousselet). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Remi+Rousselet).


Patch:
diff --git a/packages/flutter_hooks/lib/src/async.dart b/packages/flutter_hooks/lib/src/async.dart
index bdb9974..6221551 100644
--- a/packages/flutter_hooks/lib/src/async.dart
+++ b/packages/flutter_hooks/lib/src/async.dart
@@ -83,11 +83,15 @@ class _FutureStateHook<T> extends HookState<AsyncSnapshot<T>, _FutureHook<T>> {
             _snapshot = AsyncSnapshot<T>.withData(ConnectionState.done, data);
           });
         }
-      }, onError: (dynamic error) {
+        // ignore: avoid_types_on_closure_parameters
+      }, onError: (Object error, StackTrace stackTrace) {
         if (_activeCallbackIdentity == callbackIdentity) {
           setState(() {
             _snapshot = AsyncSnapshot<T>.withError(
-                ConnectionState.done, error as Object);
+              ConnectionState.done,
+              error,
+              stackTrace,
+            );
           });
         }
       });
@@ -186,9 +190,10 @@ class _StreamHookState<T> extends HookState<AsyncSnapshot<T>, _StreamHook<T>> {
         setState(() {
           _summary = afterData(data);
         });
-      }, onError: (dynamic error) {
+        // ignore: avoid_types_on_closure_parameters
+      }, onError: (Object error, StackTrace stackTrace) {
         setState(() {
-          _summary = afterError(error as Object);
+          _summary = afterError(error, stackTrace);
         });
       }, onDone: () {
         setState(() {
@@ -219,8 +224,12 @@ class _StreamHookState<T> extends HookState<AsyncSnapshot<T>, _StreamHook<T>> {
     return AsyncSnapshot<T>.withData(ConnectionState.active, data);
   }
 
-  AsyncSnapshot<T> afterError(Object error) {
-    return AsyncSnapshot<T>.withError(ConnectionState.active, error);
+  AsyncSnapshot<T> afterError(Object error, StackTrace stackTrace) {
+    return AsyncSnapshot<T>.withError(
+      ConnectionState.active,
+      error,
+      stackTrace,
+    );
   }
 
   AsyncSnapshot<T> afterDone(AsyncSnapshot<T> current) =>


Test patch:
diff --git a/packages/flutter_hooks/test/use_future_test.dart b/packages/flutter_hooks/test/use_future_test.dart
index b1f4596..38422b2 100644
--- a/packages/flutter_hooks/test/use_future_test.dart
+++ b/packages/flutter_hooks/test/use_future_test.dart
@@ -134,10 +134,12 @@ void main() {
         find.text(
             'AsyncSnapshot<String?>(ConnectionState.waiting, null, null, null)'),
         findsOneWidget);
-    completer.completeError('bad');
+    completer.completeError('bad', StackTrace.fromString('stackTrace'));
     await eventFiring(tester);
     expect(
-        find.text('AsyncSnapshot<String?>(ConnectionState.done, null, bad, )'),
+        find.text(
+          'AsyncSnapshot<String?>(ConnectionState.done, null, bad, stackTrace)',
+        ),
         findsOneWidget);
   });
   testWidgets('runs the builder using given initial data', (tester) async {
diff --git a/packages/flutter_hooks/test/use_stream_test.dart b/packages/flutter_hooks/test/use_stream_test.dart
index 8dd1ab2..9e31b27 100644
--- a/packages/flutter_hooks/test/use_stream_test.dart
+++ b/packages/flutter_hooks/test/use_stream_test.dart
@@ -127,10 +127,12 @@ void main() {
         findsOneWidget);
     controller
       ..add('3')
-      ..addError('bad');
+      ..addError('bad', StackTrace.fromString('stackTrace'));
     await eventFiring(tester);
     expect(
-        find.text('AsyncSnapshot<String>(ConnectionState.active, null, bad, )'),
+        find.text(
+          'AsyncSnapshot<String>(ConnectionState.active, null, bad, stackTrace)',
+        ),
         findsOneWidget);
     controller.add('4');
     await controller.close();