How can I use two different StreamProvider with Value - flutter

I'm developing an online shopping app, I want to check if the product in the user's wishlist/favorite list or not.
To read all products from firestore I used a stream getter method in a DatabaseService class that reads all products and then maps to the Product Model. In the Home screen I used StreamProvider<List>.value(....) and then in the display section (where I want to display products) I said:
final products = Provider.of<List<Product>>(context);
and then I used a grid view builder to display all products. it worked well. But I want to check if this product in the user's favorite list / wishlist, how can I know??
I tried many ways but it does not worked

Related

How to save shared Preferences for different users? Flutter

I have a List<String> which saves names of categories using shared preferences.
I did everything right but the problem is that every user should have his own categories that he created, if he didn't create anything.. just show default categories not other users categories.
Default categories :
List<String> defaultCategories = [ "Health", "Finance", "Tech"];
Let's say now User A logged in and what he will see is the default categories, he can add to them remove them and that's just fine.. Let's say he added one new category, so he will see it and will be saved in shared preferences and that's good.
User A signs out and then sign in and everything is as he left.. that's great!
Now, when a User B login.. guess what he sees? User A categories!! that's the problem.
I want User B to see default categories if he didn't change anything or sees his own categories.
Can anyone help me in that?
Thanks in advance.
You can manage it multiple ways, and all of them correct so you must just choose one of them.
Ex you can do with these steps;
1.You can cache the default list with a general key in shared preferences.
2.You can add a category list for your user model(nullable),
3.You can save the your user model to your shared preferences with the users unique id.
In this way you can retrive your users category list from shared preferences.
In this way you can retrive default category list from shared preferences.
How can you determine to your user category list?
You can just call the below getter in your view model, controller or where are you needing.
bool get hasUserCategories=>usermodel.categories!= null && usermodel.categories!.isNotEmpty;

How can I create a dynamic price list that is dependent on the type of car that the user has using flutter?

I have a car service section that when a user clicks on he or she is directed to the price list page. My problem is the list should be dynamic and is different for users who have a SUV when compared to the users that have a Sedan. How can I Implement this using flutter?
You can pass data to the class of the page you are going to render where you will make a switch on the type, or whatever, of the car and do you logic.
In the class declare a property and require it on the class signature.. then when you push the page give to that property a value.

Data operation in BLOC

I have a shopping application. I am trying to use the most recommended approach BLOC for the project.
Now I have a screen which contains three major parts
Categories list
Product list
Cart list
Now these subsections of that 1 screen have this operation
load/fetch
apply conditions or filter data
then multiple operations on loaded data
For example like I have a cart
Now in the cart, I have these operations
before adding a product to the cart there are multiple operations
of filtering the data like if the product has discounts or not. if so
then app discount and update price.
increment/decrement
edit
Now I am not getting the idea that should I?
The screen has 3 major sections like portions so should I use 3
blocs of 1 bloc
most apps have examples like to load, show, success, and error type
events and states so where will I apply these increment/decrements,
and apply discount operations?
there may be a case where I will have to access the current data
state from another class or file or bloc. so in short I want to hold
the data to share across multiple screens
For me, i associate every api request with a bloc.
so for example in your case, u have a Cart Page.
I would assume u have these few API requests,
GetCart
RemoveItemFromCart
UpdateItemQuantityInCartItem
So u will have then (using cubit)
GetCartCubit
RemoveItemFromCartCubit
UpdateItemQuantityInCartItemCubit
And each of this blocs can have a function called request() where you pass the data required for the api request and make an api request to a repository where u have your client API requests.
And each of this blocs will have states.
Initial
Requesting - state where api request made waiting for a response
Requested - state where there is a successful API response
Error - error state for when an API returns an error
You can check out this repo for a good example:
https://github.com/momoDragon/flutter_structure

Ember CLI - Custom routing for very basic dropdown

New to ember and ember cli, and not having any JS based framework experience apart from jQuery (which is not a framework)
I find my self stuck at the very beginning compared to work done in Angular,
I have a static list of groups which are on REST api `http://localhost:8000/api/groups' and it is only 8 items there, I needed to show them as dropdown for a search criteria. Nothing fancy
I started with creating a route and model with the name of groups but app stopped working and I had to create a model for group which is identical to groups model, only having 2 items for dropdown
Now i have a url in my ember app http://localhost:4200/groups which I dont need and i dont want it to be there,
But I ignored it and had to create a dropdown of the cities, api is
http://localhost:8000/api/cities <-- All cities list, needed for admin
http://localhost:8000/api/cities/active <-- For clients to show active cities so they can add their records
http://localhost:8000/api/cities/filled <-- For users, to show them where clients are available
So in ember, I created a route and model for cities, and same model is copied as city just to show the list of cities in dropdown, I needed to show cities which are filled, I had created ember g route city/filled and it created folders, but its model is also same like other two models.
Ajax call is not being sent to city/filled url and now I ended up having
http://localhost:4200/cities // useless for me
http://localhost:4200/cities/filled //useless for me
and in filled i see that ajax call is made but to the http://localhost:8000/api/cities two times, loading same data. I tried adding a dropdown on my application and opened http://localhost:4200/cities/filled in browswer, and woosh, it send ajax call to the same url 3 times, one for application.hbs and one for cities.hbs and one for city/filled. Why load the same data 3 times if it is already fetched from same url within single request?
in angular I just call a custom url and I can get the data, but for ember its really hard to get grip on these small things and there is no help around
active and filled are filters for your cities resource and these are not standalone resources, so you should try to use them as query parameters. like
http://localhost:8000/api/cities?type=filled
http://localhost:8000/api/cities?type=active
Facebook uses this style for query params. You can also use query params for getting paginated data of a resource, like for 1st page and 25 records per page, the request will look like:
http://localhost:8000/api/cities?page=1&records=25

Can PayPal's CUSTOM variable be used on eBay?

I program with PHP and I'm familiar with getting data from PayPal's IPN. I need to send custom data to ebay and get it back when payment is made. For example, if sold 1 Widget on ebay and that widget has a stock number of 12345A, I receive data back from PayPal. I get things like customer's name, address, item name, etc. But, unless I include that stock number in my title, I don't see any way to get that data back from PayPal. I don't want to use ebay's limited title space for including my stock numbers. I realize I could do it if I had another database to store ebay's item numbers and cross reference them with my stock numbers, but I don't want to do that.
I have noticed that when data comes back from PayPal after an ebay sale, it includes the custom variable and that variable has a large number in assigned to it. I have no idea what that is. I've also tried using ebay's custom label feature that's found in Turbo Lister and Selling Manager Pro. I was hoping that would be sent back in PayPal's custom variable, but no luck. Any ideas?
As you've discovered, it looks like it's some internal id number uniquely identifying each eBay order. You can probably forget about specifying a value for this field as it isn't documented anywhere.
The best solution to your problem is to use the eBay API. GetSingleItem will return information about an item given the item id.
The ItemSpecifics list will contain any item specific data that the seller has entered about the product. In my case, I added a custom field called SKU to the eBay item. Just add itemspecifics to your include selector. The call can be executed with a GET request:
http://open.api.ebay.com/shopping?callname=GetSingleItem&IncludeSelector=ItemSpecifics&appid=YOURAPPID=515&ItemID=ITEMIDOFINTEREST
What you get back will contain those custom fields you added to your item:
..
<ItemSpecifics>
<NameValueList>
<Name>MPN</Name>
<Value>MyPartModelA</Value>
</NameValueList>
<NameValueList>
<Name>SKU</Name>
<Value>123-456</Value>
</NameValueList>
</ItemSpecifics>
..