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.

73 lines
2.4KB

  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 HomeTabbarWidget(
  32. cropType: widget.cropType,
  33. cropId: widget.cropId,
  34. cropCode: widget.cropCode,
  35. initialIndex: widget.initialIndex,
  36. );
  37. }
  38. @override
  39. Widget build(BuildContext context) {
  40. return Scaffold(
  41. appBar: AppBarWidget(),
  42. body: BlocProvider(
  43. create: (context) => PlotDetailBloc(repository: Repository())
  44. ..add(
  45. CheckInfo(cropId: widget.cropId ?? -1, cropCode: widget.cropCode ?? ''),
  46. ),
  47. child: BlocConsumer<PlotDetailBloc, PlotDetailState>(listener: (context, state) {
  48. if (state is PlotDetailLoading) {
  49. LoadingDialog.showLoadingDialog(context);
  50. } else if (state is PlotDetailFailure) {
  51. LoadingDialog.hideLoadingDialog(context);
  52. } else {
  53. LoadingDialog.hideLoadingDialog(context);
  54. }
  55. }, builder: (context, state) {
  56. if (state is PlotDetailSuccess) {
  57. var cropPlot = state.ownerItem as CropPlot;
  58. return content(
  59. suppliesName: cropPlot.tbCropDTO?.suppliesName ?? '',
  60. code: cropPlot.tbCropDTO?.code,
  61. areaM2: cropPlot.tbCropDTO?.areaM2,
  62. );
  63. } else {
  64. return content(suppliesName: '', code: '', areaM2: 0);
  65. }
  66. }),
  67. ));
  68. }
  69. }