作者:想飞的糊涂虫 | 来源:互联网 | 2023-01-30 13:44
我有一些包含表情符号的文本,我试图在“文本”小部件上显示它们。但是,它们似乎显示为外来字符。Flutter是否支持显示表情符号?应该适用于iOS和Android
1> Collin Jacks..:
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 {
String _message = '';
Future _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: [
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;
});
},
),
);
}
}