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]: ApiVideoCameraPreview as Column element causes Exception: BoxConstraints forces an infinite height #56

Open
1 of 2 tasks
kaz080 opened this issue Jun 3, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@kaz080
Copy link

kaz080 commented Jun 3, 2024

Version

v1.2.0

Which operating systems have you used?

  • Android
  • iOS

Environment that reproduces the issue

  • iPhone (13 Pro / 17.5.1)
  • Flutter 3.19.1

Is it reproducible in the example application?

Yes

RTMP Server

none

Reproduction steps

I want the camera preview to remain full screen when the keyboard is opened,
so I put it inside a SingleChildScrollView.

Replace example with the following to reproduce:

Widget build(BuildContext context) {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      appBar: AppBar(
        title: const Text('Live Stream Example'),
        actions: <Widget>[
          PopupMenuButton<String>(
            onSelected: (choice) => _onMenuSelected(choice, context),
            itemBuilder: (BuildContext context) {
              return Constants.choices.map((String choice) {
                return PopupMenuItem<String>(
                  value: choice,
                  child: Text(choice),
                );
              }).toList();
            },
          )
        ],
      ),
      body: SafeArea(
        child: Stack(
          children: [
            SingleChildScrollView(
              child: Column(
                children: [
                  ApiVideoCameraPreview(controller: _controller),
                ],
              ),
            ),
            Align(
              alignment: Alignment.centerLeft,
              child: Padding(
                padding: const EdgeInsets.only(left: 16, right: 128),
                child: TextField(
                  decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    labelText: 'Enter text',
                  ),
                ),
              ),
            ),
            Align(
              alignment: Alignment.bottomCenter,
              child: Padding(
                padding: const EdgeInsets.only(bottom: 16.0),
                child: _controlRowWidget(),
              ),
            ),
          ],
        ),
      ),
    );
  }

Expected result

The width is fixed and it would be good if the height is also adjusted automatically.

Actual result

════════ Exception caught by rendering library ═════════════════════════════════
The following assertion was thrown during performLayout():
BoxConstraints forces an infinite height.
These invalid constraints were provided to RenderFittedBox's layout() function by the following function, which probably computed the invalid constraints in question:
  RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:280:14)
The offending constraints were: BoxConstraints(w=390.0, h=Infinity)

Additional context

  • To avoid the error, ApiVideoCameraPreview() needs to be wrapped with AspectRatio(aspectRatio: 9 / 16). However, when the device is in landscape orientation, the aspectRatio becomes incorrect.
  • Since we are getting videoSize and orientation inside ApiVideoCameraPreview, could we put the AspectRatio inside and build with the appropriate aspectRatio?

Relevant logs output

No response

@kaz080 kaz080 added the bug Something isn't working label Jun 3, 2024
@ThibaultBee
Copy link
Member

Hi,

You don't say anything about the fit parameters of ApiVideoCameraPreview. Have you tried to play with that?
Also, have you look for this error on stackoverflow?

@kaz080
Copy link
Author

kaz080 commented Jun 4, 2024

Hi @ThibaultBee!

Yes, I tried fit parameter for all types, but no luck.

Also I've look for this error on stackoverflow, e.g.
https://stackoverflow.com/questions/52442724/boxconstraints-forces-an-infinite-width

As far as I tried, wrapping AspectRatio or SizedBox avoids this error.

(Also, this problem did not occur when I use version 1.0.7.)

@ThibaultBee
Copy link
Member

Do you have the same issue on Android?

@ThibaultBee
Copy link
Member

Have you tried Expanded or Flexible?

@kaz080
Copy link
Author

kaz080 commented Jun 4, 2024

Yes.
Expanded results another exception: RenderFlex children have non-zero flex but incoming height constraints are unbounded.
Flexible also results RenderFlex children have non-zero flex but incoming height constraints are unbounded.

We don't have Android device now...

@ThibaultBee
Copy link
Member

So the preview is trying to occupy the most space inside its container.
If one of the dimension of this container is infinite it will create such issue.
Putting the ApiVideoCameraPreview is a SizedBox that adds a constraint where the dimension is infinite will fix your issue (the height in your case).

SingleChildScrollView(
    child: Column(
      children: [
        SizedBox(
          height: 300,
          child:
              ApiVideoCameraPreview(controller: _controller, fit: BoxFit.fitWidth),
        )
      ],
  ),
),

@ThibaultBee
Copy link
Member

I also made a fix so it is not the case anymore. Could you test #58?

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