build method
Implementation
@override
Widget build(BuildContext context)
{
// Check if widget is visible before wasting resources on building it
if (!widget.model.visible) return Offstage();
// Size
if ((width == null) || (height == null))
{
return UnconstrainedBox(child: MeasuredView(Material(child: BoxView(widget.model)), onMeasured));
}
ColorScheme t = Theme.of(context).colorScheme;
// set the models default border color
widget.model.defaultBorderColor = t.surfaceVariant;
// Overlay Manager
ModalManagerView? manager = context.findAncestorWidgetOfExactType<ModalManagerView>();
// SafeArea
double sa = MediaQuery.of(context).padding.top;
// Exceeds Width of Viewport
atMaxWidth = false;
maxWidth = MediaQuery.of(context).size.width;
if (width! >= (maxWidth - (padding * 4)))
{
atMaxWidth = true;
width = (maxWidth - (padding * 4));
}
if (width! <= 0) width = minimumSize;
// Exceeds Height of Viewport
atMaxHeight = false;
maxHeight = MediaQuery.of(context).size.height - sa;
if (height! >= (maxHeight - (padding * 4)))
{
atMaxHeight = true;
height = (maxHeight - (padding * 4));
}
if (height! <= 0) height = minimumSize;
// Content Box
body ??= Material(child: BoxView(widget.model));
// Non-Minimized View
if (!minimized)
{
Widget resize = Icon(Icons.apps, size: 24, color: Colors.transparent);
Widget resizeableBR = (widget.model.resizeable == false) ? Container() : GestureDetector(child: MouseRegion(cursor: SystemMouseCursors.resizeUpLeftDownRight, child: resize), onPanUpdate: onResizeBR, onTapDown: onBringToFront);
Widget resizeableBL = (widget.model.resizeable == false) ? Container() : GestureDetector(child: MouseRegion(cursor: SystemMouseCursors.resizeUpRightDownLeft, child: resize), onPanUpdate: onResizeBL, onTapDown: onBringToFront);
Widget resizeableTL = (widget.model.resizeable == false) ? Container() : GestureDetector(child: MouseRegion(cursor: SystemMouseCursors.resizeUpLeftDownRight, child: resize), onPanUpdate: onResizeTL, onTapDown: onBringToFront);
Widget resizeableTR = (widget.model.resizeable == false) ? Container() : GestureDetector(child: MouseRegion(cursor: SystemMouseCursors.resizeUpRightDownLeft, child: resize), onPanUpdate: onResizeTR, onTapDown: onBringToFront);
Widget resize2 = Container(width: isMobile ? 34 : 24, height: height);
Widget resizeableL = (widget.model.resizeable == false) ? Container() : GestureDetector(child: MouseRegion(cursor: SystemMouseCursors.resizeLeftRight, child: resize2), onPanUpdate: onResizeL, onTapDown: onBringToFront);
Widget resizeableR = (widget.model.resizeable == false) ? Container() : GestureDetector(child: MouseRegion(cursor: SystemMouseCursors.resizeLeftRight, child: resize2), onPanUpdate: onResizeR, onTapDown: onBringToFront);
Widget resize3 = Container(width: width, height: isMobile ? 34 : 24);
Widget resizeableT = (widget.model.resizeable == false) ? Container() : GestureDetector(child: MouseRegion(cursor: SystemMouseCursors.resizeUpDown, child: resize3), onPanUpdate: onResizeT, onTapDown: onBringToFront);
Widget resizeableB = (widget.model.resizeable == false) ? Container() : GestureDetector(child: MouseRegion(cursor: SystemMouseCursors.resizeUpDown, child: resize3), onPanUpdate: onResizeB, onTapDown: onBringToFront);
// Positioned
dx ??= (maxWidth / 2) - ((width! + (padding * 2)) / 2);
dy ??= (maxHeight / 2) - ((height! + (padding * 2)) / 2) + sa;
// Original Size/Position
originalDx ??= dx;
originalDy ??= dy;
originalWidth ??= width;
originalHeight ??= height;
// Last Size/Position
lastDx ??= dx;
lastDy ??= dy;
lastWidth ??= width;
lastHeight ??= height;
Widget frame = UnconstrainedBox(child: ClipRect(child: SizedBox(height: height, width: width, child: body)));
double headerHeight = 30;
var header = _buildHeader(t);
// View
Widget content = UnconstrainedBox(child: Container(color: Colors.transparent, height: height! + (padding * 2) + headerHeight, width: width! + (padding * 2),
child: Stack(children: [
Positioned(child: header, top: padding, left: padding),
Positioned(child: frame, top: headerHeight + padding, left: padding),
Positioned(child: resizeableL, top: 0, left: 0),
Positioned(child: resizeableR, top: 0, right: 0),
Positioned(child: resizeableT, top: 0, left: 0),
Positioned(child: resizeableB, bottom: 0, left: 0),
Positioned(child: resizeableTL, top: 0, left: 0),
Positioned(child: resizeableBL, bottom: 0, left: 0),
Positioned(child: resizeableBR, bottom: 0, right: 0),
Positioned(child: resizeableTR, top: 0, right: 0),
])));
// Remove from Park
if (manager != null) manager.model.unpark(widget);
Widget curtain = GestureDetector(child: content, onDoubleTap: onRestoreTo, onTapDown: onBringToFront, onPanStart: (_) => onBringToFront(null), onPanUpdate: onDrag, onPanEnd: onDragEnd, behavior: HitTestBehavior.deferToChild);
// Return View
return Positioned(top: dy, left: dx, child: curtain);
}
// Minimized View
else
{
// Get Parking Spot
int? slot = 0;
if (manager != null) slot = manager.model.park(widget);
// Build View
Widget scaled = Card(margin: EdgeInsets.all(1), child: SizedBox(width: 100, height: 50, child: Padding(child: FittedBox(child: body), padding:EdgeInsets.all(5))), elevation: 5, color: t.secondary.withOpacity(0.5), borderOnForeground: false, shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0)), side: BorderSide(width: 2, color: t.primary)));
Widget curtain = GestureDetector(onTap: onRestore, child: MouseRegion(cursor: SystemMouseCursors.click, child: SizedBox(width: 100, height: 50)));
Widget view = Stack(children: [scaled, curtain]);
// Return View
return Positioned(bottom: 10, left: 10 + (slot! * 110).toDouble(), child: view);
}
}