'Show icons by Dart Flutter action type

code:

import 'package:flutter/material.dart';

class sonIslemlerUygulamasi extends StatelessWidget {
  const sonIslemlerUygulamasi({Key? key}) : super(key: key);

  get islemler => islemler;

  @override
  Widget build(BuildContext context) {
    List <sonIslemler> islemler = [sonIslemler("10 Kasım", "Send money", "500 USD", "Borç"), sonIslemler("11 Kasım", "Withdraw money", "50 TL", "Yok")];


    return Scaffold(
      appBar: AppBar(
        title: Text("Son işlemler"),
        backgroundColor: Colors.red[500],
      ),
      body: Center(
        child: Column(
        children: [
          
          Text("\nSon işlemler", style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),),
          Text("Son işlemler uygulamasına hoş geldiniz.\n", style: TextStyle(fontSize: 20), textAlign: TextAlign.center,),
          Expanded(
          child: ListView.builder(
          itemCount: islemler.length,
          itemBuilder: (BuildContext context, int index) {
            return Card(
              child: ListTile(
                leading: processIcon(),
                title: Text(islemler[index].islemTuru, style: TextStyle(fontSize: 20)),
                subtitle: Text(islemler[index].islemTarihi,),
                trailing: Text(islemler[index].islemMiktari, style: TextStyle(fontSize: 20)),
              ),
            );
          },
          ),
          ),
        ],
      ),
    ),
    );
  }
}

processIcon() {
  // Process icon codes
}

class sonIslemler {
  String islemTarihi;
  String islemTuru;
  String islemMiktari;
  String islemAciklamasi;

  sonIslemler(this.islemTarihi, this.islemTuru, this.islemMiktari, this.islemAciklamasi);
}

My goal is to make an application that displays recent financial transactions. I want to show different icon if money is sent, different icon if money is withdrawn, and separate icon for each transaction.

i will show the icons in leading.

Transactions are in the list of transactions.

How can I show different icon according to process?



Solution 1:[1]

Just check if money is sent or not and then return a different icon

if (isSent()){
 return Icon(...)
}
else{
 return Icon(...)
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jacopo Carlini