v5.0.2measure_size
크기 변경 시 콜백을 트리거하는 위젯
40좋아요 1.5만30일 다운로드160Pub 점수
AndroidiOSWebmacOSWindowsLinux
렌더링 직후 자식 위젯의 크기를 측정하는 상태가 있는 위젯입니다.
아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
A Flutter package for efficiently measuring widget sizes and building size-aware, adaptive layouts with minimal overhead.
MeasureSize |
MeasureSizeBuilder |
|
|---|---|---|
| Purpose | Monitor size changes | Prototype-driven layout |
| Callback timing | Post-frame | During layout (invokeLayoutCallback) |
| Measurements | Single widget | Multiple prototypes |
| Use case | Reactive to size changes | Proactive layout decisions |
| Complexity | Simple | Advanced |
| Performance | Good | Excellent (single pass) |
| PreferredSizeWidget limitation | Does not work | First frame problematic |
import 'package:measure_size/measure_size.dart';
Widget child = Text('Lorem ipsum dolor sit amet');
MeasureSize(
onChange: (Size newSize) {
/// [newSize] will be the displayed size of [Widget child]
},
child: child,
);
MeasureSizeBuilder<String>(
prototypeConstraints: (constraints) => BoxConstraints(
minWidth: 0,
maxWidth: constraints.maxWidth,
minHeight: 0,
maxHeight: double.infinity,
),
prototypes: [
PrototypeId(
id: 'lorem',
child: child,
),
],
builder: (context, sizes) {
// [sizes['lorem']] will be the layed out size of [Widget child]
return child;
}
);
MeasureSizeWidget child - This widget will be displayed and and measured.void onChange(Size newSize) - A callback that is fired exactly once after the first frame of the child widget is rendered.MeasureSizeBuilder<T>List<PrototypeId<T>> prototypes - Wrap widgets you'd like to measure with PrototypeId and provide a unique identifier for each widget.PrototypeWidgetBuilder<T> builder - A builder function that contains the sizes of all prototypes.PrototypeConstraintCalculator prototypeConstraints - Constraints to be assigned to each prototype widget.A demonstration can be found in the example directory. To run the example:
flutter run example/main.dart
의존성 목록 3 개
{"sdk":"flutter"}^6.0.0{"sdk":"flutter"}사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗