measure_size 1.0.0+1 copy "measure_size: ^1.0.0+1" to clipboard
measure_size: ^1.0.0+1 copied to clipboard

outdated

A widget that provides a callback

measure_size #

A stateful widget that measures the size of a child widget immediately after it is rendered.

CAUTION: Does not work with PreferredSizeWidget

Measuring text and drawing an overlay with matching size
import 'package:measure_size/measure_size.dart';

MeasureSize(
    onChange: (Size newSize) {
        /// [newSize] will be the displayed size of [Widget child]
    },
    child: Text('Lorem ipsum dolor sit amet'),
);

MeasureSize #

Required

  • Widget child - This widget will be displayed and and measured.

Optional

  • void onChange(Size newSize) - A callback that is fired exactly once after the first frame of the child widget is rendered.

Example #

A quick demonstration can be found in the example directory. To run the example:

flutter run example/main.dart

Credits #

Thanks to Gene Bo and Dev Aggarwal for this code in a stackoverflow answer: https://stackoverflow.com/a/60868972