Aidra Connect 10.0.2+16
Aidra Connect Mobile Application
Loading...
Searching...
No Matches
this_month_earnings_card.dart
Go to the documentation of this file.
1import 'package:connect/core/constants/app_values.dart';
2import 'package:connect/core/localization/app_localizations.dart';
3
4import '/core/ui/widgets/custom_card.dart';
5import 'package:flutter/material.dart';
6import 'package:flutter_screenutil/flutter_screenutil.dart';
7import 'package:intl/intl.dart';
8
9class ThisMonthEarningCard extends StatelessWidget {
10 const ThisMonthEarningCard({
11 super.key,
12 required this.earningActualMonth,
13 required this.earningLastMonth,
14 });
15
16 final num? earningActualMonth;
17 final num? earningLastMonth;
18
19 @override
20 Widget build(BuildContext context) {
21 return CustomCard(
22 child: Column(
23 crossAxisAlignment: CrossAxisAlignment.start,
24 children: [
25 Row(
26 children: [
27 Text(
28 AppLocalizations.of(context).translate('THIS MONTH EARNINGS'),
29 style: Theme.of(context).textTheme.bodySmall,
30 ),
31 const Spacer(),
32 Text(
33 NumberFormat.currency(symbol: AppValues.currency)
34 .format(earningActualMonth),
35 style: Theme.of(context).textTheme.bodySmall?.copyWith(
36 color: Theme.of(context).primaryColor,
37 fontSize: 14.sp,
38 fontWeight: FontWeight.bold,
39 ),
40 ),
41 ],
42 ),
43 SizedBox(height: 12.sp),
44 _compareEarnings(
45 earningActualMonth ?? 0,
46 earningLastMonth ?? 0,
47 context,
48 ),
49 ],
50 ),
51 );
52 }
53
54 RichText _compareEarnings(num current, num previous, BuildContext context) {
55 // final NumberFormat percentageFormat = NumberFormat.decimalPercentPattern(
56 // decimalDigits: 1); // Shows proper percentage format
57 TextStyle? smallTextStyle = Theme.of(context).textTheme.bodySmall?.copyWith(
58 color: Theme.of(context).hintColor,
59 fontSize: 11.sp,
60 );
61
62 if (previous == 0) {
63 if (current == 0) {
64 return RichText(
65 text: TextSpan(
66 text: AppLocalizations.of(context)
67 .translate('No earnings this month compared to last month'),
68 style: smallTextStyle,
69 ),
70 );
71 } else {
72 return RichText(
73 text: TextSpan(
74 children: [
75 TextSpan(
76 text:
77 "100%", // If previous was 0 and now there’s earnings, it’s a 100% increase
78 style: Theme.of(context).textTheme.bodySmall?.copyWith(
79 color: Theme.of(context).primaryColor,
80 fontWeight: FontWeight.bold,
81 ),
82 ),
83 TextSpan(
84 text:
85 ' ${AppLocalizations.of(context).translate('higher earnings than last month')}',
86 style: smallTextStyle,
87 ),
88 ],
89 ),
90 );
91 }
92 }
93
94 double difference = (current - previous) / previous;
95 bool isHigher = difference > 0;
96
97 return RichText(
98 text: TextSpan(
99 children: [
100 TextSpan(
101 text: NumberFormat.percentPattern()
102 .format(difference), // Formats correctly as a percentage
103 style: TextStyle(
104 color: isHigher
105 ? Theme.of(context).primaryColor
106 : Theme.of(context).colorScheme.error,
107 fontSize: 11.sp,
108 fontWeight: FontWeight.bold,
109 ),
110 ),
111 TextSpan(
112 text: isHigher
113 ? ' ${AppLocalizations.of(context).translate('higher earnings than last month')}'
114 : difference < 0
115 ? ' ${AppLocalizations.of(context).translate('lower earnings than last month')}'
116 : ' ${AppLocalizations.of(context).translate('Earnings are the same as last month')}',
117 style: smallTextStyle,
118 ),
119 ],
120 ),
121 );
122 }
123}
AppLocalizations(this.locale)
const CustomCard({ super.key, required this.child, this.padding, this.bgColor, })
override Widget build(BuildContext context)
Definition app_view.dart:19
final Widget child
final Color color
Definition failures.dart:1
class LastThreeMonthsPerformanceCard extends StatefulWidget earnings