Skip to content

Commit

Permalink
set localStorage
Browse files Browse the repository at this point in the history
Signed-off-by: phuoc <[email protected]>
  • Loading branch information
phuocbitmark committed Oct 25, 2023
1 parent 5de5792 commit fe61e48
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/screen/interactive_postcard/postcard_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,10 @@ class ClaimedPostcardDetailPageState extends State<ClaimedPostcardDetailPage>
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),
Expand Down
13 changes: 12 additions & 1 deletion lib/screen/irl_screen/webview_irl_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ class _IRLWebScreenState extends State<IRLWebScreen> {
);
}

void _addLocalStorageItems(Map<String, dynamic> items) {
items.forEach((key, value) {
_controller?.webStorage.localStorage.setItem(key: key, value: value);
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -414,6 +420,9 @@ class _IRLWebScreenState extends State<IRLWebScreen> {
onWebViewCreated: (controller) {
_controller = controller;
_addJavaScriptHandler();
if (widget.payload.localStorageItems != null) {
_addLocalStorageItems(widget.payload.localStorageItems!);
}
}),
),
)
Expand Down Expand Up @@ -476,6 +485,8 @@ class JSResult {
class IRLWebScreenPayload {
final String url;
final bool isPlainUI;
final Map<String, dynamic>? localStorageItems;

IRLWebScreenPayload(this.url, {this.isPlainUI = false});
IRLWebScreenPayload(this.url,
{this.isPlainUI = false, this.localStorageItems});
}

0 comments on commit fe61e48

Please sign in to comment.