Null Safety Updates 3.16
parent
ea7744254b
commit
1bc355b2c4
File diff suppressed because it is too large
Load Diff
@ -1,75 +1,103 @@
|
||||
/*
|
||||
* Copyright © 2020, Simform Solutions
|
||||
* All rights reserved.
|
||||
* https://github.com/simformsolutions/flutter_showcaseview
|
||||
* Copyright (c) 2021 Simform Solutions
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
Customized By: Ibrahim Albitar
|
||||
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class GetPosition {
|
||||
final GlobalKey key;
|
||||
final GlobalKey? key;
|
||||
final EdgeInsets padding;
|
||||
final double? screenWidth;
|
||||
final double? screenHeight;
|
||||
|
||||
GetPosition({this.key});
|
||||
GetPosition({
|
||||
this.key,
|
||||
this.padding = EdgeInsets.zero,
|
||||
this.screenWidth,
|
||||
this.screenHeight,
|
||||
});
|
||||
|
||||
Rect getRect() {
|
||||
RenderBox box = key.currentContext.findRenderObject();
|
||||
final box = key!.currentContext!.findRenderObject() as RenderBox;
|
||||
|
||||
final topLeft = box.size.topLeft(box.localToGlobal(const Offset(0.0, 0.0)));
|
||||
final bottomRight =
|
||||
box.size.bottomRight(box.localToGlobal(const Offset(0.0, 0.0)));
|
||||
var boxOffset = box.localToGlobal(const Offset(0.0, 0.0));
|
||||
if (boxOffset.dx.isNaN || boxOffset.dy.isNaN) {
|
||||
return const Rect.fromLTRB(0, 0, 0, 0);
|
||||
}
|
||||
final topLeft = box.size.topLeft(boxOffset);
|
||||
final bottomRight = box.size.bottomRight(boxOffset);
|
||||
|
||||
Rect rect = Rect.fromLTRB(
|
||||
topLeft.dx,
|
||||
topLeft.dy,
|
||||
bottomRight.dx,
|
||||
bottomRight.dy,
|
||||
final rect = Rect.fromLTRB(
|
||||
topLeft.dx - padding.left < 0 ? 0 : topLeft.dx - padding.left,
|
||||
topLeft.dy - padding.top < 0 ? 0 : topLeft.dy - padding.top,
|
||||
bottomRight.dx + padding.right > screenWidth!
|
||||
? screenWidth!
|
||||
: bottomRight.dx + padding.right,
|
||||
bottomRight.dy + padding.bottom > screenHeight!
|
||||
? screenHeight!
|
||||
: bottomRight.dy + padding.bottom,
|
||||
);
|
||||
return rect;
|
||||
}
|
||||
|
||||
///Get the bottom position of the widget
|
||||
double getBottom() {
|
||||
RenderBox box = key.currentContext.findRenderObject();
|
||||
final bottomRight =
|
||||
box.size.bottomRight(box.localToGlobal(const Offset(0.0, 0.0)));
|
||||
return bottomRight.dy;
|
||||
final box = key!.currentContext!.findRenderObject() as RenderBox;
|
||||
final boxOffset = box.localToGlobal(const Offset(0.0, 0.0));
|
||||
if (boxOffset.dy.isNaN) return padding.bottom;
|
||||
final bottomRight = box.size.bottomRight(boxOffset);
|
||||
return bottomRight.dy + padding.bottom;
|
||||
}
|
||||
|
||||
///Get the top position of the widget
|
||||
double getTop() {
|
||||
RenderBox box = key.currentContext.findRenderObject();
|
||||
final topLeft = box.size.topLeft(box.localToGlobal(const Offset(0.0, 0.0)));
|
||||
return topLeft.dy;
|
||||
final box = key!.currentContext!.findRenderObject() as RenderBox;
|
||||
final boxOffset = box.localToGlobal(const Offset(0.0, 0.0));
|
||||
if (boxOffset.dy.isNaN) return 0 - padding.top;
|
||||
final topLeft = box.size.topLeft(boxOffset);
|
||||
return topLeft.dy - padding.top;
|
||||
}
|
||||
|
||||
///Get the left position of the widget
|
||||
double getLeft() {
|
||||
RenderBox box = key.currentContext.findRenderObject();
|
||||
final topLeft = box.size.topLeft(box.localToGlobal(const Offset(0.0, 0.0)));
|
||||
return topLeft.dx;
|
||||
final box = key!.currentContext!.findRenderObject() as RenderBox;
|
||||
final boxOffset = box.localToGlobal(const Offset(0.0, 0.0));
|
||||
if (boxOffset.dx.isNaN) return 0 - padding.left;
|
||||
final topLeft = box.size.topLeft(boxOffset);
|
||||
return topLeft.dx - padding.left;
|
||||
}
|
||||
|
||||
///Get the right position of the widget
|
||||
double getRight() {
|
||||
RenderBox box = key.currentContext.findRenderObject();
|
||||
final box = key!.currentContext!.findRenderObject() as RenderBox;
|
||||
final boxOffset = box.localToGlobal(const Offset(0.0, 0.0));
|
||||
if (boxOffset.dx.isNaN) return padding.right;
|
||||
final bottomRight =
|
||||
box.size.bottomRight(box.localToGlobal(const Offset(0.0, 0.0)));
|
||||
return bottomRight.dx;
|
||||
return bottomRight.dx + padding.right;
|
||||
}
|
||||
|
||||
double getHeight() {
|
||||
return getBottom() - getTop();
|
||||
}
|
||||
double getHeight() => getBottom() - getTop();
|
||||
|
||||
double getWidth() {
|
||||
return getRight() - getLeft();
|
||||
}
|
||||
double getWidth() => getRight() - getLeft();
|
||||
|
||||
double getCenter() {
|
||||
return (getLeft() + getRight()) / 2;
|
||||
}
|
||||
double getCenter() => (getLeft() + getRight()) / 2;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue