import 'package:flutter/material.dart'; import 'package:yumi/modules/webview/webview_page.dart'; import 'package:yumi/shared/tools/sc_room_utils.dart'; import 'package:yumi/shared/tools/sc_string_utils.dart'; import 'package:yumi/shared/tools/sc_h5_url_utils.dart'; import 'package:yumi/shared/tools/sc_lk_dialog_util.dart'; import 'package:yumi/shared/tools/sc_url_launcher_utils.dart'; import 'package:yumi/shared/business_logic/models/res/sc_index_banner_res.dart'; import 'package:yumi/modules/index/main_route.dart'; import 'package:yumi/app/routes/sc_fluro_navigator.dart'; import '../../shared/data_sources/models/enum/sc_banner_open_type.dart'; class SCBannerUtils { static Future openBanner( SCIndexBannerRes item, BuildContext context, { bool openH5AsRoomPopup = false, }) async { if (item.content == SCBannerOpenType.ENTER_ROOM.name) { var params = item.params; if (params != null && params.isNotEmpty) { SCRoomUtils.goRoom(params, context); } } else { var params = item.params; if (params == null || params.isEmpty) { return; } if (SCUrlLauncherUtils.shouldOpenExternally(params)) { final launched = await SCUrlLauncherUtils.launchExternal(params); if (launched) { return; } if (!context.mounted) { return; } } if (SCStringUtils.checkIfUrl(params)) { final h5Url = _appendToken(params); if (openH5AsRoomPopup) { await _showRoomH5Popup(context, h5Url); return; } SCNavigatorUtils.push( context, "${SCMainRoute.webViewPage}?url=${Uri.encodeComponent(h5Url)}&showTitle=false", replace: false, ); } } } static String _appendToken(String url) { return SCH5UrlUtils.appendToken(url); } static Future _showRoomH5Popup(BuildContext context, String h5Url) { final screenHeight = MediaQuery.sizeOf(context).height; return showBottomInBottomDialog( context, SizedBox( height: screenHeight * 0.75, width: double.infinity, child: WebViewPage(url: h5Url, showTitle: "false"), ), barrierColor: Colors.black54, barrierDismissible: true, ); } }