【问题标题】:How to open emoji keyboard in flutter如何在颤动中打开表情符号键盘
【发布时间】:2020-02-09 13:25:58
【问题描述】:

我正在创建一个聊天应用程序,我想在用户单击表情符号图标时打开表情符号键盘,它将打开表情符号键盘。这是图片,我想通过单击左侧表情符号图标打开表情符号键盘。

【问题讨论】:

  • 不是默认方式,但可以尝试一下。工作正常pub.dev/packages/emoji_picker#-readme-tab-
  • 是的,我已经尝试过这个 emoji_picker,但是当我点击图标并关闭按下图标时它不会弹出。所以请告诉我您是否有其他解决方案。
  • 是的,我今天会更新你。
  • 当我在安卓键盘上按住回车键时,会出现表情符号键盘。所以我想把钥匙改成表情符号脸而不是key。

标签: flutter keyboard flutter-layout emoji flutter-dependencies


【解决方案1】:

使用Emoji Picker,下面是完整的例子

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

void main() => runApp(MainApp());

class MainApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Test",
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: Text("Emoji Picker Test"),
        ),
        body: MainPage(),
      ),
    );
  }
}

class MainPage extends StatefulWidget {
  @override
  MainPageState createState() => new MainPageState();
}

class MainPageState extends State<MainPage> {
  bool isShowSticker;

  @override
  void initState() {
    super.initState();
    isShowSticker = false;
  }

  Future<bool> onBackPress() {
    if (isShowSticker) {
      setState(() {
        isShowSticker = false;
      });
    } else {
      Navigator.pop(context);
    }

    return Future.value(false);
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      child: Stack(
        children: <Widget>[
          Column(
            children: <Widget>[
              // your list goes here

              // Input content
              buildInput(),

              // Sticker
              (isShowSticker ? buildSticker() : Container()),
            ],
          ),
        ],
      ),
      onWillPop: onBackPress,
    );
  }

  Widget buildInput() {
    return Container(
      child: Row(
        children: <Widget>[
          // Button send image
          Material(
            child: new Container(
              margin: new EdgeInsets.symmetric(horizontal: 1.0),
              child: new IconButton(
                icon: new Icon(Icons.image),
                onPressed: () {},
                color: Colors.blueGrey,
              ),
            ),
            color: Colors.white,
          ),
          Material(
            child: new Container(
              margin: new EdgeInsets.symmetric(horizontal: 1.0),
              child: new IconButton(
                icon: new Icon(Icons.face),
                onPressed: () {
                  setState(() {
                    isShowSticker = !isShowSticker;
                  });
                },
                color: Colors.blueGrey,
              ),
            ),
            color: Colors.white,
          ),

          // Edit text
          Flexible(
            child: Container(
              child: TextField(
                style: TextStyle(color: Colors.blueGrey, fontSize: 15.0),
            decoration: InputDecoration.collapsed(
              hintText: 'Type your message...',
              hintStyle: TextStyle(color: Colors.blueGrey),
            ),
          ),
        ),
      ),

      // Button send message
      Material(
        child: new Container(
          margin: new EdgeInsets.symmetric(horizontal: 8.0),
          child: new IconButton(
            icon: new Icon(Icons.send),
            onPressed: () {},
            color: Colors.blueGrey,
          ),
        ),
        color: Colors.white,
      ),
    ],
  ),
  width: double.infinity,
  height: 50.0,
  decoration: new BoxDecoration(
      border: new Border(
          top: new BorderSide(color: Colors.blueGrey, width: 0.5)),
      color: Colors.white),
    );
  }

  Widget buildSticker() {
    return EmojiPicker(
  rows: 3,
  columns: 7,
  buttonMode: ButtonMode.MATERIAL,
  recommendKeywords: ["racing", "horse"],
  numRecommended: 10,
  onEmojiSelected: (emoji, category) {
    print(emoji);
  },
    );
  }
}

【讨论】:

  • 非常感谢您的宝贵回答,我已添加底部表格,然后使用此表情符号选择器,它工作正常 :)
  • 在获取最近时变慢了。
  • @b.john 你有没有设法修改它,让它变得更快?
  • @b.john 你有没有设法修改它,让它变得更快?
  • 这个插件非常滞后,如果你想制作完全流畅的应用程序,我不建议。这个插件也增加了应用程序的大小,不耐用和高效。虽然没有压力!!
猜你喜欢
  • 2023-02-26
  • 1970-01-01
  • 2018-03-25
  • 1970-01-01
  • 2017-09-11
  • 2017-01-17
  • 2022-06-24
  • 2020-12-23
  • 1970-01-01
相关资源
最近更新 更多