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

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

Closed
2 tasks done
openl4m4 opened this issue May 26, 2024 · 3 comments
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@openl4m4
Copy link

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
@openl4m4 openl4m4 added the bug Something isn't working label May 26, 2024
@openl4m4
Copy link
Author

openl4m4 commented Jun 4, 2024

Hello,

Anyone for a little help here please?

@junaid1460
Copy link

junaid1460 commented Aug 21, 2024

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)}
  }
} 

@openl4m4
Copy link
Author

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

Have a great day!

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
Development

No branches or pull requests

2 participants