📘 README.md

zeba_academy_measure

A lightweight and powerful Flutter utility package to measure widget size, position, and listen to layout changes using GlobalKey helpers and widgets.


🚀 Features

  • 📏 Measure widget size easily
  • 📍 Get widget global position
  • 🔑 GlobalKey extension helpers
  • 🔄 Detect size changes in real time
  • 🧩 Simple wrapper widget for measurement
  • ⚡ Lightweight and production-ready

📦 Installation

Add this to your pubspec.yaml:

dependencies:
  zeba_academy_measure: ^0.0.1

Then run:

flutter pub get
🧠 Usage
1. Using GlobalKey measurement
final key = GlobalKey();

Container(
  key: key,
  width: 100,
  height: 80,
  color: Colors.red,
);

// Access metrics
final size = key.size;
final position = key.position;
final metrics = key.metrics;

print(size);
print(position);
2. MeasureController
final controller = MeasureController(
  key: key,
  onMeasure: (metrics) {
    print(metrics.size);
    print(metrics.position);
  },
);

controller.measure();
3. MeasureWidget (auto tracking)
MeasureWidget(
  onChange: (metrics) {
    print(metrics.size);
    print(metrics.position);
  },
  child: Container(
    width: 120,
    height: 120,
    color: Colors.blue,
  ),
);
4. Size Change Listener
SizeChangeListener(
  onChange: (size) {
    print("Size changed: $size");
  },
  child: YourWidget(),
);
📊 API Overview
WidgetMetrics
class WidgetMetrics {
  final Size size;
  final Offset position;
}
GlobalKey Extensions
key.size → Returns widget size
key.position → Returns global position
key.metrics → Returns both size and position
🏗️ Architecture
Extension-based API for simplicity
RenderBox-based measurement system
LayoutBuilder-based size tracking
Post-frame callback safe execution
⚠️ Notes
Measurements are available after first frame render
Use inside WidgetsBinding.instance.addPostFrameCallback
Works best with constrained widgets (SizedBox / Container with constraints)
📄 License

This project is licensed under the GNU General Public License (GPL-3.0).

You are free to:

Use
Modify
Distribute

But any distributed version must also remain open-source under GPL-3.0.

👨‍💻 About Developer

✨ Sufyan bin Uzayr
Open-source developer passionate about building meaningful tools for developers.

🌐 Website: https://sufyanism.com
💼 LinkedIn: https://www.linkedin.com/in/sufyanism
📚 Zeba Academy: https://zeba.academy
📺 YouTube: https://www.youtube.com/@zeba.academy
📷 Instagram: https://www.instagram.com/zeba.academy

💡 Powered by Zeba Academy

🚀 Explore coding, development, and hands-on learning at:
https://code.zeba.academy

⭐ Support

If you find this package useful, consider starring the repository and sharing it with others.