v4 method
- @Deprecated('use config instead. Removal in 5.0.0') Map<
String, dynamic> ? options, - V4Options? config,
Generates a RNG version 4 UUID
By default it will generate a string based cryptoRNG, and will return a string. If you wish to use crypto-strong RNG, pass in UuidUtil.cryptoRNG
The first argument is an options map that takes various configuration options detailed in the readme. This is going to be eventually deprecated.
The second argument is a V4Options object that takes the same options as the options map. This is the preferred way to pass options.
http://tools.ietf.org/html/rfc4122.html#section-4.4
Example: Generate string UUID with different RNG method
import 'package:uuid/uuid_util.dart';
uuid.v4(options: {
'rng': UuidUtil.cryptoRNG
});
// -> "109156be-c4fb-41ea-b1b4-efe1671c5836"
Example: Generate string UUID with different RNG method and named parameters
import 'package:uuid/uuid_util.dart';
uuid.v4(options: {
'rng': UuidUtil.mathRNG,
'namedArgs': new Map.fromIterables([const Symbol('seed')],[1])
});
// -> "09a91894-e93f-4141-a3ec-82eb32f2a3ef"
Example: Generate string UUID with different RNG method and positional parameters
import 'package:uuid/uuid_util.dart';
uuid.v4(options: {
'rng': UuidUtil.cryptoRNG,
'positionalArgs': [1]
});
// -> "09a91894-e93f-4141-a3ec-82eb32f2a3ef"
Example: Generate string UUID with fully-specified options
uuid.v4(options: {
'random': [
0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0xc1, 0xea,
0x71, 0xb4, 0xef, 0xe1, 0x67, 0x1c, 0x58, 0x36
]
});
// -> "109156be-c4fb-41ea-b1b4-efe1671c5836"
Implementation
String v4(
{@Deprecated('use config instead. Removal in 5.0.0')
Map<String, dynamic>? options,
V4Options? config}) {
if (options != null && options.isNotEmpty) {
var rng = options["rng"];
if (options["rng"] != null && options["rng"] is! RNG) {
rng = LegacyRNG(
options["rng"], options["namedArgs"], options["positionalArgs"]);
}
config = V4Options(options["random"], rng);
}
return UuidV4(goptions: goptions).generate(options: config);
}