From fe61e48d73c9d741306c871dcae634116ab5ff46 Mon Sep 17 00:00:00 2001 From: phuoc Date: Wed, 25 Oct 2023 17:00:02 +0700 Subject: [PATCH] set localStorage Signed-off-by: phuoc --- .../interactive_postcard/postcard_detail_page.dart | 5 +++-- lib/screen/irl_screen/webview_irl_screen.dart | 13 ++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/screen/interactive_postcard/postcard_detail_page.dart b/lib/screen/interactive_postcard/postcard_detail_page.dart index 7426c2d74a..17975305fb 100644 --- a/lib/screen/interactive_postcard/postcard_detail_page.dart +++ b/lib/screen/interactive_postcard/postcard_detail_page.dart @@ -695,9 +695,10 @@ class ClaimedPostcardDetailPageState extends State log.info("?indexId=$indexId&hasCS=$hasCustomerSupport"); if (!context.mounted) return; final url = - "${Environment.merchandiseBaseUrl}?indexId=$indexId&hasCS=$hasCustomerSupport&token=$jwtToken"; + "${Environment.merchandiseBaseUrl}?indexId=$indexId&hasCS=$hasCustomerSupport"; Navigator.of(context).pushNamed(AppRouter.irlWebView, - arguments: IRLWebScreenPayload(url, isPlainUI: true)); + arguments: IRLWebScreenPayload(url, + isPlainUI: true, localStorageItems: {'token': jwtToken})); }, ), const SizedBox(height: 15), diff --git a/lib/screen/irl_screen/webview_irl_screen.dart b/lib/screen/irl_screen/webview_irl_screen.dart index 27132ffc33..a31fd7c7ed 100644 --- a/lib/screen/irl_screen/webview_irl_screen.dart +++ b/lib/screen/irl_screen/webview_irl_screen.dart @@ -389,6 +389,12 @@ class _IRLWebScreenState extends State { ); } + void _addLocalStorageItems(Map items) { + items.forEach((key, value) { + _controller?.webStorage.localStorage.setItem(key: key, value: value); + }); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -414,6 +420,9 @@ class _IRLWebScreenState extends State { onWebViewCreated: (controller) { _controller = controller; _addJavaScriptHandler(); + if (widget.payload.localStorageItems != null) { + _addLocalStorageItems(widget.payload.localStorageItems!); + } }), ), ) @@ -476,6 +485,8 @@ class JSResult { class IRLWebScreenPayload { final String url; final bool isPlainUI; + final Map? localStorageItems; - IRLWebScreenPayload(this.url, {this.isPlainUI = false}); + IRLWebScreenPayload(this.url, + {this.isPlainUI = false, this.localStorageItems}); }