click_item.dart 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/res/resources.dart';
  3. import 'package:liftmanager/widgets/load_image.dart';
  4. import 'package:liftmanager/utils/theme_utils.dart';
  5. class ClickItem extends StatelessWidget {
  6. const ClickItem({
  7. Key key,
  8. this.onTap,
  9. @required this.title,
  10. this.content: "",
  11. this.hintText: "",
  12. this.isMust: false,
  13. this.textAlign: TextAlign.start,
  14. this.maxLines: 1,
  15. this.hideDiv: false,
  16. this.hasPic,
  17. this.hasPicRight,
  18. this.titleColor = 0,
  19. }) : super(key: key);
  20. final Function onTap;
  21. final String title;
  22. final String content;
  23. final String hintText;
  24. final bool isMust;
  25. final String hasPic;
  26. final String hasPicRight;
  27. final TextAlign textAlign;
  28. final int maxLines;
  29. final int titleColor;
  30. final bool hideDiv;
  31. @override
  32. Widget build(BuildContext context) {
  33. return InkWell(
  34. onTap: onTap,
  35. child: Container(
  36. padding: const EdgeInsets.fromLTRB(15, 10.0, 15.0, 10.0),
  37. constraints:
  38. BoxConstraints(maxHeight: double.infinity, minHeight: 50.0),
  39. width: double.infinity,
  40. decoration: BoxDecoration(
  41. color: ThemeUtils.getTabsBg(context),
  42. border: this.hideDiv
  43. ? Border()
  44. : Border(
  45. bottom: Divider.createBorderSide(context, width: 0.6),
  46. )),
  47. child: Row(
  48. //为了数字类文字居中
  49. crossAxisAlignment: maxLines == 1
  50. ? CrossAxisAlignment.center
  51. : CrossAxisAlignment.start,
  52. children: <Widget>[
  53. Row(
  54. crossAxisAlignment: CrossAxisAlignment.center,
  55. children: <Widget>[
  56. hasPic != null && hasPic.isNotEmpty
  57. ? Container(
  58. padding: EdgeInsets.only(right: 10),
  59. child: ClipRRect(
  60. borderRadius: BorderRadius.circular(15),
  61. child: Container(
  62. width: 30,
  63. height: 30,
  64. color: Color(0xffFAF7FA),
  65. // padding: EdgeInsets.all(2),
  66. child: LoadAssetImage(
  67. hasPic,
  68. // fit: BoxFit.cover,
  69. // width: 100,
  70. // height: 100,
  71. ),
  72. ),
  73. ),
  74. )
  75. : Container(),
  76. Padding(
  77. padding: const EdgeInsets.only(right: 5.0),
  78. child: titleColor == 0
  79. ? Text(title)
  80. : Text(
  81. title,
  82. style: TextStyle(
  83. color: Color(titleColor),
  84. ),
  85. textAlign: TextAlign.start,
  86. ),
  87. ),
  88. ],
  89. ),
  90. Offstage(
  91. offstage: !this.isMust,
  92. child: Text(
  93. "*",
  94. style: TextStyle(color: Colors.red),
  95. ),
  96. ),
  97. const Spacer(),
  98. hasPicRight != null && hasPicRight.isNotEmpty
  99. ? Container(
  100. padding: EdgeInsets.only(right: 10),
  101. child: ClipRRect(
  102. borderRadius: BorderRadius.circular(15),
  103. child: Container(
  104. width: 50,
  105. height: 50,
  106. color: Color(0xffFAF7FA),
  107. // padding: EdgeInsets.all(2),
  108. child: LoadNetworkImage(
  109. hasPicRight,
  110. fit: BoxFit.cover,
  111. // width: 100,
  112. // height: 100,
  113. ),
  114. ),
  115. ),
  116. )
  117. : Expanded(
  118. flex: 4,
  119. child: Padding(
  120. padding: const EdgeInsets.only(right: 8.0, left: 16.0),
  121. child: Text(content.length == 0 ? hintText : content,
  122. maxLines: maxLines,
  123. textAlign:
  124. maxLines == 1 ? TextAlign.right : textAlign,
  125. overflow: maxLines == 1
  126. ? TextOverflow.ellipsis
  127. : TextOverflow.visible,
  128. style: TextStyle(
  129. fontSize: 14,
  130. color: content.length == 0
  131. ? Colours.text_gray_c
  132. : Color(0xffcccccc)))),
  133. ),
  134. Offstage(
  135. offstage: onTap == null ? true : false,
  136. child: Opacity(
  137. // 无点击事件时,隐藏箭头图标
  138. opacity: onTap == null ? 0 : 1,
  139. child: Padding(
  140. padding: EdgeInsets.only(top: maxLines == 1 ? 0.0 : 2.0),
  141. child: Images.arrowRight,
  142. ),
  143. ))
  144. ],
  145. ),
  146. ),
  147. );
  148. }
  149. }