daegalus / dart-uuid Goto Github PK
View Code? Open in Web Editor NEWGenerate RFC4122(v1,v4,v5,v6,v7,v8) UUIDs
License: MIT License
Generate RFC4122(v1,v4,v5,v6,v7,v8) UUIDs
License: MIT License
Hi,
How would I parse a string 907b0976-00be-4465-9e00-a8f0d571979a
to a Uuid object using the library? I could only find the parse(String)
but it returns a byte.
Regards,
Hello,
With version 0.3.2 and this code:
import 'package:uuid/uuid.dart';
void main() {
print(new UuidBase().v1());
}
The generated javascript file is 30KB minified.
With version 0.4.0 and the same code (except UuidBase is Uuid), the file size is 423KB minified.
That is a 14x increase.
Thank you.
Presently if you ask parse()
to parse an invalid UUID, it'll just return a list of zeros.
This makes error handling bizarre. Failing to parse should result in an error, not a value.
how to control the uuid length???just like Generate 8-digit random number
Do you have any plans to implement UUIDv7, although it's still a recent draft? It would be a nice addition to the library and will solve the long standing issue with previous UUID variants, which are not suitable to generate time-based, sortable unique identifiers to use as database keys
Here is the link to the draft UUIDv7
I was wondering why options
are passed as a Map<String, dynamic>
as it's not safer than a simple class.
While testing on v3.0.6, I found an issue with UUID.v1 performance dropping sharply after hot reload.
Not sure if it's really a problem, but I'll report it right away.
Thanks for making such a great package.
print("started");
var startTime = DateTime.now();
var value = "";
final uuid = Uuid();
for (var i = 0; i < 10000; i++) {
value = uuid.v1();
}
var endTime = DateTime.now();
var diff =
endTime.millisecondsSinceEpoch - startTime.millisecondsSinceEpoch;
print("$diff ms");
flutter: started
flutter: 29 ms
flutter: started
flutter: 29 ms
flutter: started
flutter: 16 ms
Reloaded 1 of 2178 libraries in 741ms. ← hot reload
flutter: started
flutter: 6218 ms
flutter: started
flutter: 18709 ms
flutter: started
flutter: 30760 ms
[✓] Flutter (Channel unknown, 2.11.0-0.0.pre.542, on macOS 12.0.1 21A559 darwin-x64, locale ko-KR)
• Flutter version 2.11.0-0.0.pre.542 at /Users/nero/Project/FlutterContribution/flutter
• Upstream repository unknown
• Framework revision 1958656943 (5 weeks ago), 2022-02-14 05:15:17 -0500
• Engine revision b63614c306
• Dart version 2.17.0 (build 2.17.0-104.0.dev)
• DevTools version 2.10.0
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/nero/Library/Android/sdk
• Platform android-31, build-tools 31.0.0
• Java binary at: /Volumes/Lecture HD/Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 44.0.2
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[✓] Android Studio (version 2020.3)
• Android Studio at /Volumes/Lecture HD/Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
[✓] VS Code (version 1.65.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.36.0
[✓] VS Code (version 1.63.2)
• VS Code at /Volumes/Lecture HD/Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.36.0
[✓] Connected device (2 available)
• nero의 iPad (mobile) • 00008027-000A41CE0C0A402E • ios • iOS 15.3.1 19D52
• Chrome (web) • chrome • web-javascript • Google Chrome 99.0.4844.74
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Given the nature of the v1 uuid, I'd like to be able to easily convert the uuid into a Dart DateTime object. How would I do that?
Thanks in advance!
There is a substantial performance degradation once the dart code is compiled into javascropt. To generate some 1,800 UUIDs (v4) in dart it takes ~ 2 seconds. The same code in javascript takes over 50 seconds.
Right now, the different v1
, v4
, etc.. functions return dynamic, because their return typ depends on whether a buffer has been provided.
In order to make them type safe, I suggest splitting these functions up into two functions, eg.:
String v1(/*...*/) { }
Buffer v1buffer(/*...*/) { }
Currently, the global options are ignored by Uuid class. The reason is simply, that data is incorrectly used in the _init
methods:
void _initV4(Map<String, dynamic>? options) {
options ??= {};
// ...
}
As you can see, the init method uses the local options, that have been passed into it via the v4()
method, and not the global options of the constructor. This leads to global values like grng
never beeing used!
The documentation for the constructor of the class UuidValue states:
/// Optioanlly, you can disable the validation check in the constructor
/// by setting [validate] to `true`.
Looking at the code, shouldn't the documentation say the following?
/// Optionally, you can disable the validation check in the constructor
/// by setting [validate] to `false`.
I am trying to pick up a new programming language with Dart, so it might escape my understanding, but what should happen if the UUID is invalid? The statement Uuid.isValidUUID(uuid);
returns false, and it has no further consequence. The object is created with whatever is passed as this.uuid
.
Hello,
I’m experiencing this issue when trying to add the uuid package to my project:
Because uuid >=3.0.0 depends on crypto ^3.0.0 and mqtt_client >=6.2.0 depends on crypto ^2.1.3, uuid >=3.0.0 is incompatible with mqtt_client >=6.2.0.
So, because App depends on both mqtt_client ^8.0.0 and uuid 3.0.1, version solving failed.
The fix for #46 introduced the following in UuidUtil.mathRNG
:
(seed == -1) ? b.shuffle() : b.shuffle(Random(seed));
This solution is not really optimal but was properly introduced because of missing knowledge about the underlying problem which is misuse of the Random
class. This can be expected since the Dart SDK documentation for Random
is not really that specific about how to use it.
The real problem in #46 is that we are creating a new Random()
object every time we call UuidUtil.mathRNG
. When we create a Random()
object, The Dart VM are using an internal random generator to generate a seed for our own Random()
instance. For Random()
, this seed is 32 bit long. The implementation for this can be found here:
https://github.com/dart-lang/sdk/blob/fd81b73e67051a7ac06669a01ec32082ced0dc4f/sdk/lib/_internal/vm/lib/math_patch.dart#L183
32 bit of randomness is not really that great (two Random objects with same seed will produce the same number sequence) and will open op for problems if we create a lot of Random()
objects. But the random generator behind Random()
is well implemented without the worry of repeating patterns. So what we should do instead is just create a single instance for our UUID library and reuse this.
An example can be see here:
import 'dart:math';
import 'dart:typed_data';
void main(List<String> args) {
print('brokenRandom: ${testForDuplicates(brokenRandom)}'); // Duplicates: 103
print('betterRandom: ${testForDuplicates(betterRandom)}'); // Duplicates: 0
}
int testForDuplicates(Uint8List Function() getNumbers, [int count = 1000000]) =>
count - {for (var i = 0; i < count; i++) getNumbers().join(',')}.length;
Uint8List brokenRandom() {
final rand = Random();
final b = Uint8List(16);
for (var i = 0; i < 16; i++) {
b[i] = rand.nextInt(256);
}
return b;
}
final _rand = Random();
Uint8List betterRandom() {
final b = Uint8List(16);
for (var i = 0; i < 16; i++) {
b[i] = _rand.nextInt(256);
}
return b;
}
The reason why calling shuffle
"fixes" the problem, is because shuffle are creating its own Random
object every time:
void shuffle([Random? random]) {
random ??= Random();
This is really not what big of a problem since we are not expecting shuffle
to be based on great randomness (and if we do, we are properly using Random.secure()
. But since we are creating another Random
object, and uses that for shuffle, we do make it a lot more rare that we get two 32 bit seeds in a row which we have previous seen.
But the use of shuffle
is really just needless use of CPU cycles for something which can be fixed by creating a static final
random generator.
(My change does also add a static final
for Random.secure()
. The Dart VM is implemented to call the OS for random numbers for all numbers generated with Random.secure()
so we don't have the same seed problem. But both for consistency, and because there can be some overhead, we should also just cache this random generator instance.)
Dart 1.12 is in beta and supports null safety - time to migrate packages. Can this package be migrated? I'm happy to open a PR for that.
Upgrading to uuid 0.3 has been a problem for our library that is shared between both server and client applications.
IMHO, a library such as this should try not to have such a hard distinction between client vs server application types (different import paths). Is there a way to provide a common interface that can be shared between all types of dart applications?
// Generate a v1 (time-based) id
uuid.v1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a'
from doc it say this time based
can I compare tow ids to know which created first ?
The v4()
method can generate duplicate UUIDs, when used with the default configuration (using the mathRNG
random number generator). The expected behaviour is for UUIDs to be unique.
See attached test.
uuid_v4_uniqueness_test.txt
"Simple, fast," but incorrect is not good!
I can see there could be valid reasons for not using UuidUtil.cryptoRNG
. But I would argue that cryptoRNG should be made the default, and anyone who wants to risk having duplicate UUIDs can knowingly and intentionally do so by changing to mathRNG. Most programmers will start with the defaults, and they could unwittingly run into problems without realising it until it is too late.
Cryptographically secure means something else
The current documentation on the random number generators don't make this point clear. It only talks about them being "cryptographically strong" vs not cryptographically strong.
In the context of generating UUIDs, the issue of "cryptographically strong" usually refers to whether the UUIDs are suitable for security purposes. For example, the "IP address + time" version UUIDs might be perfectly unique, but their values can be predicted by an attacker. Therefore, a programmer reading that description might choose mathRNG, because they only need unique UUIDs but does not need them to be secure.
Actually, does anyone actually want a UUID generator that can produce duplicates? Especially when the probability of duplicates appears to be greater than 1 in 10,000 ?
Looks like UUID imports cipher, which imports dart:io. Specifically, cipher/entropy/file_entropy_source.dart
Would be awesome to have a version that works in a browser.
Expected
Builds and runs for web. README says "Runs in web, server, and flutter".
Actual
Crashes upon build.
System
Flutter 1.14.6 • channel beta • https://github.com/flutter/flutter.git
Framework • revision fabeb2a16f (3 weeks ago) • 2020-01-28 07:56:51 -0800
Engine • revision c4229bfbba
Tools • Dart 2.8.0 (build 2.8.0-dev.5.0 fc3af737c7)
Error
Unable to find modules for some sources, this is usually the result of either a
bad import, a missing dependency in a package (or possibly a dev_dependency
needs to move to a real dependency), or a build failure (if importing a
generated file).
Please check the following imports:
`import 'package:uuid/uuid_util.dart';` from aWebProject|main.dart at
9:1
`import 'package:uuid/uuid.dart';` from aWebProject|main.dart at 8:1
Failed after 294ms
Building application for the web... 9.4s
Failed to build application for the Web.
I have an application with 751,446 users that generated 863,497 database records and there is a lot of conflicts.
Unique Ids | Two clashes | Three clashes | Four or more clashes |
---|---|---|---|
862,117 | 663 | 18 | 0 |
Code used to generate the id:
Uuid().v1()
Those 18 clashes generated these records:
UUID | Device | Date |
---|---|---|
80efe870-de35-11e9-8d55-214e2769a4f0 | 514503fd4f5d967a | 2019-09-23 19:08:18.0000000 +00:00 |
80efe870-de35-11e9-8d55-214e2769a4f0 | 514503fd4f5d967a | 2019-09-23 19:08:18.0000000 +00:00 |
80efe870-de35-11e9-8d55-214e2769a4f0 | 5f469abde7842bb6 | 2019-09-23 19:08:18.0000000 +00:00 |
83873a40-e158-11e9-bba5-37afc07df59f | e766537ad7fe8714 | 2019-09-27 18:56:29.0000000 +00:00 |
83873a40-e158-11e9-bba5-37afc07df59f | e766537ad7fe8714 | 2019-09-27 18:56:29.0000000 +00:00 |
83873a40-e158-11e9-bba5-37afc07df59f | e766537ad7fe8714 | 2019-09-27 18:56:29.0000000 +00:00 |
887da9d0-d7da-11e9-9274-3bccee8f26b2 | 1dc22bdfceceede2 | 2019-09-15 17:02:00.0000000 +00:00 |
887da9d0-d7da-11e9-9274-3bccee8f26b2 | 1dc22bdfceceede2 | 2019-09-15 17:02:00.0000000 +00:00 |
887da9d0-d7da-11e9-9274-3bccee8f26b2 | 1dc22bdfceceede2 | 2019-09-15 17:02:00.0000000 +00:00 |
82a65b00-d632-11e9-aa3f-3dc1d9683a0f | ae1a928095f336b8 | 2019-09-13 14:26:44.0000000 +00:00 |
82a65b00-d632-11e9-aa3f-3dc1d9683a0f | ae1a928095f336b8 | 2019-09-13 14:26:44.0000000 +00:00 |
82a65b00-d632-11e9-aa3f-3dc1d9683a0f | ae1a928095f336b8 | 2019-09-13 14:26:44.0000000 +00:00 |
e3251440-bbba-11e9-a29d-49adc69e972e | a69fc2c20bc05b04 | 2019-08-10 22:04:56.0000000 +00:00 |
e3251440-bbba-11e9-a29d-49adc69e972e | a69fc2c20bc05b04 | 2019-08-10 22:04:56.0000000 +00:00 |
e3251440-bbba-11e9-a29d-49adc69e972e | a69fc2c20bc05b04 | 2019-08-10 22:04:56.0000000 +00:00 |
ebae1bc0-e455-11e9-b7c5-75e78d1d35ac | 3c86565a56848517 | 2019-10-01 14:15:28.0000000 +00:00 |
ebae1bc0-e455-11e9-b7c5-75e78d1d35ac | 3c86565a56848517 | 2019-10-01 14:15:28.0000000 +00:00 |
ebae1bc0-e455-11e9-b7c5-75e78d1d35ac | 68cfda7341c3b7df | 2019-10-01 14:15:28.0000000 +00:00 |
8984c110-e9d7-11e9-99e9-77424a6c0053 | ae5b97827890695c | 2019-10-08 14:25:54.0000000 +00:00 |
8984c110-e9d7-11e9-99e9-77424a6c0053 | ae5b97827890695c | 2019-10-08 14:25:54.0000000 +00:00 |
8984c110-e9d7-11e9-99e9-77424a6c0053 | ae5b97827890695c | 2019-10-08 14:25:54.0000000 +00:00 |
49d78790-cad4-11e9-93b5-7d3ec148d0be | 983d9e4f85c287f5 | 2019-08-30 03:14:33.0000000 +00:00 |
49d78790-cad4-11e9-93b5-7d3ec148d0be | 983d9e4f85c287f5 | 2019-08-30 03:14:33.0000000 +00:00 |
49d78790-cad4-11e9-93b5-7d3ec148d0be | 983d9e4f85c287f5 | 2019-08-30 03:14:33.0000000 +00:00 |
d180f8b0-eb8c-11e9-a00d-8136a2b770d2 | b478c085fa129a3d | 2019-10-10 18:36:05.0000000 +00:00 |
d180f8b0-eb8c-11e9-a00d-8136a2b770d2 | b780c1f5afaf51f5 | 2019-10-10 18:36:05.0000000 +00:00 |
d180f8b0-eb8c-11e9-a00d-8136a2b770d2 | b780c1f5afaf51f5 | 2019-10-10 18:36:05.0000000 +00:00 |
5a2cec00-eae3-11e9-ae5f-9375d4cfb5a6 | 6ba68801bd95431b | 2019-10-09 22:23:00.0000000 +00:00 |
5a2cec00-eae3-11e9-ae5f-9375d4cfb5a6 | 6ba68801bd95431b | 2019-10-09 22:23:00.0000000 +00:00 |
5a2cec00-eae3-11e9-ae5f-9375d4cfb5a6 | 6ba68801bd95431b | 2019-10-09 22:23:00.0000000 +00:00 |
3f4b3ef0-e485-11e9-a8d9-93e35cf7a47d | d95b00fa73ba5397 | 2019-10-01 19:54:15.0000000 +00:00 |
3f4b3ef0-e485-11e9-a8d9-93e35cf7a47d | d95b00fa73ba5397 | 2019-10-01 19:54:15.0000000 +00:00 |
3f4b3ef0-e485-11e9-a8d9-93e35cf7a47d | d95b00fa73ba5397 | 2019-10-01 19:54:15.0000000 +00:00 |
c2003370-da51-11e9-a5bd-b14162c6c18f | 88108a74d1b62728 | 2019-09-18 20:20:29.0000000 +00:00 |
c2003370-da51-11e9-a5bd-b14162c6c18f | 88108a74d1b62728 | 2019-09-18 20:20:29.0000000 +00:00 |
c2003370-da51-11e9-a5bd-b14162c6c18f | bf58c07c7baf3b91 | 2019-09-18 20:20:29.0000000 +00:00 |
ccb96740-d35e-11e9-8f56-b589858ca938 | 21562e55368a0f6c | 2019-09-10 00:06:12.0000000 +00:00 |
ccb96740-d35e-11e9-8f56-b589858ca938 | 21562e55368a0f6c | 2019-09-10 00:06:12.0000000 +00:00 |
ccb96740-d35e-11e9-8f56-b589858ca938 | 21562e55368a0f6c | 2019-09-10 00:06:12.0000000 +00:00 |
a6356880-dcff-11e9-998c-c9c82aad3773 | a93e033c43ca5b96 | 2019-09-22 06:10:17.0000000 +00:00 |
a6356880-dcff-11e9-998c-c9c82aad3773 | a93e033c43ca5b96 | 2019-09-22 06:10:17.0000000 +00:00 |
a6356880-dcff-11e9-998c-c9c82aad3773 | a93e033c43ca5b96 | 2019-09-22 06:10:17.0000000 +00:00 |
c08960d0-c1b9-11e9-8d8f-db20ba6cee0f | 1e8a896f31966fcf | 2019-08-18 13:11:55.0000000 +00:00 |
c08960d0-c1b9-11e9-8d8f-db20ba6cee0f | 1e8a896f31966fcf | 2019-08-18 13:11:55.0000000 +00:00 |
c08960d0-c1b9-11e9-8d8f-db20ba6cee0f | 1e8a896f31966fcf | 2019-08-18 13:11:55.0000000 +00:00 |
8617dd80-e6b9-11e9-b53e-e122453c938e | 31f51293fcdcfb64 | 2019-10-04 15:13:30.0000000 +00:00 |
8617dd80-e6b9-11e9-b53e-e122453c938e | 31f51293fcdcfb64 | 2019-10-04 15:13:30.0000000 +00:00 |
8617dd80-e6b9-11e9-b53e-e122453c938e | 31f51293fcdcfb64 | 2019-10-04 15:13:30.0000000 +00:00 |
39e97480-ebc0-11e9-9619-ef0a2d518b9a | b29e47e4859ee389 | 2019-10-11 00:44:04.0000000 +00:00 |
39e97480-ebc0-11e9-9619-ef0a2d518b9a | b29e47e4859ee389 | 2019-10-11 00:44:04.0000000 +00:00 |
39e97480-ebc0-11e9-9619-ef0a2d518b9a | b29e47e4859ee389 | 2019-10-11 00:44:04.0000000 +00:00 |
b5aad7c0-aa0d-11e9-8c14-fd0b7fe3a1df | 8d301975d6c4f807 | 2019-07-19 10:12:27.0000000 +00:00 |
b5aad7c0-aa0d-11e9-8c14-fd0b7fe3a1df | 8d301975d6c4f807 | 2019-07-19 10:12:27.0000000 +00:00 |
b5aad7c0-aa0d-11e9-8c14-fd0b7fe3a1df | 8d301975d6c4f807 | 2019-07-19 10:12:27.0000000 +00:00 |
I think the problem is the granularity of the date (notice how those records were generated at the same hour, minute and second (but I really doubt about milliseconds)).
I copied the Guid Comb generator from the C# nHibernate ORM (available here: https://github.com/nhibernate/nhibernate-core/blob/master/src/NHibernate/Id/GuidCombGenerator.cs) with some minor adjustments as not generating the same Id in the exactly same millisecond (while generating in a loop) and taking the device id into account (didn't made any tests to check if it really works with 0 clashes, though):
final _onlyHexPattern = RegExp("[^0-9a-f]", caseSensitive: false);
List<int> _deviceIdGuidArray;
final _baseDate = DateTime.utc(1900, 1, 1);
int _rand = 0;
Future<String> generateNewId() async {
if (_deviceIdGuidArray == null) {
_deviceIdGuidArray = List<int>(16);
var deviceId = (await Device.instance).deviceId;
deviceId = deviceId.replaceAll(_onlyHexPattern, "");
deviceId = deviceId + deviceId + deviceId + deviceId;
var idx = 0;
for (var i = 0; i < 32; i += 2) {
_deviceIdGuidArray[idx++] = int.parse(deviceId.substring(i, i + 2), radix: 16);
}
}
final now = DateTime.now().toUtc();
final guidArray = List<int>.from(_deviceIdGuidArray);
final days = now.difference(_baseDate);
final msecs = Duration(hours: now.hour, minutes: now.minute, seconds: now.second);
final daysList = Uint32List.fromList([days.inDays]);
final msecsList = Uint32List.fromList([msecs.inMilliseconds]);
final daysArray = Uint8List.view(daysList.buffer).reversed.toList();
final msecsArray = Uint8List.view(msecsList.buffer).reversed.toList();
for (var i = 0; i < 2; i++) {
guidArray[guidArray.length - 7 + i] = daysArray[daysArray.length - 2 + i];
}
for (var i = 0; i < 4; i++) {
guidArray[guidArray.length - 5 + i] = msecsArray[msecsArray.length - 4 + i];
}
guidArray[guidArray.length - 1] = _rand % 256;
guidArray[guidArray.length - 8] = (_rand >> 8) % 256;
_rand = (_rand + 1) % 65536;
final a = guidArray.take(4);
final b = guidArray.skip(4).take(2);
final c = guidArray.skip(6).take(2);
final d = guidArray.skip(8).take(2);
final e = guidArray.skip(10).take(6);
final f = List<String>();
for (final value in a) {
f.add(value.toRadixString(16).padLeft(2, "0"));
}
f.add("-");
for (final value in b) {
f.add(value.toRadixString(16).padLeft(2, "0"));
}
f.add("-");
for (final value in c) {
f.add(value.toRadixString(16).padLeft(2, "0"));
}
f.add("-");
for (final value in d) {
f.add(value.toRadixString(16).padLeft(2, "0"));
}
f.add("-");
for (final value in e) {
f.add(value.toRadixString(16).padLeft(2, "0"));
}
return f.join("");
}
Hi, thanks for the package.
Any change of making the Uuid
class constructor a constant?
We have a class that has a dependency to the Uuid
and we would like to provide a default value for it (that must be a constant).
class MyClass {
final Uuid uuid;
MyClass([this.uuid = const Uuid()]);
}
Given DartAngular web application with this simple code in web/main.dart
//import 'package:angular/angular.dart';
import 'package:dart_uuid_error_ie/app_component.template.dart' as ng;
import 'package:uuid/uuid.dart';
void main() {
print(Uuid().v1());
// runApp(ng.AppComponentNgFactory);
}
(actually it doesn't render anything into browser, only uses console)
Compile project with --release flag:
webdev serve --release
so it is compiled by dart2js instead of dartdevc
No source of cryptographically secure random numbers available.
library version: 2.0.0
dart-sdk version: 2.1.0
browser: IE 11
Thanks for your lib!
Do you know that it produces
[Warning from Dart2JS on ...]:
packages/uuid/uuid.dart:1:9:
Duplicated library name 'Uuid'.
library Uuid;
^^^^
[Warning from Dart2JS on ...]:
packages/uuid/uuid_client.dart:1:9:
Duplicated library name 'Uuid'.
library Uuid;
^^^^
When I use your package always generate same key after second time...
*This library's restrictions on the Dart version means it is incompatible with Flutter v0.8.3.
Please update this libraries restrictions to allow >v2.0.0 Dart versions.
I am using version 4.0.0-beta1-1. I have this in the dependency_overrides: section , but now i am getting this error from external package.
Error: Non-redirecting const factory invocation is not a constant expression.
const _uuid = Uuid();
Hi, I am a beginner in flutter and uuid. Assume that a uuid is generated by a users' mobile phone, and it needs to sync to the servers, where is saving many users' data. Can this package make the uuid unique for all the users' data on the servers.
Hi there @daegalus .
The 1.0.1 release of this library (consisting of e156dfe) is a breaking change since the new lowercase pi
constant is only available in the dart 2 sdk unless a polyfill such as this is used:
import 'package:dart2_constant/convert.dart' as convert;
class Uuid {
// This isn't used, I just am propogating to use of TAU over PI - http://tauday.com/tau-manifesto
static final TAU = 2 * convert.pi;
}
The only other way your change could be considered "non-breaking" for consumers is if you bumped the lower bound of your sdk dependency to something resembling ^2.0.0.dev
.
The link goes to: https://daegalus.github.com/dart-uuid/index.html
Hello and thanks for the package !
I am using Uuid.v4()
in my flutter code and i am also validating IDs with Uuid.isValidUUID(fromString: uid)
.
I have implemented the check in python :
def is_valid_uuid(uid, version=4):
"""
Check if uuid_to_test is a valid UUID.
Parameters
----------
uuid_to_test : str
version : {1, 2, 3, 4}
Returns
-------
`True` if uuid_to_test is a valid UUID, otherwise `False`.
Examples
--------
>>> is_valid_uuid('c9bf9e57-1685-4c89-bafb-ff5af830be8a')
True
>>> is_valid_uuid('c9bf9e58')
False
"""
try:
uuid_obj = uuid.UUID(uid, version=version)
except ValueError:
logging.error(f"Not a valid uuid : {uid}")
return False
return str(uuid_obj) == uid
For uuid.uuid4()
validation which "should" be the same in my bsic understanding.
Do you know what might cause the python to tell that the Uuid.v4()
is invalid?
I have a server running on Asp.Net Boilerplate and we are using its SequentialGuidGenerator.
Uuid.parse
is unable to correctly validate the Guid generated using SequentialGuidDatabaseType.SqlServer
.
I am not familiar with Guid, is this intentionally done so in dart-uuid
?
Hi, I have some suggestions to make your valuable package fit better the everyday use:
Uint8List
parse/unparse methods. Nowadays most packages uses Uint8List
when working with bytes. I know that it is easy converting it from a List<int>
but I guess it would be a plus.UuidValue
as Uint8List
instead of String
. This will avoid the problem that two Uuids that differs only because one has uppercases and the other has lowercases could be considered different. At least "canonicalize" the internal value to lowercases while creating an instance.UuidValue
class Implement == operator
and hashCode
getter.Thanks in advance.
How to use one uuid multi times?
I have a string
final String image_name = Uuid().v1.toString();
and every time I call image_name I take different value... How can I solve this?
Stack Trace: #0 Object.noSuchMethod (dart:core-patch:1838:25)
#1 AES.randomBytes (http://localhost:8084/ui/packages/uuid/aes/aes.dart:22:67)
#2 Uuid.cryptoRNG (http://localhost:8084/ui/packages/uuid/uuid.dart:78:27)
#3 Uuid.v4 (http://localhost:8084/ui/packages/uuid/uuid.dart:239:68)
String has no method charCodes method.
Ref: https://groups.google.com/a/dartlang.org/forum/#!topic/misc/JpNkRRLI9_w, google/protobuf.dart#219
More and more packages are explicitly switching to Uint8List.
Documentation comments seems to suggest that uuid.v4()
uses an AES based random source:
https://github.com/Daegalus/dart-uuid/blob/15b232b775d6e60443bd9b67bc0762fc9a0b08ef/lib/uuid.dart#L202-L203
But the code suggest that it doesn't:
https://github.com/Daegalus/dart-uuid/blob/15b232b775d6e60443bd9b67bc0762fc9a0b08ef/lib/uuid.dart#L225-L227
(or am I reading it wrong?)
Note. people are likely to rely on v4 security properties for things like generating a request nonce, etc..
This package still uses deprecated Dart 1 SCREAMING CAPS CONSTANTS. These will be removed shortly in Dart 2. This rewriting tool can be used to automatically migrate code in most cases: https://github.com/dart-lang/dart2_fix .
I’ve been using your package to generate UUIDs for some time without any issues, but today it generated the following v1 UUID: 134467e0-b6fe-11ea-d10f-5d81049d3983
. This is not a valid UUID, because the 4th block starts with d
, indicating that this is a variant 2 UUID, which is “reserved, Microsoft Corporation backward compatibility” as defined in RFC.
I doubt that you intended to generate UUIDs reserved for backward compatibility, so there seems to be a bug in your implementation.
Failed to install packet uuid under Windows 10.
Running command "pub get" under the Windows 10 leads to message:
C:\Users\micrcx\IdeaProjects\TimerTest>pub get
Resolving dependencies...
Downloading crypto 0.9.2+1...
Downloading convert 1.1.1...
Failed to rename directory because access was denied.
This may be caused by a virus scanner or having a file
in the directory open in another application.
The package is not installed. In ubuntu everything works without problems. What's the matter?
File pubspec.yaml:
name: TimerTest
version: 0.0.1
description: A simple console application.
dependencies:
uuid: 0.5.0
Any code that depends on uuid will not be strong mode clean.
I've written a PR that adds the necessary type annotations to uuid to make it strong mode clean, please take a look: #19
Thanks!
A large number of dart libraries do not have a library name. If I try to use two of them, I get a warning: "Different libraries 'a.dart' and 'b.dart' should not have the same library name ''." Please provide a library name for each file you intend to have users import.
Code
var id = Uuid.v1();
int idCardId = id.node;
Error
The following RangeError was thrown building IdApplicationsScreen(dirty):
max must be in range 0 < max ≤ 2^32, was 0
The relevant error-causing widget was:
IdApplicationsScreen file:///home/koha/Projects/sirajulhuda_app/lib/main.dart:37:48
When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 212:49 throw_
dart-sdk/lib/_internal/js_dev_runtime/patch/math_patch.dart 314:7 nextInt
packages/better_uuid/uuid_config.dart 29:29 generate
packages/better_uuid/uuid.dart 108:18 v1
packages/sirajulhuda_app/screens/id_applications_screen.dart 12:19 build
flutter-doctor
[✓] Flutter (Channel beta, 1.21.0-9.1.pre, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Chrome - develop for the web
[!] Android Studio (version 4.0)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] Connected device (2 available)
! Doctor found issues in 1 category.
According to the following announcement, it's time to publish a stable null safe release:
https://medium.com/dartlang/preparing-the-dart-and-flutter-ecosystem-for-null-safety-e550ce72c010
App uses an insecure Random Number Generator - issue mention in the scan report by MOBSF.
Please look in this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.