security_keyboard 1.0.2

security_keyboard #

A flutter security keyboard for multiple TextField and automatically positioned to the TextField position.

Add dependency #

dependencies:
  security_keyboard: ^1.0.2

Examples #

Step1 #

Write a personalized keyboard based on project needs

typedef KeyboardSwitch = Function(SecurityKeyboardType type);

enum SecurityKeyboardType {
  text
}

class SecurityKeyboard extends StatefulWidget {
  ///用于控制键盘输出的Controller
  final KeyboardController controller;

  ///键盘类型,默认文本
  final SecurityKeyboardType keyboardType;


  const SecurityKeyboard({this.controller, this.keyboardType});

  ///文本输入类型
  static SecurityTextInputType text =
      SecurityKeyboard._inputKeyboard(SecurityKeyboardType.text);

  ///初始化键盘类型,返回输入框类型
  static SecurityTextInputType _inputKeyboard(
      SecurityKeyboardType securityKeyboardType) {
    ///设置输入框类型对应的键盘
    String inputType = securityKeyboardType.toString();
    KeyboardManager.addKeyboard(
      inputType,
      KeyboardConfig(
        builder: (context, controller) {
          return SecurityKeyboard(
            controller: controller,
            keyboardType: securityKeyboardType,
          );
        },
        getHeight: () {
          return SecurityKeyboard.getHeight(securityKeyboardType);
        },
      ),
    );

    return SecurityTextInputType(name: inputType);
  }

  ///键盘类型
  SecurityKeyboardType get _keyboardType => keyboardType;

  ///编写获取高度的方法
  static double getHeight(SecurityKeyboardType securityKeyboardType) {
    return 232;
  }


  @override
  _SecurityKeyboardState createState() => _SecurityKeyboardState();
}

class _SecurityKeyboardState extends State<SecurityKeyboard> {
  ///当前键盘类型
  SecurityKeyboardType currentKeyboardType;

  @override
  void initState() {
    super.initState();
    currentKeyboardType = widget._keyboardType;
  }

  @override
  Widget build(BuildContext context) {
    Widget keyboard;
   
    return keyboard;
  }
}

Step2 #

Add the following code to the page where you want to use the secure keyboard.

class PasswordVerify extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    ///WidgetsApp或者MaterialApp,Flutter会自动默认创建一个Navigator
    ///用于键盘弹出的时候页面可以滚动到输入框的位置
    return WillPopScope(
      child: KeyboardMediaQuery(
        child: Builder(builder: (ctx) {
          ///初始化键盘监听并且传递当前页面的context
          KeyboardManager.init(ctx);
          return Scaffold(
            appBar: AppBar(
              title: Text('验证登录密码'),
              brightness: Brightness.light,
            ),
            body: PasswordWidget(),
          );
        }),
      ),
      onWillPop: _requestPop,
    );
  }

  ///物理返回
  Future<bool> _requestPop() {
    bool b = true;
    if (KeyboardManager.isShowKeyboard) {
      KeyboardManager.hideKeyboard();
      b = false;
    }
    return Future.value(b);
  }
}

Step3 #

Set custom security keyboard type in the TextField keyboardType. Just Pass the inputType written in Step1 as you normally would set the keyboard input type.

TextField(
   ...
   keyboardType: SecurityKeyboard.text,
   ...
 )

[1.0.2] - 2019-04-08.

  • Update addKeyboard.

[1.0.1] - 2019-04-04.

  • Update dependencies.

[1.0.0] - 2019-04-04.

  • Initial version, created by cy.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  security_keyboard: ^1.0.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:security_keyboard/keyboard_controller.dart';
import 'package:security_keyboard/keyboard_manager.dart';
import 'package:security_keyboard/keyboard_media_query.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
42
Health:
Code health derived from static analysis. [more]
73
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
61
Learn more about scoring.

We analyzed this package on Jul 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Fix lib/keyboard_manager.dart. (-27.22 points)

Analysis of lib/keyboard_manager.dart failed with 1 error, 6 hints, including:

line 132 col 11: The argument type 'String' can't be assigned to the parameter type 'DiagnosticsNode'.

line 51 col 5: 'BinaryMessages' is deprecated and shouldn't be used.

line 51 col 20: 'setMockMessageHandler' is deprecated and shouldn't be used.

line 101 col 19: 'BinaryMessages' is deprecated and shouldn't be used.

line 101 col 34: 'handlePlatformMessage' is deprecated and shouldn't be used.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and security_keyboard.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test

Admin