Home > Net >  Flutter get Size of widget
Flutter get Size of widget

Time:01-07

I need same help please.

I have a widget, I need to get it size (width), and pass that size to bloc to use in other widget.

if there are a method to that!

anyone can help me. Thanks

CodePudding user response:

try to use GlobalKey to get the size of widget:

GlobalKey _keyWidget = GlobalKey();

Container(
  key: _keyWidget,
  width: 30.0,
  height: 30.0,
),

Size _getSizes() {
    final RenderBox renderBox = _keyWidget.currentContext.findRenderObject();
    return renderBox.size;
 }

CodePudding user response:

You can use the measured_size package to get the size of the widget in the runtime

Example code:

MeasuredSize(
          onChange: (Size size) {
            setState(() {
              print(size);
            });
          },
          child: Text(
            '$_counter',
            style: Theme.of(context).textTheme.headline4,
          ),
        );
  •  Tags:  
  • Related