Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions lib/linear_percent_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ extension ExtDouble on double {
bool get isZero => this.toString() == '0.0';
}

extension ExtGlobalKey on GlobalKey {
Size getSize() {
final RenderObject? renderObject = currentContext?.findRenderObject();
if (renderObject is RenderBox && renderObject.hasSize) {
return renderObject.size;
}
return Size.zero;
}
}

// ignore: must_be_immutable
class LinearPercentIndicator extends StatefulWidget {
///Percent value between 0.0 and 1.0
Expand Down Expand Up @@ -177,13 +187,14 @@ class _LinearPercentIndicatorState extends State<LinearPercentIndicator>
void initState() {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
final Size containerSize = _containerKey.getSize();
final Size indicatorSize = _keyIndicator.getSize();
setState(() {
_containerWidth = _containerKey.currentContext?.size?.width ?? 0.0;
_containerHeight = _containerKey.currentContext?.size?.height ?? 0.0;
_containerWidth = containerSize.width;
_containerHeight = containerSize.height;
if (_keyIndicator.currentContext != null) {
_indicatorWidth = _keyIndicator.currentContext?.size?.width ?? 0.0;
_indicatorHeight =
_keyIndicator.currentContext?.size?.height ?? 0.0;
_indicatorWidth = indicatorSize.width;
_indicatorHeight = indicatorSize.height;
}
});
}
Expand Down