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.

118 lines
4.0KB

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