license_plate_number 3.0.0
license_plate_number: ^3.0.0 copied to clipboard
Flutter widget for inputting license plate number. Build-in one light style and one dark style, and the style can be changed.
license_plate_number #
Language: English | 中文简体
Flutter package for inputting chinese license plate number.
- Build-in one light style and one dark style, and the style can be changed.
- Supporting landscape.
- Plate numbers can be edited separately.
- Data-driven plate patterns with built-in China, Korea, US and Japan formats.


Plate formats #
Built-in patterns for China, Korea, the US and Japan. The keyboard layout and the allowed characters of every position come from the pattern data.
| Korea | Japan (two rows) | US (dark theme) |
|---|---|---|
![]() |
![]() |
![]() |
How to use #
Install #
dependencies:
license_plate_number: ^3.0.0
Upgrading to 3.0.0 #
Compared with 2.0.1, this release contains two breaking changes:
- The SDK constraint is now
^3.7.2: Dart 3.7.2 or later is required and the package is null-safety only. Upgrade your Dart SDK and theenvironment: sdk:constraint of your app before depending on this version. PlateKeyboard.keyboardControlleris now required. Standalone use ofPlateKeyboardmust create aKeyboardControllerand pass it in (see thePlateKeyboardexample below).PlateInputFieldis not affected: its ownkeyboardControllerparameter stays optional.
Basic usage #
Package includes two main widgets,PlateInputField and PlateKeyboard.
PlateInputField is for inputting the plate number.
Container(
alignment: Alignment.center,
child: PlateInputField(
placeHolder: '沪A12345',
styles: PlateStyles.light,
inputFieldWidth: 40,
inputFieldHeight: 54,
autoCompleteLength: 7, // auto complete after 7 chars, use 8 for new energy plates
onChanged: (List<String> array, String value) {
// e.g.
// array ['沪', 'A', '1', '2', '3', '4', '5']
// value 沪A12345
},
),
)
PlateKeyboard is usually not used directly. It is controlled by PlateInputField. But we also provide KeyboardController to show/hide the keyboard by yourself.
If you use PlateKeyboard on its own, keyboardController is required:
final KeyboardController _keyboardController = KeyboardController();
PlateKeyboard(
keyboardController: _keyboardController,
);
/// KeyboardController
KeyboardController _keyboardController = KeyboardController();
/// Show keyboard
_keyboardController.showKeyboard(context);
/// Hide keyboard
_keyboardController.hideKeyboard();
/// Is keyboard showing
_keyboardController.isKeyboardShowing();
/// Modify plate number
_keyboardController.plateNumber = 'XXXXXXX';
/// Clear plate number
_keyboardController.clear();
/// Read the plate characters as an array
List<String> characters = _keyboardController.characters;
PlateInputField(
/// Pass KeyboardController to PlateInputField
keyboardController: _keyboardController,
/// Optional: complete after 7 chars for common plates
autoCompleteLength: 7,
/// Optional: haptic feedback on key press
enableHapticFeedback: true,
/// Optional: hide the keyboard when tapping outside the input fields
dismissOnTapOutside: true,
/// Optional: customize the complete button label
completeText: '完成',
/// Optional: observe every key press (empty string for backspace)
onKeyPressed: (key) => print(key),
);
Note: dismissOnTapOutside only covers the input field's own area. To
dismiss when tapping anywhere on the page, wrap your page with a
GestureDetector that calls KeyboardController.hideKeyboard (see the
example app). Other optional parameters: newEnergyPlaceHolder,
semanticsLabel, pattern.
Keyboard rules: the 8th position (new energy) only allows letters D/F and digits; special suffix keys (学/领/警/港/澳/挂/临) are enabled on the last position of common plates; the first page also contains military plate codes (军/空/海/北/沈/兰/济/南/广/成).
Custom patterns: the keyboard layout and per-position rules are described by
PlatePattern (slots, key pages, separators). PlatePatterns.china is the
default; pass pattern: to PlateInputField to use another country format.
Built-in patterns: PlatePatterns.china, PlatePatterns.korea,
PlatePatterns.unitedStates, PlatePatterns.japan (two-row layout via
displayRows).
Styles #
Two default styles was build in,but self-defined style is also supported.
/// 1. Use constructor.
PlateStyles(
/// Text style of plate input field.
plateInputFieldTextStyle: TextStyle(
color: Color(0xFFFFFFFF),
fontSize: 20,
fontWeight: FontWeight.normal,
),
/// Text style of new energy place holder.
newEnergyPlaceHolderTextStyle: TextStyle(
color: Color(0xFFDDDDDD),
fontSize: 10,
fontWeight: FontWeight.normal,
),
/// Background color of input field.
plateInputFieldColor: Color(0xFF4A4A4A),
/// Border of input field.
plateInputBorder: Border.fromBorderSide(BorderSide(
color: Color(0xFFFFFFFF),
width: 2,
style: BorderStyle.solid,
)),
/// Border of focused input field.
plateInputFocusedBorder: Border.fromBorderSide(BorderSide(
color: Color(0xFF2196F3),
width: 2,
style: BorderStyle.solid,
)),
/// Border radius of input field.
plateInputBorderRadius: const Radius.circular(8.0),
/// Color of Separator between city code and numbers.
plateSeparatorColor: Color(0xFFFFFFFF),
/// Background color of keyboard.
keyboardBackgroundColor: Color(0xFF131313),
/// Text color of key text.
keyboardButtonTextColor: Color(0xFFFFFFFF),
/// Background color of keys.
keyboardButtonColor: Color(0xFF4A4A4A),
/// Background color of disabled keys.
keyboardButtonDisabledColor: Color(0x994A4A4A),
);
/// 2. Copy with a default style.
PlateStyles.dark.copyWith(
keyboardBackgroundColor: Color(0xFF000000),
);



