Avoid dividing by 0 and setting scale to 0
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
04fd17f526
commit
cb4b658e48
@ -617,13 +617,28 @@ class ViewStyle {
|
|||||||
final int displayWidth;
|
final int displayWidth;
|
||||||
final int displayHeight;
|
final int displayHeight;
|
||||||
ViewStyle({
|
ViewStyle({
|
||||||
this.style = '',
|
required this.style,
|
||||||
this.width = 0.0,
|
required this.width,
|
||||||
this.height = 0.0,
|
required this.height,
|
||||||
this.displayWidth = 0,
|
required this.displayWidth,
|
||||||
this.displayHeight = 0,
|
required this.displayHeight,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
static defaultViewStyle() {
|
||||||
|
final desktop = (isDesktop || isWebDesktop);
|
||||||
|
final w =
|
||||||
|
desktop ? kDesktopDefaultDisplayWidth : kMobileDefaultDisplayWidth;
|
||||||
|
final h =
|
||||||
|
desktop ? kDesktopDefaultDisplayHeight : kMobileDefaultDisplayHeight;
|
||||||
|
return ViewStyle(
|
||||||
|
style: '',
|
||||||
|
width: w.toDouble(),
|
||||||
|
height: h.toDouble(),
|
||||||
|
displayWidth: w,
|
||||||
|
displayHeight: h,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static int _double2Int(double v) => (v * 100).round().toInt();
|
static int _double2Int(double v) => (v * 100).round().toInt();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -652,9 +667,14 @@ class ViewStyle {
|
|||||||
double get scale {
|
double get scale {
|
||||||
double s = 1.0;
|
double s = 1.0;
|
||||||
if (style == kRemoteViewStyleAdaptive) {
|
if (style == kRemoteViewStyleAdaptive) {
|
||||||
final s1 = width / displayWidth;
|
if (width != 0 &&
|
||||||
final s2 = height / displayHeight;
|
height != 0 &&
|
||||||
s = s1 < s2 ? s1 : s2;
|
displayWidth != 0 &&
|
||||||
|
displayHeight != 0) {
|
||||||
|
final s1 = width / displayWidth;
|
||||||
|
final s2 = height / displayHeight;
|
||||||
|
s = s1 < s2 ? s1 : s2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -680,7 +700,7 @@ class CanvasModel with ChangeNotifier {
|
|||||||
// scroll offset y percent
|
// scroll offset y percent
|
||||||
double _scrollY = 0.0;
|
double _scrollY = 0.0;
|
||||||
ScrollStyle _scrollStyle = ScrollStyle.scrollauto;
|
ScrollStyle _scrollStyle = ScrollStyle.scrollauto;
|
||||||
ViewStyle _lastViewStyle = ViewStyle();
|
ViewStyle _lastViewStyle = ViewStyle.defaultViewStyle();
|
||||||
|
|
||||||
final _imageOverflow = false.obs;
|
final _imageOverflow = false.obs;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user