how to pass http api data to anther page? - flutter

I was building a demo application for a store (not a specific one) and I got the data from an online JSON file through http requests, is it possible to pass the data to another file?
I tried to pass the data using an object from the where I extracted the data and using sharedPreferences too expecting to pass the data to the other screen and display it, but the actual output was nothing.

you can share data from one page to another page using arguments property of push method
Navigator.of(context).pushNamed("routeName",arguments: data);
to extract this data in the second page use this
ModalRoute.of(context)!.settings.arguments;

Related

How to navigate with URL to a page with query parameter in router.js

I want to be able to find a way to navigate to a page with parameter in the url for example,
Suppose if I put following like on the browser localhost:8000/?root=profiledetails&id=QQWWES Then I should be able to navigate to page configured with profiledetails in the router and also I should be able to retrieve the query parameter id QQWWES which I need to retrieve data from server.
Can anyone please help me figure this out. Appreciate your help.
You can use the router store and retrieve methods for this.
In your source page store data using store method.
router.store( routerData ); //Router is an instance of router and routerData is
//an object with required data
Then in your target page get the data using retrieve method.
var routerData = router.retrieve();

How to construct client context in AEM by passing values from an external system?

Is there a way to construct the client context in AEM by using values passed by an external website? The external website sends the user information such as IP address, page data, geolocation, etc. I want to construct the ClientContext JSON without using CQ_Analytics.ClientContextMgr.init, as the information is from an external system.
For eg: We know the location of a visitor to our website. We want to pass this value to AEM and set the client context so that we can get the targeted content for this location.
Our end goal is to get something like this (but we are trying to achieve this without constructing the JSON by ourselves):
CQ_Analytics.ClientContextMgr.clientcontext = JSON.parse('{"profile":{"country":"US"}}');
Is there any Javascript APIs provided by AEM to construct the JSON?
You need to extend the client context using AEM documentation provided at:
Creating a Custom Context Store Component
Follow the instructions till the Initialization part where you will need to populate the data in the jsp file for your extension.
So in your case it would be something this:
if(!locstore){
locstore = CQ_Analytics.JSONPStore.registerNewInstance("<%= store %>",
"<%= jsonpurl %>",{});
}
Where jsonpurl will be the location of your service that provides the external data in json(p) format. This will initialise your store with the values you want and you won't need to worry about the manual json handcrafting.
Client context is constructed on client side using the JS library in AEM. You will need some binding parameters to connect your external data source to the current client context.
The detailed tutorial can be found here.

Insert an image into a BIRT report with a secured URL

I wanted to load an image in my report with an URL.
The following stackoverflow question answers that.
How to insert an image into a BIRT report with an URL properly?
However, my URL is not public and requires authentication to access. Like, adding an Authorization token in the header.
How can I intercept the request to insert Authorization token?
You could add a new "Scripted Data Source" and write your request in JavaScript with the required authorization token to load the Image data into your Data Source.
Then you add a data Set to get the data from the scripted data source. Afterwards you add the Image as "Dynamic image" and load the data from the Data Set that gets the data from your scripted data source. This is a bit complicated, but it should be possible.
Please search for tutorials for creating a scripted data source by yourself. This is a complex field but opens up a lot of possibilities.

ASP.NET MVC passing data between forms

Im pretty new to ASP.NET MVC, trying to figure out my way around.
Currently i return a ViewModel which has a IEnumeable Events as its only property. This ViewModel is StronglyTyped to a UserControl which dislays the IEnumable Events in tabular form.
One of the properties of the Event Model is an XElement, which contains some XML loaded from the DB.
Now i've added a link to the end of the tablular data to be able to view the XML in a separate page. How do i pass this data to another page for viewing?
I would post a request back to the server with some sort of Id for the Event-object and have the receiving end send back the XML related to that Id.
if you're looping through the Event objects in your IEnumerable, you can do something like:
<%= Html.ActionLink("GetXml", "Events", new { id = currentEvent.Id }) %>;
Now create an Action on your EventsController (given that you have one) like so:
public ActionResult GetXml(int id)
and retrieve the XML to pass back to the View
There are basically two ways of bringing data from one page to another using ASP.NET MVC (or any other language/framework which follows the HTTP protocol):
Sessions: Use a session to store the data you need, and load it back up at the next page.
Post the needed data back to the server. This way, the server can hold it and display it on the next page. Posted data usually comes from input or textarea elements. If you use input type="hidden" you can give it a value which represents your data. This way, you can post it back and forth till you arrive where you want.
Besides what Arve is advising, you could also consider TempData.
If you use the Get-Post-Redirect/Forward concept for you app, you could do something like:
GET - Initial Request comes in, Server responds with View and model data. User selects an item which leads to ...
POST - User selects one of the items from #1, triggering a post. That particular item can be fetched from repository, placed in TempData and then...
REDIRECT/FORWARD - The redirect collects the information out of TenpData and uses it as the model for the new View.
here is an example http://www.eworldui.net/blog/post/2008/05/08/ASPNET-MVC-Using-Post2c-Redirect2c-Get-Pattern.aspx

MVC 2.0 Post Form to action instead of redirect to action

I am using T4MVC to redirect to another action return RedirectToAction(MVC.MyController.MyAction());.
In result it is doing get request.
Is there any way to make post request from controller. I want to keep all the same but only make post instead get. I cant find any methods for that. I found one post helper here http://geekswithblogs.net/rakker/archive/2006/04/21/76044.aspx but i cant pass any values i need using this post helper. I was trying to pass values through TempData but they are not coming when i using this helper. May be some one have any ideas?
The reason i want to do this because when user come from one controller to another and then if user click update or just click enter in browser address bar, page will break.
Should i use session for that reason?
A RedirectToAction will always perform a GET, never a POST (it returns a HTTP 302 to the browser, which will then issue a GET request).
To persist data across the redirect, if it is data that can be easily represented as a string and stored in the query string, then you can just add it to the route values of the redirect.
e.g.
return RedirectToAction("Search", new { searchString = "whatever" });
If it is a complex type, then you will need to store it in TempData. A number of other questions on StackOverflow (such as this one) give details on how.
If repeatedly storing to and reading from TempData across your application offends your code-sense, then you can encapsulate this by using the PassParametersDuringRedirect attribute and generic RedirectToAction available in the MvcContrib project. Some details on this technique are available here.
only way of doing post is by having a form and doing submit on that form, either with a submit button or with javascript, any info you want passed to that action must be in that form and you will find everything posted in FormCollection(hope I spelled it right).