27

[on web] tried to fit some widgets inside a FittedBox like this :

 FittedBox(
   fit: BoxFit.scaleDown,
   child: AnimatedContainer(...)
 )

but screen and console show only this message :

error

there's nothing else in the console

what's the next step here ? :D

Leo Ma
  • 1,021
  • 3
  • 14
  • 16

8 Answers8

23

I was getting this error inside of a CustomScrollView because one of my widgets wasn't inside of a SliverToBoxAdapter.

SliverToBoxAdapter(
  child: Row(
    children: [
      Text('Activity',
      style: TextStyle(fontWeight: FontWeight.w600, fontSize: 18),),
    ],
  ),
)

I'd just make sure all widgets in your sliver list are actually slivers.

Code on the Rocks
  • 11,488
  • 3
  • 53
  • 61
5

More Info was provided by the framework after a little messing around with the code , like extra children , random sizes to parents . . .

Error >> ... object was given an infinite size during layout

ultimately some like this worked :

FittedBox(
 fit: BoxFit.scaleDown,
 child: Container(
   height: MediaQuery.of(context).size.height * .65,
   child: AnimatedContainer(...)
)
Leo Ma
  • 1,021
  • 3
  • 14
  • 16
0

I was getting this error because somewhere in my code, I applied a wrong widget mistakenly, and that was the same stateless widget that I was writing. To make it more clear:

stateless widget - MyWidget //For example
.
.
.
Now somewhere in between the code:

Column(
children: [
MyWidget(), //This went wrong, I was supposed to Use some other widget.
]);
DevSec Guy
  • 21
  • 2
0

I encountered this error as a result of incorporating multiple Consumer widgets of the same model Provider. Solution was to follow Provider package guidelines of incorporating one Consumer widget at the top of the widget tree where the state object is to be shared from.

Mwanagenzi
  • 136
  • 1
  • 6
0

Just answering this because none of the Answers above worked for me:

My IDE (VSCode) changed the initState() method to async because I accidentally wrote a method as "await" and then just tapped the autoerrorfix

Waldi
  • 39,242
  • 6
  • 30
  • 78
Acidic
  • 67
  • 1
  • 7
0

I just wrap with container (with height=constant) it worked for me

0

if the error appears when you have clicked button at the bottom sheet, just set enabledrag to false.

      builder: (context) => BottomSheet(
                  onClosing: () {},
                  enableDrag: false,
0

I got this error because of my bloc provider

      @override
      Widget build(BuildContext context) {
      return BlocProvider(

your build method should return BlocProvider first !

AmirahmadAdibi
  • 358
  • 3
  • 9