Skip to content

Commit 9115336

Browse files
committed
remove dependancy to dart:io to allow for proper multi platform
1 parent 2145798 commit 9115336

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/src/xid_base.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'dart:io';
21
import 'dart:math';
32

43
import 'package:xid/src/base32codec.dart';
@@ -20,6 +19,7 @@ const String _allChars = "0123456789abcdefghijklmnopqrstuv";
2019
///
2120
class Xid {
2221
static String? _machineId;
22+
static int? _processId;
2323
static int? _counterInt;
2424

2525
List<int>? _xidBytes;
@@ -77,14 +77,14 @@ class Xid {
7777
}
7878

7979
List<int> _getMachineId() {
80-
var machineId = _machineId;
81-
if (machineId != null) {
82-
return _toBytes(machineId);
80+
81+
if (_machineId != null) {
82+
return _toBytes(_machineId!);
8383
}
8484

85-
machineId = Random.secure().nextInt(5170000).toString();
86-
_machineId = machineId;
87-
return _toBytes(machineId);
85+
_processId = Random.secure().nextInt(4194304);
86+
_machineId = Random.secure().nextInt(5170000).toString();
87+
return _toBytes(_machineId!);
8888
}
8989

9090
static int _counter() {
@@ -110,8 +110,8 @@ class Xid {
110110
_xidBytes![5] = machineID[1];
111111
_xidBytes![6] = machineID[2];
112112

113-
_xidBytes![7] = (pid >> 8) & 0xff;
114-
_xidBytes![8] = (pid) & 0xff;
113+
_xidBytes![7] = (_processId! >> 8) & 0xff;
114+
_xidBytes![8] = (_processId!) & 0xff;
115115

116116
_xidBytes![9] = (counter >> 16) & 0xff;
117117
_xidBytes![10] = (counter >> 8) & 0xff;

0 commit comments

Comments
 (0)