Mobile secure keyboard to prevent KeyLogger attack and screen capture.

Screenshots

AlphanumericNumeric

Getting started

To use this plugin, add flutter_secure_keyboard as a dependency in your pubspec.yaml file. For example:

dependencies:
  flutter_secure_keyboard: ^2.1.2

Examples

class WithSecureKeyboardExample extends StatefulWidget {
  @override
  _WithSecureKeyboardExampleState createState() => _WithSecureKeyboardExampleState();
}

class _WithSecureKeyboardExampleState extends State<WithSecureKeyboardExample> {
  final secureKeyboardController = SecureKeyboardController();

  final passwordEditor = TextEditingController();
  final passwordTextFieldFocusNode = FocusNode();

  final pinCodeEditor = TextEditingController();
  final pinCodeTextFieldFocusNode = FocusNode();

  @override
  Widget build(BuildContext context) {
    // We recommend that you set the secure keyboard to the top 
    // of the build function so that it can be seen properly.
    return WithSecureKeyboard(
      controller: secureKeyboardController,
      child: Scaffold(
        appBar: AppBar(title: Text('with_secure_keyboard_example')),
        body: _buildContentView()
      ),
    );
  }

  Widget _buildContentView() {
    // We recommend using the ListView widget to prevent widget overflow.
    return ListView(
      padding: const EdgeInsets.all(8.0),
      children: [
        Padding(
          padding: const EdgeInsets.only(bottom: 12.0),
          child: _buildPasswordTextField()
        ),
        _buildPinCodeTextField()
      ],
    );
  }

  Widget _buildPasswordTextField() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text('Password'),
        TextFormField(
          controller: passwordEditor,
          focusNode: passwordTextFieldFocusNode,
          // We recommended to set false to prevent the soft keyboard from opening.
          enableInteractiveSelection: false,
          obscureText: true,
          onTap: () {
            secureKeyboardController.show(
              type: SecureKeyboardType.ALPHA_NUMERIC,
              textFieldFocusNode: passwordTextFieldFocusNode,
              initText: passwordEditor.text,
              hintText: 'password',
              // Use onCharCodesChanged to have text entered in real time.
              onCharCodesChanged: (List<int> charCodes) {
                passwordEditor.text = String.fromCharCodes(charCodes);
              }
            );
          },
        ),
      ],
    );
  }

  Widget _buildPinCodeTextField() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text('PinCode'),
        TextFormField(
          controller: pinCodeEditor,
          focusNode: pinCodeTextFieldFocusNode,
          // We recommended to set false to prevent the soft keyboard from opening.
          enableInteractiveSelection: false,
          obscureText: true,
          onTap: () {
            secureKeyboardController.show(
              type: SecureKeyboardType.NUMERIC,
              textFieldFocusNode: pinCodeTextFieldFocusNode,
              initText: pinCodeEditor.text,
              hintText: 'pinCode',
              // Use onDoneKeyPressed to allow text to be entered when you press the done key,
              // or to do something like encryption.
              onDoneKeyPressed: (List<int> charCodes) {
                pinCodeEditor.text = String.fromCharCodes(charCodes);
              }
            );
          },
        ),
      ],
    );
  }
}

Package

  • WithSecureKeyboard - A widget that implements a secure keyboard with controller.
  • SecureKeyboardController - Controller to check or control the state of the secure keyboard.

Note: The parameters marked with an asterisk(*) are required.

WithSecureKeyboard

ParameterDescription
controller*Controller for controlling the secure keyboard.
child*A widget to have a secure keyboard.
keyboardHeightParameter to set the keyboard height.
Default value is 280.0.
keyRadiusSet the radius of the keyboard key.
Default value is 4.0.
keySpacingSet the spacing between keyboard keys.
Default value is 1.4.
keyInputMonitorPaddingSet the padding of the key input monitor.
Default value is EdgeInsets.only(left: 10.0, right: 5.0).
keyboardPaddingSet the padding of the keyboard.
Default value is EdgeInsets.symmetric(horizontal: 5.0).
backgroundColorParameter to set the keyboard background color.
Default value is Color(0xFF0A0A0A).
stringKeyColorParameter to set keyboard string key(alphanumeric, numeric..) color.
Default value is Color(0xFF313131).
actionKeyColorParameter to set keyboard action key(shift, backspace, clear..) color.
Default value is Color(0xFF222222).
doneKeyColorParameter to set keyboard done key color.
Default value is Color(0xFF1C7CDC).
activatedKeyColorSet the color to display when activated with the shift action key. If the value is null, doneKeyColor is used.
keyTextStyleParameter to set keyboard key text style.
Default value is TextStyle(color: Colors.white, fontSize: 16.0, fontWeight: FontWeight.bold).
inputTextStyleParameter to set keyboard input text style.
Default value is TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: FontWeight.bold).
screenCaptureDetectedAlertTitleSecurity Alert title, only works on ios.
screenCaptureDetectedAlertMessageSecurity Alert message, only works on ios
screenCaptureDetectedAlertActionTitleSecurity Alert actionTitle, only works on ios.

SecureKeyboardController

FunctionDescription
isShowingWhether the secure keyboard is open.
showShow a secure keyboard.
hideHide a secure keyboard.

SecureKeyboardController.show()

ParameterDescription
type*Specifies the secure keyboard type.
textFieldFocusNodeThe FocusNode that will receive focus on.
initTextSet the initial value of the input text.
hintTextThe hint text to display when the input text is empty.
inputTextLengthSymbolSet the symbol to use when displaying the input text length.
doneKeyTextSet the done key text.
clearKeyTextSet the clear key text.
obscuringCharacterSet the secure character to hide the input text.
Default value is .
maxLengthSet the maximum length of text that can be entered.
alwaysCapsWhether to always display uppercase characters.
Default value is false.
obscureTextWhether to hide input text as secure characters.
Default value is true.
shuffleNumericKeyWhether to shuffle the position of the numeric keys.
Default value is true.
hideKeyInputMonitorWhether to hide the key input monitor.
Default value is false.
disableKeyBubbleWhether to disable the key bubble.
Default value is false.
onKeyPressedCalled when the key is pressed.
onCharCodesChangedCalled when the character codes changed.
onDoneKeyPressedCalled when the done key is pressed.
onCloseKeyPressedCalled when the close key is pressed.

Libraries

flutter_secure_keyboard