calendar_title.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/res/colors.dart';
  3. import 'package:liftmanager/utils/utils.dart';
  4. class CalendarTile extends StatelessWidget {
  5. final VoidCallback onDateSelected;
  6. final DateTime date;
  7. final String dayOfWeek;
  8. final bool isDayOfWeek;
  9. final bool isSelected;
  10. final TextStyle dayOfWeekStyles;
  11. final TextStyle dateStyles;
  12. final Widget child;
  13. final Color weekBgColor;
  14. final Color weekTextColor;
  15. final int mtState; //0:无状态 1:待完成 2:正常 3:超期
  16. CalendarTile(
  17. {this.onDateSelected,
  18. this.date,
  19. this.child,
  20. this.dateStyles,
  21. this.dayOfWeek,
  22. this.dayOfWeekStyles,
  23. this.isDayOfWeek: false,
  24. this.isSelected: false,
  25. this.weekBgColor,
  26. this.weekTextColor,
  27. this.mtState = 0});
  28. Widget renderDateOrDayOfWeek(BuildContext context) {
  29. if (isDayOfWeek) {
  30. return new InkWell(
  31. child: new Container(
  32. height: 45,
  33. alignment: Alignment.center,
  34. child: new Text(
  35. dayOfWeek,
  36. style: dayOfWeekStyles,
  37. ),
  38. ),
  39. );
  40. } else {
  41. return new InkWell(
  42. onTap: onDateSelected,
  43. child: new Container(
  44. color: Colors.white,
  45. height: 45,
  46. alignment: Alignment.center,
  47. child: Container(
  48. width: 35,
  49. height: 35,
  50. decoration: isSelected
  51. ? BoxDecoration(
  52. shape: BoxShape.circle, color: Colours.app_main)
  53. : mtState == 1
  54. ? BoxDecoration(
  55. borderRadius: BorderRadius.circular(18),
  56. border: Border.all(
  57. color: Colours.text_gray,
  58. style: BorderStyle.solid,
  59. width: 2))
  60. : mtState == 2
  61. ? BoxDecoration(
  62. borderRadius: BorderRadius.circular(18),
  63. border: Border.all(
  64. color: Colors.yellow,
  65. style: BorderStyle.solid,
  66. width: 2))
  67. : mtState == 3
  68. ? BoxDecoration(
  69. borderRadius:
  70. BorderRadius.circular(18),
  71. border: Border.all(
  72. color: Color(0xFF9CD19E),
  73. style: BorderStyle.solid,
  74. width: 2))
  75. : mtState == 4
  76. ? BoxDecoration(
  77. borderRadius:
  78. BorderRadius.circular(18),
  79. border: Border.all(
  80. color: Colors.red,
  81. style: BorderStyle.solid,
  82. width: 2))
  83. : BoxDecoration(),
  84. alignment: Alignment.center,
  85. child: Column(
  86. mainAxisAlignment: MainAxisAlignment.center,
  87. children: <Widget>[
  88. Text(
  89. Utils.formatDay(date).toString(),
  90. style: isSelected
  91. ? new TextStyle(color: Colors.white)
  92. : dateStyles,
  93. textAlign: TextAlign.center,
  94. ),
  95. ],
  96. )),
  97. ),
  98. );
  99. }
  100. }
  101. @override
  102. Widget build(BuildContext context) {
  103. if (child != null) {
  104. return new InkWell(
  105. child: child,
  106. onTap: onDateSelected,
  107. );
  108. }
  109. return new Container(
  110. child: renderDateOrDayOfWeek(context),
  111. );
  112. }
  113. }