Untitled
unknown
dart
2 years ago
33 kB
5
Indexable
import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:get/get.dart'; import 'package:iktifaa/App/Common/Utilities/Constants/AppColors.dart'; import 'package:iktifaa/App/Mall/backend/Dto/storeIncome.dart'; import 'package:iktifaa/App/Mall/backend/storesAPIs.dart'; import 'package:iktifaa/App/Stores/modules/create_store/create_store_view/widget/primary_app_bar.dart'; import 'package:iktifaa/App/Stores/modules/store_reports/reports/SalesIncomereport/controller/SalesIncomereportController.dart'; import 'package:syncfusion_flutter_charts/charts.dart'; class SalesIncomereportView extends GetView<SalesIncomereportController> { @override Widget build(BuildContext context) { return Scaffold( backgroundColor: AppColors.backgroundColor, appBar: PrimaryAppBar( title: 'Income report'.tr, function: () { Get.back(); }, ), body: Obx( () => controller.isLoading.isTrue ? const Center(child: CupertinoActivityIndicator()) : ListView( children: [ ListTile( leading: ConstrainedBox( constraints: const BoxConstraints(maxHeight: 150), child: Container( decoration: BoxDecoration( shape: BoxShape.circle, boxShadow: [ BoxShadow( blurRadius: 6, offset: const Offset( 0, 2, ), color: Colors.grey.shade200) ], image: DecorationImage( image: NetworkImage( StoresAPIs.baseUrlMedia + controller.authManager.storeUser!.imageLogoUrl!), fit: BoxFit.cover, ), // borderRadius: BorderRadius.circular(20), color: Colors.white, ), width: Get.width * 0.15, ), ), // const Icon( // Icons.store, // size: 40, // color: AppColors.primary, // ), title: AutoSizeText( controller.authManager.storeUser!.name!, style: Get.textTheme.headline5!.copyWith( fontWeight: FontWeight.bold, ), ), ), const Divider(), Padding( padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 15), child: Row( children: [ SvgPicture.asset( 'assets/svg/money.svg', color: AppColors.primary, ), const SizedBox(width: 10), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Obx( () => controller.yearIndexValue.value > -1 ? AutoSizeText( Get.locale.toString() == 'ar_SA' ? 'Income'.tr + ' ${controller.monthList[controller.selectedMonthIndex.value]['nameAr']}' : '${controller.monthList[controller.selectedMonthIndex.value]['name']} ' + 'Income'.tr, style: Get.textTheme.subtitle1!.copyWith( color: Colors.black, height: 1, ), ) : const AutoSizeText(''), ), ], ), Row( children: [ Obx(() => controller.yearIndexValue.value > -1 ? AutoSizeText( 'Total'.tr + ' : ' + controller .getMonthlyIncome(controller.yearName.value, controller.selectedMonthIndex.value) .toString() + ' ' + 'SAR'.tr, style: Get.textTheme.headline5!.copyWith( fontWeight: FontWeight.bold, color: Colors.black, overflow: TextOverflow.clip, height: 1.5, ), ) : const AutoSizeText('')), ], ) // Row( // children: [ // Obx( // () => controller.getPercentage(controller // .selectedMonthIndex.value) == // 0 // ? Icon( // Icons.horizontal_rule_sharp, // color: Colors.grey.shade400, // ) // : controller // .getPercentage(controller // .selectedMonthIndex.value) // .isNegative // ? SvgPicture.asset( // 'assets/svg/down.svg', // // color: AppColors.primary, // ) // : SvgPicture.asset( // 'assets/svg/up.svg', // // color: AppColors.primary, // ), // ), // // Obx( // // () => Row( // // children: [ // // AutoSizeText( // // controller.selectedMonthIndex.value == // // 0 // // ? ' ' + // // controller // // .getPercentage(controller // // .selectedMonthIndex // // .value) // // .toStringAsFixed(1) + // // ' % ' // // : controller.storeIncome.value.monthData?[controller.selectedMonthIndex.value - 1].totalMonth == 0 && // // controller // // .storeIncome // // .value // // .monthData![controller // // .selectedMonthIndex // // .value] // // .totalMonth! > // // 0 // // ? controller.getPercentage(controller.selectedMonthIndex.value).toStringAsFixed(1) + // // ' ' + // // 'SAR'.tr + // // ' ' // // : ' ' + // // controller // // .getPercentage(controller // // .selectedMonthIndex // // .value) // // .toStringAsFixed(1) + // // ' % ', // // style: controller.getPercentage( // // controller // // .selectedMonthIndex // // .value) == // // 0 // // ? Get.textTheme.headline1!.copyWith( // // fontSize: 12, // // fontWeight: FontWeight.bold, // // color: Colors.grey.shade400, // // height: 1.5) // // : controller // // .getPercentage(controller // // .selectedMonthIndex // // .value) // // .isNegative // // ? Get.textTheme.headline1! // // .copyWith( // // fontSize: 12, // // fontWeight: // // FontWeight.bold, // // color: AppColors.red, // // height: 1.5) // // : Get.textTheme.headline1! // // .copyWith( // // fontSize: 12, // // fontWeight: // // FontWeight.bold, // // color: // // AppColors.primary, // // height: 1.5), // // ), // // AutoSizeText( // // 'Since last month'.tr, // // style: Get.textTheme.headline1! // // .copyWith( // // fontSize: 12, // // fontWeight: FontWeight.bold, // // color: Colors.grey.shade400, // // height: 1.5), // // ), // // ], // // ), // // ), // ], // ), ], ), ], ), ), const SizedBox(height: 16), Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ YearButton( year: '2021', onPressed: () { controller.yearName.value = 2021; controller.yearIndexValue.value = controller.storeIncome.value.yearData! .indexWhere((element) => element.yearNo.toString() == '2021'); controller.storeIncome.value.yearData! .where((element) => element.yearNo.toString() == '2021') .toList() .length > 0 ? { controller.yearName.value = 2021, controller.SelectedMonth( controller.yearName.value, controller.selectedMonthIndex.value) } : print('NO DATA'); print(controller.yearIndexValue.value); print(controller.selectedMonthIndex.value); }, colorBtn: controller.yearName == 2021 ? AppColors.lightGreen : AppColors.greyWhite, ), YearButton( year: '2022', onPressed: () { controller.yearName.value = 2022; controller.yearIndexValue.value = controller.storeIncome.value.yearData! .indexWhere((element) => element.yearNo.toString() == '2022'); controller.storeIncome.value.yearData! .where((element) => element.yearNo.toString() == '2022') .toList() .length > 0 ? { controller.yearName.value = 2022, controller.SelectedMonth( controller.yearName.value, controller.selectedMonthIndex.value), } : print('NO DATA'); print(controller.yearIndexValue.value); print(controller.selectedMonthIndex.value); }, colorBtn: controller.yearName == 2022 ? AppColors.lightGreen : AppColors.greyWhite, ), YearButton( year: '2023', onPressed: () { controller.yearName.value = 2023; controller.yearIndexValue.value = controller.storeIncome.value.yearData! .indexWhere((element) => element.yearNo.toString() == '2023'); controller.storeIncome.value.yearData! .where((element) => element.yearNo.toString() == '2023') .toList() .length > 0 ? { controller.yearName.value = 2023, controller.SelectedMonth( controller.yearName.value, (controller .storeIncome .value .monthData?[controller.selectedMonthIndex.value] .monthNo ?? controller.selectedMonthIndex.value + 1) - 1) } : print('NO DATA'); print(controller.yearIndexValue.value); print(controller.selectedMonthIndex.value); print('111111'); print(controller.storeIncome.value.yearData! .indexWhere((element) => element.yearNo.toString() == '2023')); }, colorBtn: controller.yearName == 2023 ? AppColors.lightGreen : AppColors.greyWhite, ), YearButton( year: '2024', onPressed: () { controller.yearName.value = 2024; controller.yearIndexValue.value = controller.storeIncome.value.yearData! .indexWhere((element) => element.yearNo.toString() == '2024'); controller.storeIncome.value.yearData! .where((element) => element.yearNo.toString() == '2024') .toList() .length > 0 ? { controller.yearName.value = 2024, controller.SelectedMonth( controller.yearName.value, (controller .storeIncome .value .monthData?[controller.selectedMonthIndex.value] .monthNo ?? controller.selectedMonthIndex.value + 1) - 1) } : print('NO DATA'); print(controller.yearIndexValue.value); print(controller.selectedMonthIndex.value); }, colorBtn: controller.yearName == 2024 ? AppColors.lightGreen : AppColors.greyWhite, ), ], ), const SizedBox(height: 16), Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(6), border: Border.all(color: Colors.transparent), ), child: Column( children: [ Padding( padding: const EdgeInsets.only(right: 24, left: 24, bottom: 24), child: Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(6), boxShadow: [ BoxShadow( spreadRadius: 1, blurRadius: 4, color: Colors.grey.shade200, ), ], border: Border.all(color: Colors.transparent)), child: Column( children: [ Padding( padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 10), child: Container( width: Get.width, child: Obx( () => controller.yearIndexValue.value > -1 ? Flexible( child: SfCartesianChart( // primaryXAxis: CategoryAxis(), primaryXAxis: CategoryAxis( majorGridLines: const MajorGridLines(color: Colors.transparent), ), primaryYAxis: NumericAxis( //Hide the gridlines of y-axis majorGridLines: const MajorGridLines(width: 0), //Hide the axis line of y-axis axisLine: const AxisLine(width: 0)), // Chart title // title: ChartTitle(text: 'Half yearly sales analysis'), // Enable legend legend: Legend(isVisible: true), // Enable tooltip tooltipBehavior: TooltipBehavior(enable: true), series: <ChartSeries<WeekData, String>>[ ColumnSeries<WeekData, String>( dataSource: controller.yearIndexValue.value > -1 ? controller .storeIncome .value .yearData![ controller.yearIndexValue.value] .monthdata![ controller.selectedMonthIndex.value] .weekData ?? [] : [], xValueMapper: (income, _) { return 'Week'.tr + ' ${income.weekNo ?? ''}'; }, yValueMapper: (income, _) { return income.value ?? 0; }, isVisibleInLegend: false, color: const Color(0xffB1D4C0), borderRadius: const BorderRadius.vertical( top: Radius.circular(8)), // Enable data label dataLabelSettings: const DataLabelSettings(isVisible: true)) ], ), ) : SizedBox(), ), ), ), ], ), ), ), GetBuilder<SalesIncomereportController>( builder: (controller) { return Padding( padding: const EdgeInsets.only(right: 24, left: 24, bottom: 24), child: Obx( () => controller.yearIndexValue.value > -1 ? Container( //width: Get.width, // height: Get.height * .15, child: GridView.builder( shrinkWrap: true, physics: const NeverScrollableScrollPhysics(), gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 6, crossAxisSpacing: 10.0, mainAxisSpacing: 20.0, ), scrollDirection: Axis.vertical, itemCount: controller.monthList.length, itemBuilder: (context, index) { return InkWell( onTap: () { controller.SelectedMonth( controller.yearName.value, (controller.storeIncome.value.monthData?[index] .monthNo ?? index + 1) - 1); print(controller.yearIndexValue.value); print(controller.selectedMonthIndex.value); }, // : null, child: Container( decoration: BoxDecoration( color: controller.selectedMonthIndex == index ? AppColors.primary : Colors.white, borderRadius: BorderRadius.circular(6), boxShadow: [ BoxShadow( spreadRadius: 1, blurRadius: 4, color: Colors.grey.shade200, ), ], border: controller.selectedMonthIndex == index ? Border.all(color: AppColors.primary) : Border.all(color: Colors.transparent)), child: Center( child: AutoSizeText( Get.locale.toString() == 'ar_SA' ? controller.monthList[index]['nameAr'] : controller.monthList[index]['name'], style: Get.textTheme.subtitle1!.copyWith( fontSize: Get.width * 0.03, fontWeight: FontWeight.bold, color: controller.selectedMonthIndex == index ? AppColors.white : AppColors.black), maxFontSize: 20, minFontSize: 10, ), ), ), ); }, ), ) : SizedBox(), ), ); }, ), ], ), ), ], ), )); } } class YearButton extends StatelessWidget { const YearButton({ Key? key, required this.year, required this.onPressed, required this.colorBtn, }) : super(key: key); final String year; final VoidCallback? onPressed; final Color colorBtn; @override Widget build(BuildContext context) { return Container( width: Get.width * 0.17, child: ElevatedButton( child: AutoSizeText( year, style: Get.theme.textTheme.headline6!.merge( const TextStyle( color: AppColors.black, fontWeight: FontWeight.w500, ), ), maxFontSize: 20, minFontSize: 8, ), onPressed: onPressed, style: ElevatedButton.styleFrom(padding: const EdgeInsets.all(10.0), primary: colorBtn), ), ); } }
Editor is loading...