我從這樣的服務器獲取串列
[
{
"Date": "2022-10-21",
"Wages": [
{
"Name": "101 Working hours",
"Balance": "8.00",
"Date": "2022-10-21",
"ShiftName": "AU128"
},
{
"Name": "102 Bonus pay",
"Balance": "3:48",
"Date": "2022-10-21",
"ShiftName": ""
},
{
"Name": "110 Split Shift",
"Balance": "1:00",
"Date": "2022-10-21",
"ShiftName": ""
},
{
"Name": "111 Wage reduction",
"Balance": "1:00",
"Date": "2022-10-21",
"ShiftName": ""
}
]
},
]
如果 ShiftName 不為空并在 FE 顯示,我想獲取它。班次名稱在工資單中
Text(
Wages[i].shiftName ?? "",
style: wageTextStyle,
),
我嘗試使用List.any((any) => any.containsValue());
但我不知道我從服務器得到哪個值,因為 shiftName 可以更改
我來自提供者消費者的 API 呼叫方法
Consumer<EmployeeWageAccountsProvider>(
builder: (context, data, child) {
if (!data.isLoading) {
int length = data.getEmployeeAccountsData!.length;
if (data.getEmployeeAccountsData!.isNotEmpty) {
wageAccountsData = data.getEmployeeAccountsData!;
return ListView.builder(
itemCount: length,
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemBuilder: (context, i) {
return WageAccountsCard(
date: Helper.formatStringDate(
wageAccountsData[i].date!),
shiftName: wageAccountsData[i].wages!
[i].shiftName!.isEmpty ? "":wageAccountsData[i].wages!
[i].shiftName,
wages: wageAccountsData[i].wages,
);
},
);
}
return noDataFound(context, 50);
}
return const WageAccountsShimmer();
}),
工資賬戶卡向用戶顯示資料
class WageAccountsCard extends StatelessWidget {
final String? date;
final String? shiftName;
final List<Wages>? wages;
const WageAccountsCard(
{Key? key,
this.date,
this.shiftName,
this.wages})
: super(key: key);
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.all(10),
padding: const EdgeInsets.all(8),
decoration: CustomBoxDecoration.cardDecoration(context,
shadow: true),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
shiftName ?? "",
style: wageTextStyle,
),
Text(
date.toString(),
style: wageTextStyle,
),
],
),
SizedBox(
height: Styles.height(context) * 0.01,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
S.of(context).wage_type,
style: cTextStyle,
),
Text(
S.of(context).balance,
style: cTextStyle,
),
],
),
const Divider(
color: Colors.black,
),
ListView.builder(
itemBuilder: (context, index) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
wages![index].name!,
style: cTextStyle,
),
Text(
wages![index].balance.toString(),
style: cTextStyle,
),
],
);
},
itemCount: wages!.length,
shrinkWrap: true,
),
SizedBox(
height: Styles.height(context) * 0.01,
),
],
),
);
} }

uj5u.com熱心網友回復:
shiftName ?? "",用于在 null 情況下回傳默認值。
你得到空字串,因此你可以做
shiftName.isEmpty ? "onEmptyCaseValue" : shiftName
uj5u.com熱心網友回復:
return shiftName.isEmpty ? Center(child: Text('Empty')) : Text(
shiftName ?? "",
style: wageTextStyle,
),
uj5u.com熱心網友回復:
wageAccountsData[i].wages!
[i].shiftName!.isEmpty ? "":wageAccountsData[i].wages[i].shiftName,
插入這個就這樣寫
wageAccountsData[i].wages![i].shiftName ?? "Default Text",
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/526224.html
標籤:扑镖飞镖零安全
