2017-07-05 179 views
1

我有一些文字包含emojis,我正試圖在Text小部件上顯示它們。但是,它們似乎被顯示爲外來字符。 Flutter支持顯示emojis嗎?應該適用於iOS和Android用Emojis在Flutter上顯示文字

回答

2

Flutter支持表情符號。以下是一些演示表情符號文本輸入的代碼。 (如果您看到外來字符,很可能是您將字節解碼爲ASCII而不是UTF-8;如果您使用演示問題的代碼更新問題,我們可以向您展示如何解決此問題。)

import 'dart:async'; 
import 'package:flutter/material.dart'; 

void main() { 
    runApp(new MyApp()); 
} 

class MyApp extends StatelessWidget { 
    @override 
    Widget build(BuildContext context) { 
    return new MaterialApp(
     title: 'Flutter Demo', 
     home: new MyHomePage(), 
    ); 
    } 
} 

class MyHomePage extends StatefulWidget { 
    MyHomePage({Key key}) : super(key: key); 

    @override 
    _MyHomePageState createState() => new _MyHomePageState(); 
} 

class _MyHomePageState extends State<MyHomePage> { 
    String _message = ''; 

    Future<String> _promptForString(String label, { String hintText }) { 
    final TextEditingController controller = new TextEditingController(); 
    return showDialog(
     context: context, 
     child: new AlertDialog(
     title: new Text(label), 
     content: new TextFormField(
      controller: controller, 
      decoration: new InputDecoration(hintText: hintText), 
     ), 
     actions: <Widget>[ 
      new FlatButton(
      onPressed:() => Navigator.pop(context), 
      child: const Text('CANCEL'), 
     ), 
      new FlatButton(
      onPressed:() => Navigator.pop(context, controller.text), 
      child: const Text('OK'), 
     ), 
     ], 
    ), 
    ); 
    } 

    @override 
    Widget build(BuildContext context) { 
    return new Scaffold(
     appBar: new AppBar(
     title: new Text(_message), 
    ), 
     body: new Center(
     child: new Text(_message, style: Theme.of(context).textTheme.display2), 
    ), 
     floatingActionButton: new FloatingActionButton(
     child: new Icon(Icons.edit), 
     onPressed:() async { 
      String message = await _promptForString('New text', hintText: 'Try emoji!'); 
      if (!mounted) 
      return; 
      setState(() { 
      _message = message; 
      }); 
     }, 
    ), 
    ); 
    } 
} 
+0

有沒有一種方法來顯示一個專門的表情符號屏幕在顫動?我不是指集成在鍵盤上的Emojis。 –