utils.dart 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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, {double susHeight = 40}) {
  18. if (tag == '★') {
  19. tag = '★ 热门城市';
  20. }
  21. return Container(
  22. height: susHeight,
  23. width: MediaQuery.of(context).size.width,
  24. padding: EdgeInsets.only(left: 16.0),
  25. color: Color(0xFFF3F4F5),
  26. alignment: Alignment.centerLeft,
  27. child: Text(
  28. '$tag',
  29. softWrap: false,
  30. style: TextStyle(
  31. fontSize: 14.0,
  32. color: Color(0xFF666666),
  33. ),
  34. ),
  35. );
  36. }
  37. static Widget getWeChatListItem(BuildContext context, ContactInfo model,
  38. {double susHeight = 40, Color? defHeaderBgColor, void Function()? onTap}) {
  39. return getWeChatItem(context, model, defHeaderBgColor: defHeaderBgColor, onTap: onTap);
  40. // return Column(
  41. // mainAxisSize: MainAxisSize.min,
  42. // children: <Widget>[
  43. // Offstage(
  44. // offstage: !(model.isShowSuspension == true),
  45. // child: getSusItem(context, model.getSuspensionTag(),
  46. // susHeight: susHeight),
  47. // ),
  48. // getWeChatItem(context, model, defHeaderBgColor: defHeaderBgColor),
  49. // ],
  50. // );
  51. }
  52. static Widget getWeChatItem(BuildContext context, ContactInfo model,
  53. {Color? defHeaderBgColor, void Function()? onTap}) {
  54. DecorationImage? image;
  55. // if (model.img != null && model.img.isNotEmpty) {
  56. // image = DecorationImage(
  57. // image: CachedNetworkImageProvider(model.img),
  58. // fit: BoxFit.contain,
  59. // );
  60. // }
  61. void _onTap () {
  62. LogUtil.e("onItemClick : $model");
  63. Utils.showSnackBar(context, 'onItemClick : ${model.name}');
  64. }
  65. return ListTile(
  66. leading: Container(
  67. width: 36,
  68. height: 36,
  69. decoration: BoxDecoration(
  70. shape: BoxShape.rectangle,
  71. borderRadius: BorderRadius.circular(4.0),
  72. color: model.bgColor ?? defHeaderBgColor,
  73. image: image,
  74. ),
  75. child: model.iconData == null
  76. ? null
  77. : Icon(
  78. model.iconData,
  79. color: Colors.white,
  80. size: 20,
  81. ),
  82. ),
  83. title: Text(model.name),
  84. onTap: onTap ?? _onTap,
  85. );
  86. }
  87. }