A pure Dart library for parsing and validating Indonesian NIK (Nomor Induk Kependudukan) - the national identification number for Indonesian citizens.
- ✅ Validate NIK format: Check if a NIK string is valid
- ✅ Parse NIK data: Extract province code, regency code, birth date, and gender
- ✅ Pure Dart: Platform-agnostic, works on Flutter, web, and server
- ✅ Type-safe: Strong typing with null safety
- ✅ Well-tested: Comprehensive unit tests included
- ✅ Lightweight: No external dependencies
Watch the NIK parser in action:
The NIK is a 16-digit unique identification number with the following structure:
| Position | Description |
|---|---|
| 1-2 | Province code |
| 3-4 | Regency/City code |
| 5-6 | District code |
| 7-12 | Birth date (DDMMYY) where DD+40 for females |
| 13-16 | Unique serial number |
- Male: Birth day is 1-31
- Female: Birth day is 41-71 (actual day + 40)
Example: For a female born on January 11, the date segment would be 511295 (51 = 11 + 40).
Add this package to your pubspec.yaml:
dependencies:
nik_parser_flutter: ^0.1.0Then run:
flutter pub getimport 'package:nik_parser_flutter/nik_parser_flutter.dart';
void main() {
final nik = '3203012301010001';
if (NikParser.isValid(nik)) {
print('NIK is valid');
} else {
print('NIK is invalid');
}
}import 'package:nik_parser_flutter/nik_parser_flutter.dart';
void main() {
final nik = '3203012301010001';
final info = NikParser.parse(nik);
if (info != null) {
print('Province Code: ${info.provinceCode}'); // 32
print('Regency Code: ${info.regencyCode}'); // 3203
print('Birth Date: ${info.birthDate}'); // 2001-01-23
print('Gender: ${info.gender}'); // M
print('Raw NIK: ${info.raw}'); // 3203012301010001
} else {
print('Invalid NIK');
}
}import 'package:nik_parser_flutter/nik_parser_flutter.dart';
void main() {
// Female born on December 11, 1995
// Day 11 + 40 = 51, so birth segment is 511295
final nik = '3203015112950001';
final info = NikParser.parse(nik);
if (info != null) {
print('Gender: ${info.gender}'); // F
print('Birth Date: ${info.birthDate}'); // 1995-12-11
}
}import 'package:nik_parser_flutter/nik_parser_flutter.dart';
void main() {
final invalidNiks = [
'123', // Too short
'abcd1234567890ef', // Non-numeric
'3203013201010001', // Invalid date (day 32)
];
for (final nik in invalidNiks) {
final info = NikParser.parse(nik);
if (info == null) {
print('$nik is invalid');
}
}
}Main parser class with static methods.
Validates whether a NIK string has the correct format.
Parameters:
nik: The NIK string to validate
Returns:
trueif the NIK is valid,falseotherwise
Validation checks:
- Length must be exactly 16 digits
- All characters must be numeric
- Birth date segment must represent a valid date
Parses a NIK string and extracts information.
Parameters:
nik: The NIK string to parse
Returns:
- A
NikInfoobject if valid,nullif invalid
Data class containing parsed NIK information.
String raw- The original 16-digit NIKString provinceCode- 2-digit province codeString regencyCode- 4-digit regency/city codeDateTime birthDate- Parsed birth dateString gender- Gender: "M" for male, "F" for female
- This package does NOT collect, store, or transmit any NIK data
- Never log or store NIK in plaintext in your applications
- Always mask NIK values when displaying (e.g.,
3203****010001) - Comply with Indonesian data protection regulations (UU ITE, UU PDP)
- Use encryption when storing NIK data
- Obtain proper consent before processing NIK data
See the example directory for a complete Flutter application demonstrating the usage of this package.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
This library is provided for educational and development purposes. Users are solely responsible for ensuring compliance with all applicable laws and regulations regarding the handling of personal data, including Indonesian NIK data.