I am developing a project on ecommerce where i have need of sending the data from html to flutter web page using javascript. I tried ways of sending data using EncodedURIComponent to creating a web socket to send data to the flutter site. But, none of that work . Can somebody tell me how to send data from a html site to flutter web page using javascript?
params.id is the value that want to send.
//sample js and dart code
//js
function sendData() {
const id = `${params.id}`; // Example ID
// Construct the URL with query parameters
const flutterUrl = `http://localhost:50759/#/productbrand?id=${encodeURIComponent(id)}}`;
// Redirect to the Flutter web app with the query parameters
window.location.href = flutterUrl;
}
document
.getElementById("send-product-id")
.addEventListener("click", sendData);
//dart
this one is the route code where i have already given required parameter in the ui file.
case productbrand:
final id = uri.queryParameters['id'];
return MaterialPageRoute(
builder: (_) => Productbrandpage(id: id ?? 'Unknown ID'),
);
I have a route name code which put up a name for each page displayed in the search bar.
Productbrandpage.route: (context) => Productbrandpage(
id: '',
),
Thank you.