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
|
* Copyright (c) 2021 Simform Solutions
|
||||||
* All rights reserved.
|
*
|
||||||
* https://github.com/simformsolutions/flutter_showcaseview
|
* 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';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class GetPosition {
|
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() {
|
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)));
|
var boxOffset = box.localToGlobal(const Offset(0.0, 0.0));
|
||||||
final bottomRight =
|
if (boxOffset.dx.isNaN || boxOffset.dy.isNaN) {
|
||||||
box.size.bottomRight(box.localToGlobal(const Offset(0.0, 0.0)));
|
return const Rect.fromLTRB(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
final topLeft = box.size.topLeft(boxOffset);
|
||||||
|
final bottomRight = box.size.bottomRight(boxOffset);
|
||||||
|
|
||||||
Rect rect = Rect.fromLTRB(
|
final rect = Rect.fromLTRB(
|
||||||
topLeft.dx,
|
topLeft.dx - padding.left < 0 ? 0 : topLeft.dx - padding.left,
|
||||||
topLeft.dy,
|
topLeft.dy - padding.top < 0 ? 0 : topLeft.dy - padding.top,
|
||||||
bottomRight.dx,
|
bottomRight.dx + padding.right > screenWidth!
|
||||||
bottomRight.dy,
|
? screenWidth!
|
||||||
|
: bottomRight.dx + padding.right,
|
||||||
|
bottomRight.dy + padding.bottom > screenHeight!
|
||||||
|
? screenHeight!
|
||||||
|
: bottomRight.dy + padding.bottom,
|
||||||
);
|
);
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
///Get the bottom position of the widget
|
///Get the bottom position of the widget
|
||||||
double getBottom() {
|
double getBottom() {
|
||||||
RenderBox box = key.currentContext.findRenderObject();
|
final box = key!.currentContext!.findRenderObject() as RenderBox;
|
||||||
final bottomRight =
|
final boxOffset = box.localToGlobal(const Offset(0.0, 0.0));
|
||||||
box.size.bottomRight(box.localToGlobal(const Offset(0.0, 0.0)));
|
if (boxOffset.dy.isNaN) return padding.bottom;
|
||||||
return bottomRight.dy;
|
final bottomRight = box.size.bottomRight(boxOffset);
|
||||||
|
return bottomRight.dy + padding.bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
///Get the top position of the widget
|
///Get the top position of the widget
|
||||||
double getTop() {
|
double getTop() {
|
||||||
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 boxOffset = box.localToGlobal(const Offset(0.0, 0.0));
|
||||||
return topLeft.dy;
|
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
|
///Get the left position of the widget
|
||||||
double getLeft() {
|
double getLeft() {
|
||||||
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 boxOffset = box.localToGlobal(const Offset(0.0, 0.0));
|
||||||
return topLeft.dx;
|
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
|
///Get the right position of the widget
|
||||||
double getRight() {
|
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 =
|
final bottomRight =
|
||||||
box.size.bottomRight(box.localToGlobal(const Offset(0.0, 0.0)));
|
box.size.bottomRight(box.localToGlobal(const Offset(0.0, 0.0)));
|
||||||
return bottomRight.dx;
|
return bottomRight.dx + padding.right;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getHeight() {
|
double getHeight() => getBottom() - getTop();
|
||||||
return getBottom() - getTop();
|
|
||||||
}
|
|
||||||
|
|
||||||
double getWidth() {
|
double getWidth() => getRight() - getLeft();
|
||||||
return getRight() - getLeft();
|
|
||||||
}
|
|
||||||
|
|
||||||
double getCenter() {
|
double getCenter() => (getLeft() + getRight()) / 2;
|
||||||
return (getLeft() + getRight()) / 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue