Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

How to get and update the index of a current item in flutter

Please I need help. I have a List whose item is a class with the different items (class variables). Here is my code

class ProductProvider with ChangeNotifier {
 static List<Product> _items = [
    **Product(
        id: 'KIOEL9IKJD',
        designId: 'Pack',
        title: 'Varities',,
        *price: 120,*
     ),**
    Product(
        id: 'KILE9IKDJK',
        designId: 'Pack',
        title: 'Cheeze',
        price: 20),
    Product(
      id: 'LOIR9IOEHD',
      designId: 'Fresh',
      title: 'Berry',
      price: 70,
    ),
  ];

  List<Product> get items {
    return [..._items];
  }
}

Then, I used ListView.builder to send the data to a new screen when clicking on, now my problem is, in the new screen how can I dynamically (without saying _items[1].price) get its index so that I can update the only price of the item by a button click and also add the updated total price


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...