jhomlala / catcher

Flutter error catching & handling plugin. Handles and reports exceptions in your app!
Apache License 2.0
784 stars 175 forks source link

[BUG] Catcher is not triggered #230

Open MichalNemec opened 2 years ago

MichalNemec commented 2 years ago

Describe the bug Basic settings and i dont see any dialog.

To Reproduce

import 'package:catcher/catcher.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await initServices();

  CatcherOptions debugOptions =
      CatcherOptions(DialogReportMode(), [ConsoleHandler()]);

  /// Release configuration. Same as above, but once user accepts dialog, user will be prompted to send email with crash to support.
  CatcherOptions releaseOptions = CatcherOptions(DialogReportMode(), [
    EmailManualHandler(["cy@as.as"])
  ]);

  Catcher(
    rootWidget: const MyApp(),
    debugConfig: debugOptions,
    releaseConfig: releaseOptions,
    enableLogger: true,
    ensureInitialized: true,
  );
  //runApp(const MyApp());
}

Future<void> initServices() async {
  print('starting services ...');
  await Get.putAsync(() => PrefsService().init());
  print('All services started...');
}

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

  @override
  Widget build(BuildContext context) {
    String initialPath = "/welcome";
    PrefsService storage = Get.find();

    return MaterialApp(
      /// STEP 3. Add navigator key from Catcher. It will be used to navigate user to report page or to show dialog.
      navigatorKey: Catcher.navigatorKey,
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: ChildWidget()),
    );
  }
}
class ChildWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
            child: TextButton(
                child: Text("Generate error"),
                onPressed: () => generateError()));
  }

  generateError() async {
    throw "Test exception";
  }
}

Expected behavior see error dialog, to test it

Flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.5 21G72 darwin-arm, locale en-CZ)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.70.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

• No issues found!

Catcher version

Smartphone (please complete the following information):

Additional context running in vscode by run -> run without debugging | with debugging produces same stuff. Only exception in debug console as if catcher is not even there.

calcitem commented 1 year ago

https://github.com/calcitem/Sanmill/commit/9de1aff2e4218875b46f083a1a5766c37d836bc3

PlatformDispatcher.instance.onError = (error, stack) {

        Catcher.reportCheckedError(error, stack);

      return true;
    };