You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.8KB

  1. import 'package:farm_tpf/custom_model/CropPlot.dart';
  2. import 'package:farm_tpf/data/repository/repository.dart';
  3. import 'package:farm_tpf/presentation/custom_widgets/app_bar_widget.dart';
  4. import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart';
  5. import 'package:farm_tpf/presentation/screens/plot_detail/bloc/plot_detail_bloc.dart';
  6. import 'package:farm_tpf/presentation/screens/plot_detail/widget_tab.dart';
  7. import 'package:farm_tpf/utils/const_assets.dart';
  8. import 'package:farm_tpf/utils/formatter.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:flutter_bloc/flutter_bloc.dart';
  11. class PlotDetailScreen extends StatefulWidget {
  12. int? cropId;
  13. String? cropCode;
  14. int cropType;
  15. int initialIndex;
  16. PlotDetailScreen({
  17. this.cropId,
  18. this.initialIndex = 0,
  19. this.cropCode,
  20. required this.cropType,
  21. });
  22. @override
  23. _PlotDetailScreenState createState() => _PlotDetailScreenState();
  24. }
  25. class _PlotDetailScreenState extends State<PlotDetailScreen> {
  26. Widget content({String? suppliesName, String? code, required num areaM2}) {
  27. return Column(
  28. children: [
  29. Container(
  30. padding: const EdgeInsets.all(8),
  31. width: double.infinity,
  32. color: Colors.white,
  33. child: Row(
  34. children: [
  35. const SizedBox(
  36. width: 12,
  37. ),
  38. Expanded(
  39. child: Container(
  40. height: 75,
  41. child: Column(
  42. crossAxisAlignment: CrossAxisAlignment.start,
  43. mainAxisSize: MainAxisSize.min,
  44. children: [
  45. Text('${suppliesName ?? ''}', style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18)),
  46. const Expanded(
  47. child: SizedBox(),
  48. ),
  49. Text(
  50. 'Mã lô: ${code ?? ''}',
  51. style: const TextStyle(color: Colors.grey),
  52. overflow: TextOverflow.clip,
  53. ),
  54. Text('Diện tích: ${areaM2.formatNumtoStringDecimal() ?? '0'} m\u00B2', style: const TextStyle(color: Colors.grey))
  55. ],
  56. ),
  57. ),
  58. ),
  59. Image.asset(
  60. AppAssets.tempImage,
  61. width: 75,
  62. height: 75,
  63. )
  64. ],
  65. ),
  66. ),
  67. Expanded(
  68. child: HomeTabbarWidget(
  69. cropType: widget.cropType,
  70. cropId: widget.cropId,
  71. cropCode: widget.cropCode,
  72. initialIndex: widget.initialIndex,
  73. ))
  74. ],
  75. );
  76. }
  77. @override
  78. Widget build(BuildContext context) {
  79. return Scaffold(
  80. appBar: AppBarWidget(),
  81. body: BlocProvider(
  82. create: (context) => PlotDetailBloc(repository: Repository())..add(CheckInfo(cropId: widget.cropId ?? -1, cropCode: widget.cropCode ?? '')),
  83. child: BlocConsumer<PlotDetailBloc, PlotDetailState>(listener: (context, state) {
  84. if (state is PlotDetailLoading) {
  85. LoadingDialog.showLoadingDialog(context);
  86. } else if (state is PlotDetailFailure) {
  87. LoadingDialog.hideLoadingDialog(context);
  88. } else {
  89. LoadingDialog.hideLoadingDialog(context);
  90. }
  91. }, builder: (context, state) {
  92. if (state is PlotDetailSuccess) {
  93. var cropPlot = state.ownerItem as CropPlot;
  94. return content(
  95. suppliesName: cropPlot.tbCropDTO?.suppliesName ?? '', code: cropPlot.tbCropDTO?.code, areaM2: cropPlot.tbCropDTO?.areaM2 ?? 0);
  96. } else {
  97. return content(suppliesName: '', code: '', areaM2: 0);
  98. }
  99. }),
  100. ));
  101. }
  102. }