exam_card.dart 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import 'package:flutter/material.dart';
  2. import 'package:vitalapp/consts/styles.dart';
  3. /// 检查小卡片
  4. class ExamCard extends StatelessWidget {
  5. const ExamCard({
  6. super.key,
  7. this.title,
  8. required this.content,
  9. this.clickCard,
  10. this.titleText,
  11. this.topPadding = 20,
  12. this.bottomPadding = 15,
  13. this.isSelect = false,
  14. this.color = Colors.white,
  15. this.required,
  16. });
  17. final String? title;
  18. final Widget content;
  19. final Widget? titleText;
  20. final Function? clickCard;
  21. final double topPadding;
  22. final double bottomPadding;
  23. final bool isSelect;
  24. final Color color;
  25. final bool? required;
  26. @override
  27. Widget build(BuildContext context) {
  28. return Card(
  29. elevation: 6,
  30. shape: RoundedRectangleBorder(
  31. borderRadius: GlobalStyles.borderRadius,
  32. ),
  33. child: Material(
  34. color: color,
  35. borderRadius: GlobalStyles.borderRadius,
  36. child: InkWell(
  37. borderRadius: GlobalStyles.borderRadius,
  38. onTap: clickCard != null ? () => clickCard!.call() : null,
  39. child: _buildTitle(),
  40. ),
  41. ),
  42. );
  43. }
  44. Widget _buildTitle() {
  45. Widget titleContent = const SizedBox();
  46. if (title?.isNotEmpty ?? false) {
  47. titleContent = RichText(
  48. text: TextSpan(
  49. text: '',
  50. children: [
  51. if (required ?? false)
  52. TextSpan(
  53. text: "* ",
  54. style: const TextStyle(color: Colors.red, fontSize: 35),
  55. ),
  56. TextSpan(
  57. text: title ?? '',
  58. style: TextStyle(
  59. fontSize: 26,
  60. color: Colors.black,
  61. fontFamily: "NotoSansSC",
  62. fontFamilyFallback: const ["NotoSansSC"],
  63. ),
  64. ),
  65. ],
  66. ),
  67. );
  68. }
  69. return titleText ??
  70. Container(
  71. padding: EdgeInsets.only(
  72. top: topPadding,
  73. left: 30,
  74. bottom: bottomPadding,
  75. ),
  76. child: Row(
  77. mainAxisAlignment: MainAxisAlignment.center,
  78. crossAxisAlignment: CrossAxisAlignment.center,
  79. children: [
  80. titleContent,
  81. Expanded(child: content),
  82. ],
  83. ),
  84. );
  85. }
  86. }
  87. /// 检查小卡片
  88. class ExamCard2 extends StatelessWidget {
  89. const ExamCard2({
  90. super.key,
  91. this.title,
  92. required this.content,
  93. this.clickCard,
  94. this.titleText,
  95. this.topPadding = 20,
  96. this.isSelect = false,
  97. });
  98. final String? title;
  99. final Widget content;
  100. final Widget? titleText;
  101. final Function? clickCard;
  102. final double topPadding;
  103. final bool isSelect;
  104. @override
  105. Widget build(BuildContext context) {
  106. return Card(
  107. elevation: 6,
  108. shape: RoundedRectangleBorder(
  109. borderRadius: GlobalStyles.borderRadius,
  110. ),
  111. child: Material(
  112. color: Colors.white,
  113. borderRadius: GlobalStyles.borderRadius,
  114. child: InkWell(
  115. borderRadius: GlobalStyles.borderRadius,
  116. onTap: clickCard != null ? () => clickCard!.call() : null,
  117. child: _buildTitle(),
  118. ),
  119. ),
  120. );
  121. }
  122. Widget _buildTitle() {
  123. // Widget titleContent = const SizedBox();
  124. // if (title?.isNotEmpty ?? false) {
  125. // titleContent = Text(
  126. // title!,
  127. // style: const TextStyle(fontSize: 26),
  128. // );
  129. // }
  130. return titleText ??
  131. Container(
  132. padding: EdgeInsets.only(
  133. top: topPadding,
  134. left: 30,
  135. bottom: 15,
  136. ),
  137. child: Row(
  138. mainAxisAlignment: MainAxisAlignment.center,
  139. crossAxisAlignment: CrossAxisAlignment.start,
  140. children: [
  141. Expanded(child: content),
  142. ],
  143. ),
  144. );
  145. }
  146. }