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.

116 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({
  27. String? suppliesName,
  28. String? code,
  29. num? areaM2,
  30. }) {
  31. return Column(
  32. children: [
  33. Container(
  34. padding: EdgeInsets.all(8),
  35. width: double.infinity,
  36. color: Colors.white,
  37. child: Row(
  38. children: [
  39. SizedBox(
  40. width: 12,
  41. ),
  42. Expanded(
  43. child: Container(
  44. height: 75,
  45. child: Column(
  46. crossAxisAlignment: CrossAxisAlignment.start,
  47. mainAxisSize: MainAxisSize.min,
  48. children: [
  49. Text('${suppliesName ?? ''}', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18)),
  50. Expanded(
  51. child: SizedBox(),
  52. ),
  53. Text(
  54. 'Mã lô: ${code ?? ''}',
  55. style: TextStyle(color: Colors.grey),
  56. overflow: TextOverflow.clip,
  57. ),
  58. Text('Diện tích: ${areaM2?.formatNumtoStringDecimal() ?? '0'} m\u00B2', style: TextStyle(color: Colors.grey))
  59. ],
  60. ),
  61. ),
  62. ),
  63. Image.asset(
  64. AppAssets.tempImage,
  65. width: 75,
  66. height: 75,
  67. )
  68. ],
  69. ),
  70. ),
  71. Expanded(
  72. child: HomeTabbarWidget(
  73. cropType: widget.cropType,
  74. cropId: widget.cropId,
  75. cropCode: widget.cropCode,
  76. initialIndex: widget.initialIndex,
  77. ))
  78. ],
  79. );
  80. }
  81. @override
  82. Widget build(BuildContext context) {
  83. return Scaffold(
  84. appBar: AppBarWidget(),
  85. body: BlocProvider(
  86. create: (context) => PlotDetailBloc(repository: Repository())
  87. ..add(
  88. CheckInfo(cropId: widget.cropId ?? -1, cropCode: widget.cropCode ?? ''),
  89. ),
  90. child: BlocConsumer<PlotDetailBloc, PlotDetailState>(listener: (context, state) {
  91. if (state is PlotDetailLoading) {
  92. LoadingDialog.showLoadingDialog(context);
  93. } else if (state is PlotDetailFailure) {
  94. LoadingDialog.hideLoadingDialog(context);
  95. } else {
  96. LoadingDialog.hideLoadingDialog(context);
  97. }
  98. }, builder: (context, state) {
  99. if (state is PlotDetailSuccess) {
  100. var cropPlot = state.ownerItem as CropPlot;
  101. return content(
  102. suppliesName: cropPlot.tbCropDTO?.suppliesName ?? '',
  103. code: cropPlot.tbCropDTO?.code,
  104. areaM2: cropPlot.tbCropDTO?.areaM2,
  105. );
  106. } else {
  107. return content(suppliesName: '', code: '', areaM2: 0);
  108. }
  109. }),
  110. ));
  111. }
  112. }