click_item.dart 5.8 KB

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