0

I am trying to add a Stack within a ListView in a SafeArea. However, there is a runtime exception as seen below:

BoxConstraints forces an infinite height.
I/flutter (18717): These invalid constraints were provided to RenderConstrainedBox's layout() function by the following
I/flutter (18717): function, which probably computed the invalid constraints in question:
I/flutter (18717):   RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:259:13)
I/flutter (18717): The offending constraints were:
I/flutter (18717):   BoxConstraints(w=411.4, h=Infinity)

My code:

    @override
  Widget build(BuildContext context) {
    SizeConfig().init(context);

    return new Scaffold(
        body: SafeArea(
            top: true,
            child: ListView(  shrinkWrap: true,
        children: <Widget>[_buildFrostedRow(context)])));
  }


  Stack _buildFrostedRow(BuildContext context) {
    return Stack(
    children: <Widget>[
      new ConstrainedBox(
          constraints: const BoxConstraints.expand(), child: _showCardRow()),
      new Center(
        child: new ClipRect(
          child: new BackdropFilter(
            filter: new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
            child: new Container(
              width: SizeConfig.safeBlockHorizontal * 90,
              height: SizeConfig.safeBlockVertical * 20,
              decoration: new BoxDecoration(
                  color: Colors.grey.shade200.withOpacity(0.5)),
              child: new Center(
                child: new Text('Frosted',
                    style: Theme.of(context).textTheme.display3),
              ),
            ),
          ),
        ),
      ),
    ],
  );
  }

What am I missing here?

2
  • You need to limit height to Stack (put it into Container and set height or something like that). Because if you didn't, the ListView cannot calculate layout. Commented Sep 30, 2019 at 6:36
  • ohh jeez that worked! If you can add a answer, I will accept it and close this. :) Commented Sep 30, 2019 at 6:39

2 Answers 2

3

You need to limit height to Stack (put it into Container and set height or something like that). Because if you didn't, the ListView cannot calculate layout.

return new Scaffold(
        body: SafeArea(
            top: true,
            child: ListView(  shrinkWrap: true,
        children: <Widget>[Container(height:200, // can change
                           child: _buildFrostedRow(context))])));
Sign up to request clarification or add additional context in comments.

Comments

0

Just wrap your Stack with Constrained box or Fixed Heigh Container. Because, Listview and Stack has infinite height

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.