Home > Net >  Show icons by Dart Flutter action type
Show icons by Dart Flutter action type

Time:02-19

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?

CodePudding user response:

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(transactionType),
                title: Text(islemler[index].islemTuru, style: TextStyle(fontSize: 20)),
                subtitle: Text(islemler[index].islemTarihi,),
                trailing: Text(islemler[index].islemMiktari, style: TextStyle(fontSize: 20)),
              ),
            );
          },
          ),
          ),
        ],
      ),
    ),
    );
  }
}

Widget processIcon(String transactionType) {
    switch transactionType{
        case "sent":
            return Icon(); // Put the icon for 'sent' here
           
        case "withdrawn": 
            return Icon(); // Put the icon for 'withdrawn' here

        case "transaction1": 
            return Icon(); // Put the icon for 'transaction1' here

        case "transaction2": 
            return Icon(); // Put the icon for 'transaction2' here

        default:
            return Icon(); // Put a default icon in case transactionType variable is not one of the above.
    }
}

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

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

I am not sure what is type of your transaction. You should be able to pass it to the function and handle it from there.

CodePudding user response:

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

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