chart changes

This commit is contained in:
venbaittech 2025-02-21 09:11:34 +05:30
parent bdcdf737a8
commit a1993712ac
2 changed files with 409 additions and 700 deletions

View File

@ -1346,10 +1346,9 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
// If chartFilteredData is empty, print the message // If chartFilteredData is empty, print the message
if (chartFilteredData.isEmpty) { if (chartFilteredData.isEmpty) {
if (kDebugMode) { if (kDebugMode) {
print( print("Selected year: ${selectedFilters.firstWhere((f) => f['filter_key'] == 'TIME_PERIOD',
"Selected year: ${selectedFilters.firstWhere((f) => f['filter_key'] == 'TIME_PERIOD', orElse: () => { orElse: () => {'filter_data': ['Unknown']})['filter_data']} - No data for chart: : $chartHeading");
'filter_data': ['Unknown']
})['filter_data']} - No data for chart: : $chartHeading");
} }
// Add the complete chart data to the filteredData list // Add the complete chart data to the filteredData list
@ -1372,6 +1371,7 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
addedChartIds addedChartIds
.add(chart['chart_heading']); // Track by a unique identifier .add(chart['chart_heading']); // Track by a unique identifier
} }
} }
// List filteredCardData = []; // List filteredCardData = [];
@ -1799,18 +1799,21 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
print("FilteringDAtss START1 - $filterData"); print("FilteringDAtss START1 - $filterData");
print('TABId1 - $tabId'); print('TABId1 - $tabId');
// for (var item in filterData) {
// if (item['filter_key'] == 'TIME_PERIOD') { for (var item in filterData) {
// // Convert the values to integers, sort them, and convert back to strings if (item['filter_key'] == 'TIME_PERIOD') {
// List<int> timePeriodData = item['filter_data'] // Convert the values to integers, sort them, and convert back to strings
// .map<int>((e) => int.parse(e.toString())) // Convert to int List<int> timePeriodData = item['filter_data']
// .toList(); .map<int>((e) => int.parse(e.toString())) // Convert to int
// timePeriodData.sort((a, b) => a.compareTo(b)); // Sort numerically .toList();
// timePeriodData.sort((a, b) => a.compareTo(b)); // Sort numerically
// // Optionally, convert sorted integers back to strings if necessary
// item['filter_data'] = timePeriodData.map((e) => e.toString()).toList(); // Optionally, convert sorted integers back to strings if necessary
// } item['filter_data'] = timePeriodData.map((e) => e.toString()).toList();
// } }
}
print('TABId - $tabId'); print('TABId - $tabId');
print("TABFiltered Data: $filterData"); print("TABFiltered Data: $filterData");
@ -1927,6 +1930,10 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
}); });
double myheight = MediaQuery.of(context).size.height; double myheight = MediaQuery.of(context).size.height;
double mywidth = MediaQuery.of(context).size.width; double mywidth = MediaQuery.of(context).size.width;
int crossAxisCount = cardData.isNotEmpty ? (cardData.length / 2).ceil().clamp(1, 2) : 1;
final color = final color =
Color(int.parse(widget.bgColor.replaceFirst('0x', ''), radix: 16)); Color(int.parse(widget.bgColor.replaceFirst('0x', ''), radix: 16));
return PopScope( return PopScope(
@ -1938,45 +1945,6 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
child: BaseScaffold( child: BaseScaffold(
key: _scaffoldKey, key: _scaffoldKey,
// backgroundColor: color,
// appBar: AppBar(
// backgroundColor: color,
// elevation: 0,
// actions: [
// // IconButton(
// // onPressed: () {},
// // icon: const Icon(Icons.toggle_off_outlined),
// // ),
// MyToggle(
// // key: toggleKey,
// isOn: locale?.languageCode == 'en',
// knobTextWhenOn: 'ع',
// knobTextWhenOff: 'EN',
// pathColorWhenOn: Colors.grey.shade300,
// pathColorWhenOff: Colors.grey.shade300,
// onTap: () {
// ref.read(localeProvider.notifier).toggleLocale();
// },
// ),
// ],
// leading: IconButton(
// icon: Icon(Icons.arrow_back_ios_new, color: Colors.white),
// onPressed: () {
// if (widget.keyParam == 'home') {
// context.go('/myhomepage');
// } else {
// context.go('/uaenumbers');
// }
// },
// ),
// title: Text(
// context.translate(
// 'UAE Numbers',
// 'أرقام الإمارات',
// ),
// style: TextStyle(color: Colors.white),
// ),
// ),
title: Text( title: Text(
context.translate( context.translate(
'UAE Numbers', 'UAE Numbers',
@ -2035,25 +2003,7 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
fontFamily: 'Roboto'), fontFamily: 'Roboto'),
), ),
// Row(
// mainAxisAlignment: MainAxisAlignment.end,
// children: [
// IconButton(
// onPressed: () {},
// icon: Icon(
// Icons.bookmark_add_outlined,
// color: Colors.white,
// size: 40,
// )),
// IconButton(
// onPressed: () {},
// icon: Icon(
// Icons.share,
// color: Colors.white,
// size: 30,
// )),
// ],
// ),
], ],
), ),
)), )),
@ -2073,7 +2023,7 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
GestureDetector( GestureDetector(
onTap: () { onTap: () {
if (isBookmarked) { if (isBookmarked) {
showRemoveBookmarkDialog(); showRemoveBookmarkDialog();
} else { } else {
showAddBookmarkDialog(); showAddBookmarkDialog();
} }
@ -2194,37 +2144,43 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
size: 24, size: 24,
semanticLabel: 'Share', semanticLabel: 'Share',
), ),
),
), ),
),
], ],
), ),
SizedBox( SizedBox(
width: 10), // Horizontal space between items width: 10), // Horizontal space between items
Row( Row(
children: [ children: [
Text(
context.translate(
'Filter',
'فلتر',
),
style: const TextStyle(
fontSize: 16,
color: Colors.white,
),
),
SizedBox(width: 10),
GestureDetector( GestureDetector(
onTap: () { onTap: () {
showRightSideModal( showRightSideModal(
context, filterData, chartsData); context, filterData, chartsData);
}, },
child: Image.asset(
child: Row(
children: [
Text(
context.translate(
'Filter',
'فلتر',
),
style: const TextStyle(
fontSize: 16,
color: Colors.white,
),
),
SizedBox(width: 10),
Image.asset(
UaeNumbersAssetPath.filterUae, UaeNumbersAssetPath.filterUae,
color: Colors.white, // Set color to white color: Colors.white, // Set color to white
width: 21, width: 21,
height: 21, height: 21,
), ),
],),
) )
// IconButton( // IconButton(
// icon: Icon(Icons.filter_alt_outlined, // icon: Icon(Icons.filter_alt_outlined,
@ -2302,32 +2258,26 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
// nonChartData Cards // nonChartData Cards
Padding( Padding(
padding: const EdgeInsets.all(3.34), padding: const EdgeInsets.all(3.34),
child: GridView.builder(
child: GridView.builder(
key: cardKey, key: cardKey,
itemCount: cardData.length, itemCount: cardData.length,
shrinkWrap: true, shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
gridDelegate: gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount:crossAxisCount,
// crossAxisCount:2, // crossAxisCount: cardData.length % 2 == 0 ? 2 : 3,
crossAxisCount:
cardData.length % 2 == 0 ? 2 : 3, crossAxisSpacing: 2,
// crossAxisCount: cardData.length == 2
// ? 2
// : cardData.length == 3
// ? 3
// : cardData.length == 4
// ? 2
// : 3, // Default to 3 if more than 4 items // 2 cards per row
crossAxisSpacing: 2,
mainAxisSpacing: 5, mainAxisSpacing: 5,
childAspectRatio: MediaQuery.of(context) childAspectRatio: MediaQuery.of(context)
.size .size
.width / .width /
(MediaQuery.of(context).size.height / (MediaQuery.of(context).size.height /
(cardData.length % 2 == 0 (cardData.length % 2 == 0 ? 2 : 2)),
? 2
: 1.3)),
// childAspectRatio: // childAspectRatio:
// calculateAspectRatio(cardData.length, cardData), // calculateAspectRatio(cardData.length, cardData),
), ),
@ -2366,6 +2316,7 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
borderRadius: borderRadius:
BorderRadius.circular(12), BorderRadius.circular(12),
border: Border.all( border: Border.all(
color: Color(int.parse( color: Color(int.parse(
(chartScreenData[ (chartScreenData[
'border_color'] ?? 'border_color'] ??
@ -2444,15 +2395,17 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
height: 20.0, height: 20.0,
child: FittedBox( child: FittedBox(
child: Text( child: Text(
'(${response[0]['display_value'] ?? 'NA'})', // '(${response[0]['display_value'] ?? 'NA'})',
// '(${data['firstYear'] ?? RegExp(r'\d').hasMatch(response[0]['display_value'] ?? '')
// 'NA'} - ${data['lastYear'] ?? ? '(${response[0]['display_value'] ?? 'NA'})'
// 'NA'})', : '${response[0]['display_value'] ?? 'NA'}',
style: style:
const TextStyle( const TextStyle(
fontSize: 10, fontSize: 10,
color: Colors color: Colors.grey,
.grey), overflow: TextOverflow.ellipsis,
),
), ),
), ),
), ),
@ -2467,60 +2420,35 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
child: Row( child: Row(
children: [ children: [
Text( Text(
response[0][ response[0]['value'] ?? 'NA',
'value'] ??
'NA',
// '${data['roundedAverage'] ?? // '${data['roundedAverage'] ??
// 'NA'}', // 'NA'}',
style: TextStyle( style:
fontSize: 20, TextStyle(
fontSize: 18,
fontWeight: fontWeight:
FontWeight FontWeight.w800,
.w900, color: response[0]['calculation'] == 'different'
color: response[0] ? _getColorFromHex(response[0]['font_color'])
[ : const Color(0xFF90B0D5),
'calculation'] ==
'different'
? _getColorFromHex(
response[0]
[
'font_color'])
: const Color(
0xFF90B0D5),
// color: Color( // color: Color(
// 0xFF90B0D5), // 0xFF90B0D5),
), ),
), ),
const SizedBox( const SizedBox(width: 1), // Space between text and icon
width: if (response[0]['calculation'] == 'different') ...[
1), // Space between text and icon if (response[0]['font_color'] == '#D83731')
if (response[0][ const Icon(Icons.arrow_downward, color: Colors.red, size: 20)
'calculation'] == else if (response[0]['font_color'] == '#11AF22')
'different') ...[ const Icon(Icons.arrow_upward, color: Colors.green, size: 20),
if (response[0][
'font_color'] ==
'#D83731')
const Icon(
Icons
.arrow_downward,
color: Colors
.red,
size: 22)
else if (response[
0][
'font_color'] ==
'#11AF22')
const Icon(
Icons
.arrow_upward,
color: Colors
.green,
size: 22),
], ],
], ],
), ),
), ),
), ),
), ),
], ],
), ),
@ -2608,12 +2536,16 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
), ),
const SizedBox(height: 1), const SizedBox(height: 1),
Text( Text(
'(${response[0]['display_value'] ?? 'NA'})', // '(${response[0]['display_value'] ?? 'NA'})',
RegExp(r'\d').hasMatch(response[0]['display_value'] ?? '')
? '(${response[0]['display_value'] ?? 'NA'})'
: '${response[0]['display_value'] ?? 'NA'}',
// '(${data['lastYear'] ?? 'NA'})',
style: const TextStyle( style: const TextStyle(
fontSize: 10, fontSize: 10,
color: Colors.grey), color: Colors.grey,
overflow: TextOverflow.ellipsis,),
), ),
const SizedBox(height: 1), const SizedBox(height: 1),
Flexible( Flexible(
@ -2628,18 +2560,13 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
// data['lastYearValue']), // data['lastYearValue']),
// apiService.formatAmount( // apiService.formatAmount(
// data['lastYearValue']), // data['lastYearValue']),
style: TextStyle( style: TextStyle(
fontSize: 18, fontSize: 18,
fontWeight: fontWeight:
FontWeight.w900, FontWeight.w900,
color: response[0][ color: response[0]['calculation'] == 'different'
'calculation'] == ? _getColorFromHex(response[0]['font_color'])
'different' : const Color(0xFF90B0D5),
? _getColorFromHex(
response[0][
'font_color'])
: const Color(
0xFF90B0D5),
), ),
), ),
), ),
@ -2666,26 +2593,26 @@ class _ChartScreen1State extends ConsumerState<ChartScreen1> {
fontSize: 14, fontSize: 14,
fontWeight: fontWeight:
FontWeight.w600, FontWeight.w600,
color: response[1][
'calculation'] == color: response[1]['calculation'] == 'different'
'different' ? _getColorFromHex(response[0]['font_color'])
? _getColorFromHex( : const Color(0xFFD83731),
response[0][
'font_color'])
: const Color(
0xFFD83731),
), ),
), ),
), ),
), ),
Text( Text(
'(${response[1]['display_value'] ?? 'NA'})', // '(${response[1]['display_value'] ?? 'NA'})',
// '(${data['secondLastYear'] ?? 'NA'})', RegExp(r'\d').hasMatch(response[1]['display_value'] ?? '')
? '(${response[1]['display_value'] ?? 'NA'})'
: '${response[1]['display_value'] ?? 'NA'}',
style: const TextStyle( style: const TextStyle(
fontSize: 9, fontSize: 9,
fontWeight: fontWeight:
FontWeight.w500, FontWeight.w500,
color: Colors.grey), color: Colors.grey,
overflow: TextOverflow.ellipsis,),
), ),
], ],
), ),
@ -2822,4 +2749,4 @@ Color _getColorFromHex(String hexColor) {
hexColor = 'FF$hexColor'; // Add alpha if not provided hexColor = 'FF$hexColor'; // Add alpha if not provided
} }
return Color(int.parse(hexColor, radix: 16)); return Color(int.parse(hexColor, radix: 16));
} }

File diff suppressed because it is too large Load Diff