csells / go_router

The purpose of the go_router for Flutter is to use declarative routes to reduce complexity, regardless of the platform you're targeting (mobile, web, desktop), handling deep linking from Android, iOS and the web while still allowing an easy-to-use developer experience.
https://gorouter.dev
442 stars 96 forks source link

[error message] GoRouter of(BuildContext context) error message is not useful #114

Closed aoatmon closed 2 years ago

aoatmon commented 2 years ago

To Reproduce

import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart';

void main() { runApp(const MyApp()); }

class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key);

// This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( home: Material( child: Center( child: MaterialButton( child: const Text('go somewhere'), onPressed: () => GoRouter.of(context).go('places'), ), ), ), ); } }


due to the implementation below

```dart
  /// Find the current GoRouter in the widget tree.
  static GoRouter of(BuildContext context) =>
      context.dependOnInheritedWidgetOfExactType<InheritedGoRouter>()!.goRouter;

in place of the canonical one

Expected behavior provide a useful error message

Actual behavior provide a vague error message

══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
The following TypeErrorImpl was thrown while handling a gesture:
Unexpected null value.

When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49      throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 528:63  nullCheck
packages/go_router/src/go_router.dart 170:72                                      of
packages/go_route_context_issue/main.dart 19:51                                   <fn>
packages/flutter/src/material/ink_well.dart 989:21                                [_handleTap]
packages/flutter/src/gestures/recognizer.dart 193:24                              invokeCallback
packages/flutter/src/gestures/tap.dart 608:48                                     handleTapUp
packages/flutter/src/gestures/tap.dart 296:5                                      [_checkUp]
packages/flutter/src/gestures/tap.dart 230:7                                      handlePrimaryPointer
packages/flutter/src/gestures/recognizer.dart 558:9                               handleEvent
packages/flutter/src/gestures/pointer_router.dart 94:12                           [_dispatch]
packages/flutter/src/gestures/pointer_router.dart 139:9                           <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/linked_hash_map.dart 21:13          forEach
packages/flutter/src/gestures/pointer_router.dart 137:17                          [_dispatchEventToRoutes]
packages/flutter/src/gestures/pointer_router.dart 123:7                           route
packages/flutter/src/gestures/binding.dart 440:19                                 handleEvent
packages/flutter/src/gestures/binding.dart 420:14                                 dispatchEvent
packages/flutter/src/rendering/binding.dart 278:11                                dispatchEvent
packages/flutter/src/gestures/binding.dart 374:7                                  [_handlePointerEventImmediately]
packages/flutter/src/gestures/binding.dart 338:5                                  handlePointerEvent
packages/flutter/src/gestures/binding.dart 296:7                                  [_flushPointerEventQueue]
packages/flutter/src/gestures/binding.dart 279:32                                 [_handlePointerDataPacket]
lib/_engine/engine/platform_dispatcher.dart 1018:13                               invoke1
lib/_engine/engine/platform_dispatcher.dart 182:5                                 invokeOnPointerDataPacket
lib/_engine/engine/pointer_binding.dart 130:39                                    [_onPointerData]
lib/_engine/engine/pointer_binding.dart 555:18                                    <fn>
lib/_engine/engine/pointer_binding.dart 508:21                                    <fn>
lib/_engine/engine/pointer_binding.dart 216:16                                    loggedHandler

Handler: "onTap"
Recognizer:
  TapGestureRecognizer#fb584
csells commented 2 years ago

@aoatmon that's an excellent bug report and a good catch -- you're right, that's a terrible message. I'll fix this ASAP.

csells commented 2 years ago

fixed in v2.2.1. @aoatmon can you confirm?