Hibok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

58 lines
1.6 KiB

  1. import 'package:extended_text_library/extended_text_library.dart';
  2. import 'package:flutter/material.dart';
  3. ///emoji/image text
  4. class EmojiText extends SpecialText {
  5. static const String flag = "[";
  6. final int start;
  7. final double emojiSize;
  8. EmojiText(TextStyle textStyle, {this.start, this.emojiSize=20.0})
  9. : super(EmojiText.flag, "]", textStyle);
  10. @override
  11. InlineSpan finishText() {
  12. var key = toString();
  13. if (EmojiUitl.instance.emojiMap.containsKey(key)) {
  14. //fontsize id define image height
  15. //size = 30.0/26.0 * fontSize
  16. final double size = emojiSize;
  17. // ScreenUtil().setWidth(emojiSize);
  18. ///fontSize 26 and text height =30.0
  19. //final double fontSize = 26.0;
  20. return ImageSpan(AssetImage(EmojiUitl.instance.emojiMap[key]),
  21. actualText: key,
  22. imageWidth: size,
  23. imageHeight: size,
  24. start: start,
  25. fit: BoxFit.contain,
  26. margin: EdgeInsets.only(left: 2.0, top: 2.0, right: 2.0));
  27. }
  28. return TextSpan(text: toString(), style: textStyle);
  29. }
  30. }
  31. class EmojiUitl { ///emoji
  32. final Map<String, String> _emojiMap = new Map<String, String>();
  33. Map<String, String> get emojiMap => _emojiMap;
  34. final String _emojiFilePath = "assets/images/emojiface";
  35. static EmojiUitl _instance;
  36. static EmojiUitl get instance {
  37. if (_instance == null) _instance = new EmojiUitl._();
  38. return _instance;
  39. }
  40. EmojiUitl._() {
  41. for (int i = 1; i < 87; i++) {
  42. _emojiMap[EmojiText.flag+"$i]"] = "$_emojiFilePath/$i.png";
  43. }
  44. }
  45. }