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.

114 lines
3.9KB

  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. Text(
  52. 'Mã lô: ${code ?? ''}',
  53. style: TextStyle(color: Colors.grey),
  54. overflow: TextOverflow.clip,
  55. ),
  56. Text(
  57. 'Diện tích: ${areaM2.formatNumtoStringDecimal() ?? '0'} m\u00B2',
  58. 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(CheckInfo(cropId: widget.cropId, cropCode: widget.cropCode)),
  88. child: BlocConsumer<PlotDetailBloc, PlotDetailState>(
  89. listener: (context, state) {
  90. if (state is PlotDetailLoading) {
  91. LoadingDialog.showLoadingDialog(context);
  92. } else if (state is PlotDetailFailure) {
  93. LoadingDialog.hideLoadingDialog(context);
  94. } else {
  95. LoadingDialog.hideLoadingDialog(context);
  96. }
  97. }, builder: (context, state) {
  98. if (state is PlotDetailSuccess) {
  99. var cropPlot = state.ownerItem as CropPlot;
  100. return content(
  101. suppliesName: cropPlot.tbCropDTO.suppliesName,
  102. code: cropPlot.tbCropDTO.code,
  103. areaM2: cropPlot.tbCropDTO.areaM2);
  104. } else {
  105. return content(suppliesName: '', code: '', areaM2: 0);
  106. }
  107. }),
  108. ));
  109. }
  110. }