Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show Unhandled Exception: Null check operator used on a null value error #138

Closed
P-B1101 opened this issue Sep 5, 2021 · 5 comments · Fixed by #142
Closed

show Unhandled Exception: Null check operator used on a null value error #138

P-B1101 opened this issue Sep 5, 2021 · 5 comments · Fixed by #142

Comments

@P-B1101
Copy link
Contributor

P-B1101 commented Sep 5, 2021

Describe the bug
When I update package to version 1.1.1 and run the app, it show this error in console and the showcase itself not working.

Console

/flutter ( 2417): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Null check operator used on a null value E/flutter ( 2417): #0 _OverlayBuilderState.addToOverlay package:showcaseview/src/layout_overlays.dart:163 E/flutter ( 2417): #1 _OverlayBuilderState.showOverlay package:showcaseview/src/layout_overlays.dart:155 E/flutter ( 2417): #2 _OverlayBuilderState.initState.<anonymous closure> package:showcaseview/src/layout_overlays.dart:120 E/flutter ( 2417): #3 SchedulerBinding._invokeFrameCallback package:flutter/…/scheduler/binding.dart:1144 E/flutter ( 2417): #4 SchedulerBinding.handleDrawFrame package:flutter/…/scheduler/binding.dart:1090 E/flutter ( 2417): #5 SchedulerBinding._handleDrawFrame package:flutter/…/scheduler/binding.dart:998 E/flutter ( 2417): #6 _rootRun (dart:async/zone.dart:1354:13) E/flutter ( 2417): #7 _CustomZone.run (dart:async/zone.dart:1258:19) E/flutter ( 2417): #8 _CustomZone.runGuarded (dart:async/zone.dart:1162:7) E/flutter ( 2417): #9 _invoke (dart:ui/hooks.dart:163:10) E/flutter ( 2417): #10 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:259:5) E/flutter ( 2417): #11 _drawFrame (dart:ui/hooks.dart:126:31)

@vatsaltanna
Copy link
Collaborator

@P-B1101 can you please share snippet code in which you are facing this issue?

@vatsaltanna vatsaltanna added the more-info-required Provide more information label Sep 13, 2021
@P-B1101
Copy link
Contributor Author

P-B1101 commented Sep 14, 2021

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 ShowCaseWidget(
      builder: Builder(builder: (context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: const MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

const int showCaseTriger = 5;

class _MyHomePageState extends State<MyHomePage> {
  final GlobalKey gKey = GlobalKey();
  int _counter = 0;

  void _incrementCounter() {
    if (_counter > showCaseTriger) return;
    if (_counter == showCaseTriger) {
      ShowCaseWidget.of(context)?.startShowCase([gKey]);
      return;
    }
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Showcase(
              title: 'Test Title\n',
              description: 'Test Description',
              key: gKey,
              overlayColor: Theme.of(context).primaryColor,
              showcaseBackgroundColor: Colors.transparent,
              showArrow: false,
              disableAnimation: true,
              contentPadding: const EdgeInsets.only(
                top: 8,
                bottom: 8,
                left: 16,
                right: 16,
              ),
              child: Text(
                'Push the button ${showCaseTriger - _counter} more times to trigger the show case.',
              ),
              disposeOnTap: true,
              onTargetClick: () {},
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

@vatsaltanna
Copy link
Collaborator

vatsaltanna commented Sep 15, 2021

@P-B1101 We identified the reason of error that you are facing with your widget tree
please place ShowCaseWidget inside MaterialApp.

Your Current Widget Tree:
main() -> ShowCaseWidget -> MaterialApp -> MyHomePage

Update widget tree with below sequence:
main() -> MaterialApp -> ShowCaseWidget -> MyHomePage

We have handled this issue with your widget tree structure as well and will be available in next release.

@vatsaltanna vatsaltanna removed the more-info-required Provide more information label Sep 15, 2021
@vatsaltanna
Copy link
Collaborator

I am closing this issue for now, feel free to reopen this issue if the given solution is not working.

@P-B1101
Copy link
Contributor Author

P-B1101 commented Sep 15, 2021

Thank you, your solution fix the issue :) .

meetjanani pushed a commit to meetjanani/flutter_showcaseview that referenced this issue Sep 15, 2021
meetjanani pushed a commit to meetjanani/flutter_showcaseview that referenced this issue Oct 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants