minikin/popover

[Bug]: type 'RenderSliverList' is not a subtype of type 'RenderBox?' in type cast

Closed this issue ยท 3 comments

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Hello,

I'm facing an issue when calling a showPopover inside a Function while the same showPopover works when called directly from an appBar.

Here's my code from the Scaffold body and then it goes loop --> StreamBuilder --> Function --> showPopover:

      body: ListView.builder(
        itemCount: selectedPlayers.length,
        itemBuilder: (context, index) {
          _initPlayerStatistics(
            widget.teamId,
            widget.gameId,
            widget.setNumber,
            selectedPlayers[index].id,
          );

          return Card(
            margin: const EdgeInsets.all(5),
            shape: Theme.of(context).cardTheme.shape,
            child: SingleChildScrollView(
              scrollDirection: Axis.horizontal,
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Column(
                    children: [
                     xxxxxx
                    ],
                  ),
                  for (int section = 0;
                      section <= basicSections.length - 1;
                      section++)
                    SizedBox(
                      height: 115,
                      width: 100,
                      child: StreamBuilder<List<Statistics>>(
                          stream: objectbox.getContinuousPlayerStats(
                            widget.teamId,
                            widget.gameId,
                            widget.setNumber,
                            selectedPlayers[index].id,
                          ),
                          builder: (context, snapshot) => ListView.builder(
                              shrinkWrap: true,
                              itemCount:
                                  snapshot.hasData ? snapshot.data!.length : 0,
                              itemBuilder: _statsBuilder(
                                  snapshot.data ?? [],
                                  widget.teamId,
                                  widget.gameId,
                                  widget.setNumber,
                                  selectedPlayers[index].id,
                                  section))),
                    )
                ],
              ),
            ),
          );

Column Function(BuildContext, int) _statsBuilder(List<Statistics> stats,
          int teamId, int gameId, int setNumber, int playerId, int section) =>
      (BuildContext context, int index) {
        return Column(
          children: [
            Container(
                ....
              ),
              child: GestureDetector(
                child: Center(
                  child: Text(basicSections[section].title,
                      style: const TextStyle(
                          fontSize: 10.0,
                          fontWeight: FontWeight.bold,
                          color: Colors.black)),
                ),
                onTap: () {
                  showPopover(
                    context: context,
                    bodyBuilder: (context) => const ListItems(),
                    onPop: () => print('Popover was popped!'),
                    direction: PopoverDirection.bottom,
                    width: 200,
                    height: 400,
                    arrowHeight: 15,
                    arrowWidth: 30,
                  );
                },
              ),
            ),

The issue seems to come from the following part of the code:

# lib/src/utils/build_context_extension.dart:10

  static Offset? getWidgetLocalToGlobal(BuildContext context) {
    final box = context.findRenderObject() as RenderBox?;
    return (box != null) ? box.localToGlobal(Offset.zero) : null;
  }

Could it be a context or key issue not finding the object to render?

Thanks a lot, and great job with this package ๐Ÿ‘ :)

Expected Behavior

I'd like to be able to showPopover wherever I want.

What operating system are you seeing the problem on?

Android

Relevant log output

โ•โ•โ•โ•โ•โ•โ•โ• Exception caught by widgets library โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
The following _TypeError was thrown building PopScope(dependencies: [_ModalScopeStatus], state: _PopScopeState#f3a14):
type 'RenderSliverList' is not a subtype of type 'RenderBox?' in type cast

The relevant error-causing widget was:
    MaterialApp MaterialApp:file:///home/kin/workspace/devapes/volleyball_stats/lib/main.dart:26:12

When the exception was thrown, this was the stack:
#0      BuildContextExtension.getWidgetLocalToGlobal (package:popover/src/utils/build_context_extension.dart:10:44)
build_context_extension.dart:10
#1      _PopoverItemState._configureRect (package:popover/src/popover_item.dart:140:42)
popover_item.dart:140
#2      _PopoverItemState.initState (package:popover/src/popover_item.dart:99:5)
popover_item.dart:99
#3      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5611:55)
framework.dart:5611
#4      ComponentElement.mount (package:flutter/src/widgets/framework.dart:5456:5)
framework.dart:5456
...     Normal element mounting (180 frames)

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Hello,

Anyone for a little help here please?

The problem is in the code of calculating offset, alternatively solution is to wrap your items in a

Container{ 
  Builder (builderContext) { 
     GestureDetector { onTap = showPopOver(builderContext)}
  }
} 

Thanks Junaid, it works now :) I'll experiment more with the package.

Have a great day!