aves/lib/model/panorama.dart
Thibault Deckers ca221635e9 minor fixes
2021-07-19 10:37:01 +09:00

51 lines
1.7 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
class PanoramaInfo {
final Rect? croppedAreaRect;
final Size? fullPanoSize;
final String? projectionType;
PanoramaInfo({
this.croppedAreaRect,
this.fullPanoSize,
this.projectionType,
});
factory PanoramaInfo.fromMap(Map map) {
var cLeft = map['croppedAreaLeft'] as int?;
var cTop = map['croppedAreaTop'] as int?;
final cWidth = map['croppedAreaWidth'] as int?;
final cHeight = map['croppedAreaHeight'] as int?;
var fWidth = map['fullPanoWidth'] as int?;
var fHeight = map['fullPanoHeight'] as int?;
final projectionType = map['projectionType'] as String?;
// handle missing `fullPanoHeight` (e.g. Samsung camera app panorama mode)
if (fHeight == null && fWidth != null && cHeight != null) {
fHeight = (fWidth / 2).round();
cTop = ((fHeight - cHeight) / 2).round();
}
Rect? croppedAreaRect;
if (cLeft != null && cTop != null && cWidth != null && cHeight != null) {
croppedAreaRect = Rect.fromLTWH(cLeft.toDouble(), cTop.toDouble(), cWidth.toDouble(), cHeight.toDouble());
}
Size? fullPanoSize;
if (fWidth != null && fHeight != null) {
fullPanoSize = Size(fWidth.toDouble(), fHeight.toDouble());
}
return PanoramaInfo(
croppedAreaRect: croppedAreaRect,
fullPanoSize: fullPanoSize,
projectionType: projectionType,
);
}
bool get hasCroppedArea => croppedAreaRect != null && fullPanoSize != null;
@override
String toString() => '$runtimeType#${shortHash(this)}{croppedAreaRect=$croppedAreaRect, fullPanoSize=$fullPanoSize, projectionType=$projectionType}';
}