HomeX-It / open-mail-app-flutter

This library provides the ability to query the device for installed email apps and open those apps.
MIT License
36 stars 91 forks source link

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Null check operator used on a null value. Error thrown Instance of 'ErrorDescription'. #46

Open ablbol opened 2 years ago

ablbol commented 2 years ago

Thank you for this great library. I am running the library on android 12 without any problems. But when my designer runs the app on android 9, she gets an exception. The device does have Gmail installed on it. I was able to see the exception in Crashlytics. Any one knows the problem ? Here is the exception (code that launches the email client is below):

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Null check operator used on a null value. Error thrown Instance of 'ErrorDescription'.
       at EmailModalBottomSheet.build.<fn>(build.java:58)
       at SetMixin.toList(SetMixin.java)
       at EmailModalBottomSheet.build(EmailModalBottomSheet.java:73)
       at StatelessElement.build(StatelessElement.java:4827)
       at HookElement.build(HookElement.java:416)
       at ComponentElement.performRebuild(ComponentElement.java:4754)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at StatefulElement._firstBuild(StatefulElement.java:4919)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at SingleChildRenderObjectElement.mount(SingleChildRenderObjectElement.java:6284)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at SingleChildRenderObjectElement.mount(SingleChildRenderObjectElement.java:6284)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at SingleChildRenderObjectElement.mount(SingleChildRenderObjectElement.java:6284)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at StatefulElement._firstBuild(StatefulElement.java:4919)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at StatefulElement._firstBuild(StatefulElement.java:4919)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at SingleChildRenderObjectElement.mount(SingleChildRenderObjectElement.java:6284)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at StatefulElement._firstBuild(StatefulElement.java:4919)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at StatefulElement._firstBuild(StatefulElement.java:4919)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at SingleChildRenderObjectElement.mount(SingleChildRenderObjectElement.java:6284)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at SingleChildRenderObjectElement.mount(SingleChildRenderObjectElement.java:6284)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at SingleChildRenderObjectElement.mount(SingleChildRenderObjectElement.java:6284)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at StatefulElement._firstBuild(StatefulElement.java:4919)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at StatefulElement._firstBuild(StatefulElement.java:4919)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at SingleChildRenderObjectElement.mount(SingleChildRenderObjectElement.java:6284)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at SingleChildRenderObjectElement.mount(SingleChildRenderObjectElement.java:6284)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at StatefulElement._firstBuild(StatefulElement.java:4919)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at StatefulElement._firstBuild(StatefulElement.java:4919)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at SingleChildRenderObjectElement.mount(SingleChildRenderObjectElement.java:6284)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at SingleChildRenderObjectElement.mount(SingleChildRenderObjectElement.java:6284)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at SingleChildRenderObjectElement.mount(SingleChildRenderObjectElement.java:6284)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at StatefulElement._firstBuild(StatefulElement.java:4919)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at StatefulElement._firstBuild(StatefulElement.java:4919)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at SingleChildRenderObjectElement.mount(SingleChildRenderObjectElement.java:6284)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at StatefulElement._firstBuild(StatefulElement.java:4919)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at StatefulElement._firstBuild(StatefulElement.java:4919)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at StatefulElement._firstBuild(StatefulElement.java:4919)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at SingleChildRenderObjectElement.mount(SingleChildRenderObjectElement.java:6284)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at StatefulElement._firstBuild(StatefulElement.java:4919)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at Element.updateChild(Element.java:3540)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at ComponentElement._firstBuild(ComponentElement.java:4735)
       at StatefulElement._firstBuild(StatefulElement.java:4919)
       at ComponentElement.mount(ComponentElement.java:4729)
       at Element.inflateWidget(Element.java:3790)
       at MultiChildRenderObjectElement.inflateWidget(MultiChildRenderObjectElement.java:6422)
       at Element.updateChild(Element.java:3540)
       at RenderObjectElement.updateChildren(RenderObjectElement.java:5845)
       at MultiChildRenderObjectElement.update(MultiChildRenderObjectElement.java:6445)
       at Element.updateChild(Element.java:3501)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at StatefulElement.update(StatefulElement.java:4960)
       at Element.updateChild(Element.java:3501)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ProxyElement.update(ProxyElement.java:5108)
       at Element.updateChild(Element.java:3501)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ProxyElement.update(ProxyElement.java:5108)
       at _InheritedNotifierElement.update(_InheritedNotifierElement.java:111)
       at Element.updateChild(Element.java:3501)
       at SingleChildRenderObjectElement.update(SingleChildRenderObjectElement.java:6291)
       at Element.updateChild(Element.java:3501)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at StatefulElement.update(StatefulElement.java:4960)
       at Element.updateChild(Element.java:3501)
       at SingleChildRenderObjectElement.update(SingleChildRenderObjectElement.java:6291)
       at Element.updateChild(Element.java:3501)
       at SingleChildRenderObjectElement.update(SingleChildRenderObjectElement.java:6291)
       at Element.updateChild(Element.java:3501)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at Element.rebuild(Element.java:4477)
       at ProxyElement.update(ProxyElement.java:5108)
       at Element.updateChild(Element.java:3501)
       at ComponentElement.performRebuild(ComponentElement.java:4780)
       at StatefulElement.performRebuild(StatefulElement.java:4928)
       at Element.rebuild(Element.java:4477)
       at BuildOwner.buildScope(BuildOwner.java:2659)
       at WidgetsBinding.drawFrame(WidgetsBinding.java:882)
       at RendererBinding._handlePersistentFrameCallback(RendererBinding.java:363)
       at SchedulerBinding._invokeFrameCallback(SchedulerBinding.java:1144)
       at SchedulerBinding.handleDrawFrame(SchedulerBinding.java:1081)
       at SchedulerBinding._handleDrawFrame(SchedulerBinding.java:995)

Here is the class that launches the email client:

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:oolfa/app_typography.dart';
import 'package:oolfa/widgets/modal_bottom_sheet_header.dart';
import 'package:open_mail_app/open_mail_app.dart';

const supportedEmails = {
  'Airmail': 'assets/email_icons/airmail.png',
  'Apple Mail': 'assets/email_icons/apple_mail.png',
  'Dispatch': 'assets/email_icons/email.png',
  'Fastmail': 'assets/email_icons/fastmail.png',
  'Gmail': 'assets/email_icons/gmail.png',
  'Outlook': 'assets/email_icons/outlook.png',
  'ProtonMail': 'assets/email_icons/proton_mail.png',
  'Spark': 'assets/email_icons/spark.png',
  'Superhuman': 'assets/email_icons/superhuman.png',
  'Yahoo': 'assets/email_icons/yahoo.png',
};

class EmailModalBottomSheet extends HookWidget {
  final List<MailApp> mailApps;

  const EmailModalBottomSheet({required this.mailApps, Key? key})
      : super(key: key);

  Future show(BuildContext context) {
    return showModalBottomSheet(
      context: context,
      builder: (context) => this,
      isScrollControlled: true,
      isDismissible: true,
    );
  }

  @override
  Widget build(BuildContext context) {
    final height = MediaQuery.of(context).size.height;

    return SafeArea(
      child: ConstrainedBox(
        constraints: BoxConstraints.loose(Size.fromHeight(height * .9)),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            ModalBottomSheetHeader(
              title: 'Select mail app',
              onLeftIconPressed: () => Navigator.pop(context),
            ),
            Flexible(
              fit: FlexFit.loose,
              child: ListView(
                shrinkWrap: true,
                children: mailApps.map(
                  (MailApp app) {
                    return ListTile(
                      leading: Image.asset(
                        supportedEmails[app.name]!,
                        width: 24,
                        height: 24,
                      ),
                      title: Text(
                        app.name,
                        style: AppTypography.subtitle1,
                      ),
                      onTap: () {
                        Navigator.pop(context);
                        OpenMailApp.openSpecificMailApp(app);
                      },
                      minLeadingWidth: 26,
                    );
                  },
                ).toList(),
              ),
            ),
            const SizedBox(height: 16),
          ],
        ),
      ),
    );
  }
}
BazinC commented 2 years ago

From these 2 lines

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Null check operator used on a null value. Error thrown Instance of 'ErrorDescription'.
       at EmailModalBottomSheet.build.<fn>(build.java:58)

I guess supportedEmails[app.name]! raise the error because app.name is not present in your supportedEmails assets map.

I don't know what mailApps list you are providing to your widget, but I suggest you filter supported mailApps first instead of using '!' operator. final supportedApps = mailApps.where((app) => supportedEmails.containsKey(app.name)).toList();

And I don't think you need HookWidget here :) StatelessWidget is enough