|
|
|
@@ -1,91 +1,117 @@ |
|
|
|
import 'package:farm_tpf/custom_model/CropPlot.dart'; |
|
|
|
import 'package:farm_tpf/data/repository/repository.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/app_bar_widget.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/plot_detail/bloc/plot_detail_bloc.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/plot_detail/widget_tab.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_assets.dart'; |
|
|
|
import 'package:farm_tpf/utils/formatter.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart'; |
|
|
|
|
|
|
|
class PlotDetailScreen extends StatefulWidget { |
|
|
|
int cropId; |
|
|
|
String cropCode; |
|
|
|
int cropType; |
|
|
|
int initialIndex; |
|
|
|
String code; |
|
|
|
num areaM2; |
|
|
|
String suppliesName; |
|
|
|
PlotDetailScreen( |
|
|
|
{this.cropId, |
|
|
|
this.initialIndex = 0, |
|
|
|
this.cropCode, |
|
|
|
@required this.cropType, |
|
|
|
@required this.code, |
|
|
|
@required this.areaM2, |
|
|
|
@required this.suppliesName}); |
|
|
|
PlotDetailScreen({ |
|
|
|
this.cropId, |
|
|
|
this.initialIndex = 0, |
|
|
|
this.cropCode, |
|
|
|
@required this.cropType, |
|
|
|
}); |
|
|
|
@override |
|
|
|
_PlotDetailScreenState createState() => _PlotDetailScreenState(); |
|
|
|
} |
|
|
|
|
|
|
|
class _PlotDetailScreenState extends State<PlotDetailScreen> { |
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
return Scaffold( |
|
|
|
appBar: AppBarWidget(), |
|
|
|
body: Column( |
|
|
|
children: [ |
|
|
|
Container( |
|
|
|
padding: EdgeInsets.all(8), |
|
|
|
width: double.infinity, |
|
|
|
color: Colors.white, |
|
|
|
child: Row( |
|
|
|
children: [ |
|
|
|
SizedBox( |
|
|
|
width: 12, |
|
|
|
), |
|
|
|
Expanded( |
|
|
|
child: Container( |
|
|
|
height: 75, |
|
|
|
child: Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
children: [ |
|
|
|
Text('${widget.suppliesName ?? ''}', |
|
|
|
style: TextStyle( |
|
|
|
fontWeight: FontWeight.bold, fontSize: 18)), |
|
|
|
Expanded( |
|
|
|
child: SizedBox(), |
|
|
|
), |
|
|
|
Row( |
|
|
|
children: [ |
|
|
|
Text('Mã lô: ${widget.code ?? ''}', |
|
|
|
style: TextStyle(color: Colors.grey)), |
|
|
|
SizedBox( |
|
|
|
width: 16, |
|
|
|
), |
|
|
|
Text( |
|
|
|
'Diện tích: ${widget.areaM2.formatNumtoStringDecimal() ?? '0'} m\u00B2', |
|
|
|
style: TextStyle(color: Colors.grey)) |
|
|
|
], |
|
|
|
) |
|
|
|
], |
|
|
|
), |
|
|
|
Widget content({String suppliesName, String code, num areaM2}) { |
|
|
|
return Column( |
|
|
|
children: [ |
|
|
|
Container( |
|
|
|
padding: EdgeInsets.all(8), |
|
|
|
width: double.infinity, |
|
|
|
color: Colors.white, |
|
|
|
child: Row( |
|
|
|
children: [ |
|
|
|
SizedBox( |
|
|
|
width: 12, |
|
|
|
), |
|
|
|
Expanded( |
|
|
|
child: Container( |
|
|
|
height: 75, |
|
|
|
child: Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
children: [ |
|
|
|
Text('${suppliesName ?? ''}', |
|
|
|
style: TextStyle( |
|
|
|
fontWeight: FontWeight.bold, fontSize: 18)), |
|
|
|
Expanded( |
|
|
|
child: SizedBox(), |
|
|
|
), |
|
|
|
Row( |
|
|
|
children: [ |
|
|
|
Text('Mã lô: ${code ?? ''}', |
|
|
|
style: TextStyle(color: Colors.grey)), |
|
|
|
SizedBox( |
|
|
|
width: 16, |
|
|
|
), |
|
|
|
Text( |
|
|
|
'Diện tích: ${areaM2.formatNumtoStringDecimal() ?? '0'} m\u00B2', |
|
|
|
style: TextStyle(color: Colors.grey)) |
|
|
|
], |
|
|
|
) |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
Image.asset( |
|
|
|
AppAssets.tempImage, |
|
|
|
width: 75, |
|
|
|
height: 75, |
|
|
|
) |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
Image.asset( |
|
|
|
AppAssets.tempImage, |
|
|
|
width: 75, |
|
|
|
height: 75, |
|
|
|
) |
|
|
|
], |
|
|
|
), |
|
|
|
Expanded( |
|
|
|
child: HomeTabbarWidget( |
|
|
|
cropType: widget.cropType, |
|
|
|
cropId: widget.cropId, |
|
|
|
cropCode: widget.cropCode, |
|
|
|
initialIndex: widget.initialIndex, |
|
|
|
)) |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
Expanded( |
|
|
|
child: HomeTabbarWidget( |
|
|
|
cropType: widget.cropType, |
|
|
|
cropId: widget.cropId, |
|
|
|
cropCode: widget.cropCode, |
|
|
|
initialIndex: widget.initialIndex, |
|
|
|
)) |
|
|
|
], |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
return Scaffold( |
|
|
|
appBar: AppBarWidget(), |
|
|
|
body: BlocProvider( |
|
|
|
create: (context) => PlotDetailBloc(repository: Repository()) |
|
|
|
..add(CheckInfo(cropId: widget.cropId, cropCode: widget.cropCode)), |
|
|
|
child: BlocConsumer<PlotDetailBloc, PlotDetailState>( |
|
|
|
listener: (context, state) { |
|
|
|
if (state is PlotDetailLoading) { |
|
|
|
LoadingDialog.showLoadingDialog(context); |
|
|
|
} else if (state is PlotDetailFailure) { |
|
|
|
LoadingDialog.hideLoadingDialog(context); |
|
|
|
} else { |
|
|
|
LoadingDialog.hideLoadingDialog(context); |
|
|
|
} |
|
|
|
}, builder: (context, state) { |
|
|
|
if (state is PlotDetailSuccess) { |
|
|
|
var cropPlot = state.ownerItem as CropPlot; |
|
|
|
return content( |
|
|
|
suppliesName: cropPlot.tbCropDTO.suppliesName, |
|
|
|
code: cropPlot.tbCropDTO.code, |
|
|
|
areaM2: cropPlot.tbCropDTO.areaM2); |
|
|
|
} else { |
|
|
|
return content(suppliesName: '', code: '', areaM2: 0); |
|
|
|
} |
|
|
|
}), |
|
|
|
)); |
|
|
|
} |
|
|
|
} |