skip to Main Content

How to allow emojis as input string in text form field flutter.

Text form field should allow only text and emojis. How to do it.

2

Answers


  1. class EmojiTextField extends StatefulWidget { 
      final TextEditingController _controller = TextEditingController();
      String? _validateInput(String input) {
        final RegExp regex = RegExp(
          r'^[u0020-u007Eu00A0-u00FFu0100-u017Fu0180-u024Fu0250-u02AFu0300-u03FF]*$',
          );
    if (!regex.hasMatch(input)) {
      return 'Please enter only text and emojis';
    }
    return null;
    }
    
    Widget build(BuildContext context) {
    return Padding(
    child: TextField(
          controller: _controller,
          decoration: InputDecoration(
            hintText: 'Enter text or emojis',
            errorText: _validateInput(_controller.text),
          ),
        ),
     );
    }
    
    Login or Signup to reply.
  2. You can use the following package:

    emoji_picker_flutter
    

    https://pub.dev/packages/emoji_picker_flutter

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search