| 
									
										
										
										
											2023-11-22 10:49:22 +08:00
										 |  |  | import 'dart:io'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import 'package:flowy_infra_ui/flowy_infra_ui.dart'; | 
					
						
							|  |  |  | import 'package:flutter/material.dart'; | 
					
						
							|  |  |  | import 'package:google_fonts/google_fonts.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // used to prevent loading font from google fonts every time
 | 
					
						
							|  |  |  | List<String>? _cachedFallbackFontFamily; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Some emojis are not supported by the default font on Android or Linux, fallback to noto color emoji
 | 
					
						
							|  |  |  | class EmojiText extends StatelessWidget { | 
					
						
							|  |  |  |   const EmojiText({ | 
					
						
							|  |  |  |     super.key, | 
					
						
							|  |  |  |     required this.emoji, | 
					
						
							|  |  |  |     required this.fontSize, | 
					
						
							|  |  |  |     this.textAlign, | 
					
						
							| 
									
										
										
										
											2023-12-10 13:44:37 +02:00
										 |  |  |     this.lineHeight, | 
					
						
							| 
									
										
										
										
											2023-11-22 10:49:22 +08:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   final String emoji; | 
					
						
							|  |  |  |   final double fontSize; | 
					
						
							|  |  |  |   final TextAlign? textAlign; | 
					
						
							| 
									
										
										
										
											2023-12-10 13:44:37 +02:00
										 |  |  |   final double? lineHeight; | 
					
						
							| 
									
										
										
										
											2023-11-22 10:49:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     _loadFallbackFontFamily(); | 
					
						
							|  |  |  |     return FlowyText( | 
					
						
							|  |  |  |       emoji, | 
					
						
							|  |  |  |       fontSize: fontSize, | 
					
						
							|  |  |  |       textAlign: textAlign, | 
					
						
							|  |  |  |       fallbackFontFamily: _cachedFallbackFontFamily, | 
					
						
							| 
									
										
										
										
											2023-12-10 13:44:37 +02:00
										 |  |  |       lineHeight: lineHeight, | 
					
						
							| 
									
										
										
										
											2023-11-22 10:49:22 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void _loadFallbackFontFamily() { | 
					
						
							|  |  |  |     if (Platform.isLinux || Platform.isAndroid) { | 
					
						
							|  |  |  |       final notoColorEmoji = GoogleFonts.notoColorEmoji().fontFamily; | 
					
						
							|  |  |  |       if (notoColorEmoji != null) { | 
					
						
							|  |  |  |         _cachedFallbackFontFamily = [notoColorEmoji]; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |