0

I have finally made my bagel order test app. I can load bagels from json file. Building a list and display on screen. I have added cubit to mange the bagel total state All this works fine.

But I new I would run into this next problem as I was getting cubit state working.

When I select + to increment from 0 to 1 for plain bagels. see pix attached first is start of app. all bagel counts are set to zero, after pressing + 3 times, they all update to 3 . All the count fields update. I understand right now they all have the same field name used in cubit.

I looking for suggestion on how to fix this.

  1. old school i assign a unique name to each generate item in the listview for bagel total. But how would i use cubit to manage state?
  2. I started reading about maybe using Keys, but they seem to me not to be the answer.
  3. I know each item in the list has a unique index. As I have display on the app for testing.

I increment plain bagel and all bagels are updated. So what would be the correct way to address this?

thanks new to flutter/dart so getting my feet wet...

incremented shows all going from zero to 3 [1]: https://i.stack.imgur.com/7N6Gp.png

  • Bloc is an architecture pattern. The main concept is to separate your UI and Buisness Logic <- Backend code / functions that you run eg. onPressed and onTap. The Bloc pattern mainly uses streams to update the state <- data being used by ui. You can implement bloc using ordinary streams, rxdart, or flutter_bloc. You have to learn provider or get_it as well to make your model <- variables and available for use in any screen. By doing that, you don't have to pass your data around just to make it accessible to the UI. https://flutter.dev/docs/development/data-and-backend/state-mgmt/options – CoderUni Jan 28 '21 at 03:43
  • i have the cubit bloc working. just there are now examples I can find as to what i need to do with bloc in this listview. setting. most bloc/cubit examples are just one simple app and one field + 0 1 nothing more. I am RTFM as best i can. – Bill Sanderson Jan 28 '21 at 03:55
  • The best way to do that is to have a list of food models: https://fluttercrashcourse.com/blog/05-models . After you place your variables, place a BlocBuilder along with each model inside your ListView.builder(). So if food model 1 contains bagel and 3 quantities, pressing inc or dec will inc or dec that certain food model only. So something like this myFoodList[0].quantity will be displayed in the ui – CoderUni Jan 28 '21 at 04:11

0 Answers0