Skip to content

myaasiinh/nik_parser_flutter

Repository files navigation

nik_parser_flutter

pub package License: Apache-2.0

A pure Dart library for parsing and validating Indonesian NIK (Nomor Induk Kependudukan) - the national identification number for Indonesian citizens.

Features

  • 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

Demo

Watch the NIK parser in action:

📹 View Demo Video

NIK Structure

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

Gender Encoding

  • 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).

Installation

Add this package to your pubspec.yaml:

dependencies:
  nik_parser_flutter: ^0.1.0

Then run:

flutter pub get

Usage

Basic Validation

import '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');
  }
}

Parsing NIK Information

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');
  }
}

Female NIK Example

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
  }
}

Error Handling

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');
    }
  }
}

API Reference

NikParser

Main parser class with static methods.

Methods

isValid(String nik) → bool

Validates whether a NIK string has the correct format.

Parameters:

  • nik: The NIK string to validate

Returns:

  • true if the NIK is valid, false otherwise

Validation checks:

  • Length must be exactly 16 digits
  • All characters must be numeric
  • Birth date segment must represent a valid date
parse(String nik) → NikInfo?

Parses a NIK string and extracts information.

Parameters:

  • nik: The NIK string to parse

Returns:

  • A NikInfo object if valid, null if invalid

NikInfo

Data class containing parsed NIK information.

Properties

  • String raw - The original 16-digit NIK
  • String provinceCode - 2-digit province code
  • String regencyCode - 4-digit regency/city code
  • DateTime birthDate - Parsed birth date
  • String gender - Gender: "M" for male, "F" for female

Privacy & Security

⚠️ Important: NIK is sensitive personal data protected by Indonesian law.

  • 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

Example App

See the example directory for a complete Flutter application demonstrating the usage of this package.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Disclaimer

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.

About

A pure Dart library to parse and validate Indonesian NIK (National ID)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages