utils.dart 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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,
  17. {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(
  38. BuildContext context,
  39. ContactInfo model, {
  40. double susHeight = 40,
  41. Color? defHeaderBgColor,
  42. }) {
  43. return getWeChatItem(context, model, defHeaderBgColor: defHeaderBgColor);
  44. // return Column(
  45. // mainAxisSize: MainAxisSize.min,
  46. // children: <Widget>[
  47. // Offstage(
  48. // offstage: !(model.isShowSuspension == true),
  49. // child: getSusItem(context, model.getSuspensionTag(),
  50. // susHeight: susHeight),
  51. // ),
  52. // getWeChatItem(context, model, defHeaderBgColor: defHeaderBgColor),
  53. // ],
  54. // );
  55. }
  56. static Widget getWeChatItem(
  57. BuildContext context,
  58. ContactInfo model, {
  59. Color? defHeaderBgColor,
  60. }) {
  61. DecorationImage? image;
  62. // if (model.img != null && model.img.isNotEmpty) {
  63. // image = DecorationImage(
  64. // image: CachedNetworkImageProvider(model.img),
  65. // fit: BoxFit.contain,
  66. // );
  67. // }
  68. return ListTile(
  69. leading: Container(
  70. width: 36,
  71. height: 36,
  72. decoration: BoxDecoration(
  73. shape: BoxShape.rectangle,
  74. borderRadius: BorderRadius.circular(4.0),
  75. color: model.bgColor ?? defHeaderBgColor,
  76. image: image,
  77. ),
  78. child: model.iconData == null
  79. ? null
  80. : Icon(
  81. model.iconData,
  82. color: Colors.white,
  83. size: 20,
  84. ),
  85. ),
  86. title: Text(model.name),
  87. onTap: () {
  88. LogUtil.e("onItemClick : $model");
  89. Utils.showSnackBar(context, 'onItemClick : ${model.name}');
  90. },
  91. );
  92. }
  93. }