utils.dart 2.7 KB

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