简体   繁体   English

按 Dart Flutter 操作类型显示图标

[英]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 .我将在leading中显示图标。

Transactions are in the list of transactions.交易在交易列表中。

How can I show different icon according to process?如何根据进程显示不同的图标?

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.您应该能够将其传递给 function 并从那里进行处理。

Just check if money is sent or not and then return a different icon只需检查是否发送了钱,然后返回一个不同的图标

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM