openPopupGallery static method
Opens a new popup window at the Routes.gallery page with the provided
chatId
.
Implementation
static bool openPopupGallery(ChatId chatId, {String? id, int? index}) {
final int screenW = web.window.screen.width;
final int screenH = web.window.screen.height;
final Rect? prefs = getGalleryRect();
final width = min(prefs?.width ?? 500, screenW);
final height = min(prefs?.height ?? 500, screenH);
var left = prefs?.left ?? screenW - 50 - width;
if (left < 0) {
left = 0;
} else if (left + width > screenW) {
left = screenW - width;
}
var top = prefs?.top ?? 50;
if (top < 0) {
top = 0;
} else if (top + height > screenH) {
top = screenH.toDouble() - height;
}
final List<String> parameters = [
if (id != null) 'id=$id',
if (index != null) 'index=$index',
];
final String query = parameters.isEmpty ? '' : '?${parameters.join('&')}';
final web.Window? window = web.window.open(
'${Routes.gallery}/$chatId$query',
'gallery_${const Uuid().v4()}',
'popup=1,width=$width,height=$height,left=$left,top=$top',
);
try {
return window?.closed == false;
} catch (_) {
return false;
}
}