snowflake_dart

Creator: coderz1093

Last updated:

0 purchases

snowflake_dart Image
snowflake_dart Images

Languages

Categories

Add to Cart

Description:

snowflake dart

SNOWFLAKE_DART #
A full-featured Snowflake ID generator for Dart #
Can set nodeBits, sequenceBits, epoch, nodeId, and generate id from DateTime.

import 'package:snowflake_dart/snowflake_dart.dart';

void main() async {
var node = Snowflake(nodeId: 0);
print(node.generate());
// You can create from DateTime
var id = node.generate(time: DateTime.now());
print(id);

var timeFromId = node.getTimeFromId(id);
print(timeFromId);
var nodeFromId = node.getNodeFromId(id);
print(nodeFromId);
var stepFromId = node.getSequenceFromId(id);
print(stepFromId);

// If you want to use a custom epoch, you can set:
var node2 = Snowflake(nodeId: 0, epoch: 1688019071792);
print(node2.generate());

// Also, can set nodeBits, sequenceBits
// But sum of nodeBits and sequenceBits must be 22
var node3 = Snowflake(nodeId: 0, nodeBits: 16, sequenceBits: 6);
print(node3.generate());
var node4 = Snowflake(nodeId: 0, nodeBits: 14, sequenceBits: 8);
print(node4.generate());
}
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.