utils.dart 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import 'package:e2ee_chat/model/contact_info.dart';
  2. import 'package:e2ee_chat/presenter/contact_list.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:common_utils/common_utils.dart';
  5. class Utils {
  6. static String getImgPath(String name, {String format: 'png'}) {
  7. return 'assets/images/$name.$format';
  8. }
  9. static void showSnackBar(BuildContext context, String msg) {
  10. ScaffoldMessenger.of(context).showSnackBar(
  11. SnackBar(
  12. content: Text(msg),
  13. duration: Duration(seconds: 2),
  14. ),
  15. );
  16. }
  17. static Widget getSusItem(BuildContext context, String tag,
  18. {double susHeight = 40}) {
  19. if (tag == '★') {
  20. tag = '★ 热门城市';
  21. }
  22. return Container(
  23. height: susHeight,
  24. width: MediaQuery.of(context).size.width,
  25. padding: EdgeInsets.only(left: 16.0),
  26. color: Color(0xFFF3F4F5),
  27. alignment: Alignment.centerLeft,
  28. child: Text(
  29. '$tag',
  30. softWrap: false,
  31. style: TextStyle(
  32. fontSize: 14.0,
  33. color: Color(0xFF666666),
  34. ),
  35. ),
  36. );
  37. }
  38. static Widget getWeChatListItem(BuildContext context, ContactInfo model,
  39. {double susHeight = 40,
  40. Color? defHeaderBgColor,
  41. void Function()? onTap,
  42. void Function()? onLongPress}) {
  43. return getWeChatItem(context, model,
  44. defHeaderBgColor: defHeaderBgColor,
  45. onTap: onTap,
  46. onLongPress: onLongPress);
  47. // return Column(
  48. // mainAxisSize: MainAxisSize.min,
  49. // children: <Widget>[
  50. // Offstage(
  51. // offstage: !(model.isShowSuspension == true),
  52. // child: getSusItem(context, model.getSuspensionTag(),
  53. // susHeight: susHeight),
  54. // ),
  55. // getWeChatItem(context, model, defHeaderBgColor: defHeaderBgColor),
  56. // ],
  57. // );
  58. }
  59. static Widget getWeChatItem(BuildContext context, ContactInfo model,
  60. {Color? defHeaderBgColor,
  61. void Function()? onTap,
  62. void Function()? onLongPress}) {
  63. DecorationImage? image;
  64. // if (model.img != null && model.img.isNotEmpty) {
  65. // image = DecorationImage(
  66. // image: CachedNetworkImageProvider(model.img),
  67. // fit: BoxFit.contain,
  68. // );
  69. // }
  70. void _onTap() {
  71. LogUtil.e("onItemClick : $model");
  72. Utils.showSnackBar(context, 'onItemClick : ${model.name}');
  73. }
  74. return ListTile(
  75. leading: Container(
  76. width: 36,
  77. height: 36,
  78. decoration: BoxDecoration(
  79. shape: BoxShape.rectangle,
  80. borderRadius: BorderRadius.circular(4.0),
  81. color: model.bgColor ?? defHeaderBgColor,
  82. image: image,
  83. ),
  84. child: model.iconData == null
  85. ? null
  86. : Icon(
  87. model.iconData,
  88. color: Colors.white,
  89. size: 20,
  90. ),
  91. ),
  92. title: Text(model.name),
  93. onTap: onTap ?? _onTap,
  94. onLongPress: onLongPress,
  95. );
  96. }
  97. }