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

Not providing blurValue causes Exception: Please provide ShowCaseView context #182

Closed
cirediew opened this issue Feb 4, 2022 · 0 comments · Fixed by #191
Closed

Not providing blurValue causes Exception: Please provide ShowCaseView context #182

cirediew opened this issue Feb 4, 2022 · 0 comments · Fixed by #191
Labels
bug Something isn't working

Comments

@cirediew
Copy link

cirediew commented Feb 4, 2022

Not providing blurValue causes an exception when using a ReorderableListView

My code:

import 'package:flutter/material.dart';
import 'package:showcaseview/showcaseview.dart';
import 'package:test_app/my_list.dart';

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: ShowCaseWidget(
        builder: Builder(
          builder: (_) => const MyList(),
        ),
      ),
    );
  }
}
import 'package:flutter/material.dart';
import 'package:showcaseview/showcaseview.dart';

class MyList extends StatefulWidget {
  const MyList({Key? key}) : super(key: key);

  @override
  _MyListState createState() => _MyListState();
}

class _MyListState extends State<MyList> {
  final List<int> _items = List<int>.generate(50, (int index) => index);
  final GlobalKey _one = GlobalKey();

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance!.addPostFrameCallback(
        (_) => ShowCaseWidget.of(context)!.startShowCase([_one]));
  }

  @override
  Widget build(BuildContext context) {
    final ColorScheme colorScheme = Theme.of(context).colorScheme;
    final Color oddItemColor = colorScheme.primary.withOpacity(0.05);
    final Color evenItemColor = colorScheme.primary.withOpacity(0.15);

    return ReorderableListView(
      children: <Widget>[
        for (int index = 0; index < _items.length; index++)
          if (index == 0)
            Showcase(
              key: _one,
              description: 'MyDescription',
              child: ListTile(
                key: Key('$index'),
                tileColor: _items[index].isOdd ? oddItemColor : evenItemColor,
                title: Text('Item ${_items[index]}'),
              ),
            )
          else
            ListTile(
              key: Key('$index'),
              tileColor: _items[index].isOdd ? oddItemColor : evenItemColor,
              title: Text('Item ${_items[index]}'),
            ),
      ],
      onReorder: (int oldIndex, int newIndex) {
        setState(() {
          if (oldIndex < newIndex) {
            newIndex -= 1;
          }
          final int item = _items.removeAt(oldIndex);
          _items.insert(newIndex, item);
        });
      },
    );
  }
}
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following _Exception was thrown building
_OverlayEntryWidget-[LabeledGlobalKey<_OverlayEntryWidgetState>#8a869](dirty, dependencies:
[MediaQuery], state: _OverlayEntryWidgetState#1cbb4):
Exception: Please provide ShowCaseView context
The relevant error-causing widget was:
  MaterialApp MaterialApp:file:///Users/user/development/app/lib/main.dart:55:22
When the exception was thrown, this was the stack:
#0      ShowCaseWidget.of (package:showcaseview/src/showcase_widget.dart:66:7)
#1      _ShowcaseState.buildOverlayOnTarget (package:showcaseview/src/showcase.dart:266:52)
#2      _ShowcaseState.build.<anonymous closure> (package:showcaseview/src/showcase.dart:222:16)
#3      AnchoredOverlay.build.<anonymous closure>.<anonymous closure> (package:showcaseview/src/layout_overlays.dart:82:35)
#4      _OverlayEntryWidgetState.build (package:flutter/src/widgets/overlay.dart:208:34)
#5      StatefulElement.build (package:flutter/src/widgets/framework.dart:4705:27)
#6      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4588:15)
#7      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4763:11)
#8      Element.rebuild (package:flutter/src/widgets/framework.dart:4311:5)
#9      StatefulElement.update (package:flutter/src/widgets/framework.dart:4795:5)
#10     Element.updateChild (package:flutter/src/widgets/framework.dart:3370:15)
#11     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5626:32)
#12     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6284:17)
#13     Element.updateChild (package:flutter/src/widgets/framework.dart:3370:15)
#14     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4613:16)
#15     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4763:11)
#16     Element.rebuild (package:flutter/src/widgets/framework.dart:4311:5)
#17     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2578:33)
#18     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:882:21)
#19     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:363:5)
#20     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1145:15)
#21     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1082:9)
#22     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:996:5)
#26     _invoke (dart:ui/hooks.dart:150:10)
#27     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:270:5)
#28     _drawFrame (dart:ui/hooks.dart:114:31)
(elided 3 frames from dart:async)
════════════════════════════════════════════════════════════════════════════════════════════════════

It works fine when I do provide a blurValue like so:

Showcase(
              key: _one,
              description: 'MyDescription',
              blurValue: 0.0,
              child: ListTile(
                key: Key('$index'),
                tileColor: _items[index].isOdd ? oddItemColor : evenItemColor,
                title: Text('Item ${_items[index]}'),
              ),
            )
@vatsaltanna vatsaltanna added the bug Something isn't working label Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants