click_item.dart 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/res/resources.dart';
  3. import 'package:liftmanager/utils/theme_utils.dart';
  4. class ClickItem extends StatelessWidget {
  5. const ClickItem({
  6. Key key,
  7. this.onTap,
  8. @required this.title,
  9. this.content: "",
  10. this.hintText:"",
  11. this.isMust:false,
  12. this.textAlign: TextAlign.start,
  13. this.maxLines: 1,
  14. this.hideDiv:false
  15. }): super(key: key);
  16. final Function onTap;
  17. final String title;
  18. final String content;
  19. final String hintText;
  20. final bool isMust;
  21. final TextAlign textAlign;
  22. final int maxLines;
  23. final bool hideDiv;
  24. @override
  25. Widget build(BuildContext context) {
  26. bool isDark = ThemeUtils.isDark(context);
  27. return InkWell(
  28. onTap: onTap,
  29. child: Container(
  30. padding: const EdgeInsets.fromLTRB(15, 15.0, 15.0, 15.0),
  31. constraints: BoxConstraints(
  32. maxHeight: double.infinity,
  33. minHeight: 50.0
  34. ),
  35. width: double.infinity,
  36. decoration: BoxDecoration(
  37. color: isDark?Colors.black:Colors.white,
  38. border: this.hideDiv?Border():Border(
  39. bottom: Divider.createBorderSide(context, width: 0.6),
  40. )
  41. ),
  42. child: Row(
  43. //为了数字类文字居中
  44. crossAxisAlignment: maxLines == 1 ? CrossAxisAlignment.center : CrossAxisAlignment.start,
  45. children: <Widget>[
  46. Padding(
  47. padding: const EdgeInsets.only(right: 5.0),
  48. child: Text(title),
  49. ),
  50. Offstage(
  51. offstage: !this.isMust,
  52. child: Text("*",style: TextStyle(color: Colors.red),),
  53. ),
  54. const Spacer(),
  55. Expanded(
  56. flex: 4,
  57. child: Padding(
  58. padding: const EdgeInsets.only(right: 8.0, left: 16.0),
  59. child: Text(
  60. (content == null || content.length==0)?hintText:content,
  61. maxLines: maxLines,
  62. textAlign: maxLines == 1 ? TextAlign.right : textAlign,
  63. overflow: maxLines==1?TextOverflow.ellipsis:TextOverflow.visible,
  64. style: Theme.of(context).textTheme.subtitle.copyWith(fontSize: Dimens.font_sp14))
  65. // style: TextStyle(fontSize: 14,color: content.length==0?Colours.text_gray_c:Colors.black))
  66. ),
  67. ),
  68. Offstage(
  69. offstage: onTap == null ? true:false,
  70. child: Opacity(
  71. // 无点击事件时,隐藏箭头图标
  72. opacity: onTap == null ? 0 : 1,
  73. child: Padding(
  74. padding: EdgeInsets.only(top: maxLines == 1 ? 0.0 : 2.0),
  75. child: Images.arrowRight,
  76. ),
  77. )
  78. )
  79. ],
  80. ),
  81. ),
  82. );
  83. }
  84. }