Home > OS >  .map method in dart language
.map method in dart language

Time:12-18

I have UrunModel file. In the model file i have urunFiyat variable.

I have one static List sepetList = [];

and I want to sum the urunFiyat's in this list and write the following function:

But i can't find sum, what is the reason and what can i do?

Widget toplamSatiri() {
    double toplam = 1;
    if (Sepet.sepetList.isNotEmpty) {
      Sepet.sepetList.map((e) => toplam  = e.urunFiyat);
    } else {
      toplam = 0;
    } //burası çalışmıyor
    return Container(
      height: 60,
      decoration: boxesdecorations(Colors.black),
      child: Padding(
        padding: const EdgeInsets.all(10.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              'TOPLAM',
              style: Theme.of(context)
                  .textTheme
                  .headline5!
                  .copyWith(color: Colors.white),
            ),
            Text(
              '$toplam TL',
              style: Theme.of(context)
                  .textTheme
                  .headline5!
                  .copyWith(color: Colors.white),
            ),
          ],
        ),
      ),
    );
  }

CodePudding user response:

Change this line Sepet.sepetList.map((e) => toplam = e.urunFiyat); to this: Sepet.sepetList.map((e) { toplam = e.urunFiyat;}).toList();

edit: I forgot to add semicolon

  • Related