From 1c8515709a79fd358f51053e93c6ff957ba8b678 Mon Sep 17 00:00:00 2001 From: venbaittech Date: Fri, 21 Mar 2025 18:08:31 +0530 Subject: [PATCH] filter and charts bug fix --- android/app/build.gradle | 4 +- .../Screens/charts/screens/chart_screen.dart | 15 ++- .../Screens/charts/widgets/chart_widget.dart | 92 ++++++++++++++++++- pubspec.yaml | 2 +- 4 files changed, 101 insertions(+), 12 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 308dea91..85b1ce96 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -20,12 +20,12 @@ if (project.hasProperty('google-services.json')) { def flutterVersionCode = localProperties.getProperty("flutter.versionCode") if (flutterVersionCode == null) { - flutterVersionCode = "41" + flutterVersionCode = "42" } def flutterVersionName = localProperties.getProperty("flutter.versionName") if (flutterVersionName == null) { - flutterVersionName = "1.0.40" + flutterVersionName = "1.0.41" } def keystorePropertiesFile = rootProject.file("key.properties") diff --git a/lib/presentation/Screens/charts/screens/chart_screen.dart b/lib/presentation/Screens/charts/screens/chart_screen.dart index b9b70203..fe546771 100644 --- a/lib/presentation/Screens/charts/screens/chart_screen.dart +++ b/lib/presentation/Screens/charts/screens/chart_screen.dart @@ -451,7 +451,8 @@ class _ChartScreen1State extends ConsumerState { ///Calculate card Width Future _getWidget() async { await Future.delayed(Duration(milliseconds: 50)); // Ensures widget is built - final RenderBox? box = cardKey.currentContext?.findRenderObject() as RenderBox?; + final RenderBox? box = + cardKey.currentContext?.findRenderObject() as RenderBox?; if (box != null) { final Offset position = box.localToGlobal(Offset.zero); @@ -537,7 +538,7 @@ class _ChartScreen1State extends ConsumerState { final double screenHeight = MediaQuery.of(context).size.height; // print('remaintarget $remainHeight'); // print ('at intint target : ${screenHeight-remainHeight}'); - final double arrowPosition= screenHeight-tourCard; + final double arrowPosition = screenHeight - tourCard; marriageTargets = [ TargetFocus( enableTargetTab: false, @@ -561,7 +562,7 @@ class _ChartScreen1State extends ConsumerState { child: Stack( children: [ Positioned( - bottom: arrowPosition*0.41, + bottom: arrowPosition * 0.41, left: 16, right: 16, child: Column( @@ -871,7 +872,7 @@ class _ChartScreen1State extends ConsumerState { final double screenHeight = MediaQuery.of(context).size.height; // print('remaintarget $remainHeight'); // print ('at intint target : ${screenHeight-remainHeight}'); - final double arrowPosition= screenHeight-tourCard; + final double arrowPosition = screenHeight - tourCard; previousMarriageTargets = [ TargetFocus( enableTargetTab: false, @@ -1055,7 +1056,7 @@ class _ChartScreen1State extends ConsumerState { child: Stack( children: [ Positioned( - bottom: arrowPosition*0.41, + bottom: arrowPosition * 0.41, left: 16, right: 16, child: Column( @@ -1794,6 +1795,9 @@ class _ChartScreen1State extends ConsumerState { Expanded( child: ElevatedButton( onPressed: () { + setState(() { + isLoading = true; + }); selectedFilters.forEach((filter) { filter["filter_data"].clear(); }); @@ -1849,6 +1853,7 @@ class _ChartScreen1State extends ConsumerState { "Selected Filters before applying: $selectedFilters"); setState(() { + isLoading = true; chartsData = originalTabChartsData; cardData = originalTabCardData; }); diff --git a/lib/presentation/Screens/charts/widgets/chart_widget.dart b/lib/presentation/Screens/charts/widgets/chart_widget.dart index bcf5bc46..cc917b4c 100644 --- a/lib/presentation/Screens/charts/widgets/chart_widget.dart +++ b/lib/presentation/Screens/charts/widgets/chart_widget.dart @@ -335,7 +335,70 @@ class ChartWidget extends StatelessWidget { }).toList(); } - List generateIndicators(dynamic chartData) { + // List generateIndicators(dynamic chartData) { + // var groupByKeyValue; + // if (chartData['chart_type_json']['chart_type'] == 'bar_chart_horizontal' || + // chartData['chart_type_json']['chart_type'] == 'horizontal_rotate') { + // groupByKeyValue = chartData['chart_type_json']['y_group'] ?? ''; + // } else { + // groupByKeyValue = chartData['chart_type_json']['x_group'] ?? ''; + // } + // + // return [ + // Center( + // child: Wrap( + // alignment: WrapAlignment.center, // Center-align all items + // spacing: 10, // Adjust horizontal spacing + // runSpacing: 5, // Adjust vertical spacing for wrapping + // children: chartData['response'].asMap().entries.map((entry) { + // int index = entry.key; + // var data = entry.value; + // Color color = Colors.primaries[index % Colors.primaries.length]; + // String title = data['ObsKey'][groupByKeyValue] ?? ''; + // + // return Container( + // padding: EdgeInsets.symmetric(vertical: 4), // Add spacing + // child: Row( + // mainAxisSize: + // MainAxisSize.min, // Wrap content without extra space + // mainAxisAlignment: + // MainAxisAlignment.center, // Align items center + // crossAxisAlignment: + // CrossAxisAlignment.center, // Align vertically + // children: [ + // Container( + // width: 10, + // height: 10, + // decoration: BoxDecoration( + // color: uniqueColors[index % uniqueColors.length], + // shape: BoxShape.circle, + // ), + // ), + // SizedBox(width: 5), + // ConstrainedBox( + // constraints: BoxConstraints( + // maxWidth: 200, // Ensures text wraps within a limit + // ), + // child: Text( + // title, + // style: TextStyle(fontSize: 12), + // softWrap: true, // Allow text to wrap naturally + // textAlign: TextAlign.center, // Center text alignment + // ), + // ), + // ], + // ), + // ); + // }).toList(), + // ), + // ), + // ]; + // } + + List generateIndicators( + dynamic chartData, + double totalValue, + ) { var groupByKeyValue; if (chartData['chart_type_json']['chart_type'] == 'bar_chart_horizontal' || chartData['chart_type_json']['chart_type'] == 'horizontal_rotate') { @@ -348,9 +411,30 @@ class ChartWidget extends StatelessWidget { var data = entry.value; Color color = Colors.primaries[index % Colors.primaries.length]; String title = data['ObsKey'][groupByKeyValue] ?? ''; + // String value = data['ObsValue']['Value'].toString(); String shortTitle = title.length > 10 ? '${title.substring(0, 10)}…' : title; + // Handle different types: int, double, and String + double value = 0.0; + var rawValue = data['ObsValue']['Value']; + + if (rawValue is String) { + value = double.tryParse(rawValue) ?? 0.0; + } else if (rawValue is num) { + value = rawValue.toDouble(); + } else if (rawValue is double) { + value = rawValue; + } else { + print('Unexpected Type for ObsValue[Value]: ${rawValue.runtimeType}'); + } + + // double percentage = (value / totalValue) * 100; + String percentage = (totalValue > 0) + ? ((value / totalValue) * 100).toStringAsFixed(1) + : "0.0"; + // bool isTouched = index == touchedIndex; + return Row( mainAxisSize: MainAxisSize.min, children: [ @@ -376,9 +460,9 @@ class ChartWidget extends StatelessWidget { message: title, // Full text on hover child: ConstrainedBox( // Constrain width to allow wrapping - constraints: BoxConstraints(maxWidth: 200), + constraints: BoxConstraints(maxWidth: 250), child: Text( - title, + '$title -- $percentage%', style: TextStyle( fontSize: 12, ), @@ -630,7 +714,7 @@ class ChartWidget extends StatelessWidget { child: Column( // Change Row to Column crossAxisAlignment: CrossAxisAlignment.start, - children: generateIndicators(chartData), + children: generateIndicators(chartData, totalValue), ), ), ), diff --git a/pubspec.yaml b/pubspec.yaml index f8a4b1ba..7d133b2a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: uae_stat description: "View statistics about the UAE from the Federal Center for Statistics and Competitiveness." publish_to: "none" -version: 1.0.40+41 +version: 1.0.41+40 environment: sdk: ">=3.2.3 <4.0.0"