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.

95 lines
2.8KB

  1. // ignore_for_file: public_member_api_docs, sort_constructors_first
  2. import 'package:farm_tpf/presentation/custom_widgets/checkbox/checkbox_widget.dart';
  3. import 'package:farm_tpf/utils/helpers.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:farm_tpf/presentation/screens/codes/models/stamp.dart';
  6. import '../../../../themes/app_colors.dart';
  7. import '../../../../themes/styles_text.dart';
  8. import 'package:farm_tpf/utils/formatter.dart';
  9. import '../models/task.dart';
  10. class ItemTask extends StatelessWidget {
  11. final Task item;
  12. final Function onPressed;
  13. final Function(bool) onChangedStatus;
  14. ItemTask({
  15. Key? key,
  16. required this.item,
  17. required this.onPressed,
  18. required this.onChangedStatus,
  19. }) : super(key: key);
  20. @override
  21. Widget build(BuildContext context) {
  22. var dueDate = item.dueDate?.format_DDMMYY().toString() ?? '';
  23. var completedDate = item.executeDate?.format_DDMMYY().toString() ?? '';
  24. var backgroundColor = Colors.white;
  25. if (item.isCompleted ?? false) {
  26. backgroundColor = AppColors.primary1.withOpacity(0.3);
  27. } else {
  28. var dueDateCompare = item.dueDate?.convertStringServerDateTimeToLocalDateTime() ?? DateTime.now();
  29. if (Helpers.isAfterToday(dueDateCompare)) {
  30. backgroundColor = Colors.white;
  31. } else {
  32. backgroundColor = AppColors.semantic6;
  33. }
  34. }
  35. return GestureDetector(
  36. onTap: () {
  37. onPressed();
  38. },
  39. child: Container(
  40. padding: EdgeInsets.all(8),
  41. margin: EdgeInsets.symmetric(vertical: 4, horizontal: 8),
  42. decoration: BoxDecoration(
  43. borderRadius: BorderRadius.circular(10),
  44. border: Border.all(
  45. color: Colors.grey.shade200,
  46. width: 1,
  47. ),
  48. color: backgroundColor,
  49. ),
  50. child: Row(
  51. children: [
  52. Expanded(
  53. child: Column(
  54. crossAxisAlignment: CrossAxisAlignment.start,
  55. children: [
  56. Text(
  57. '${item.title ?? ''}',
  58. style: StylesText.body4,
  59. ),
  60. const SizedBox(
  61. height: 4,
  62. ),
  63. Text(
  64. 'Hạn chót: $dueDate',
  65. style: StylesText.body6,
  66. ),
  67. const SizedBox(
  68. height: 4,
  69. ),
  70. Text(
  71. 'Hoàn thành: $completedDate',
  72. style: StylesText.body6,
  73. ),
  74. ],
  75. ),
  76. ),
  77. CheckboxWidget(
  78. title: '',
  79. isChecked: item.isCompleted ?? false,
  80. onChange: (val) {
  81. onChangedStatus(val);
  82. },
  83. )
  84. ],
  85. ),
  86. ),
  87. );
  88. }
  89. }