Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
4605b51a
Unverified
Commit
4605b51a
authored
Mar 30, 2020
by
Jonah Williams
Committed by
GitHub
Mar 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] use package Uuid consistently (#53492)
parent
57d7946b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
5 additions
and
98 deletions
+5
-98
utils.dart
packages/flutter_tools/lib/src/base/utils.dart
+1
-35
create.dart
packages/flutter_tools/lib/src/commands/create.dart
+2
-1
daemon.dart
packages/flutter_tools/lib/src/commands/daemon.dart
+2
-1
utils_test.dart
packages/flutter_tools/test/general.shard/utils_test.dart
+0
-61
No files found.
packages/flutter_tools/lib/src/base/utils.dart
View file @
4605b51a
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
// found in the LICENSE file.
// found in the LICENSE file.
import
'dart:async'
;
import
'dart:async'
;
import
'dart:math'
show
Random
,
max
;
import
'dart:math'
show
max
;
import
'package:intl/intl.dart'
;
import
'package:intl/intl.dart'
;
import
'package:meta/meta.dart'
;
import
'package:meta/meta.dart'
;
...
@@ -141,40 +141,6 @@ class SettingsFile {
...
@@ -141,40 +141,6 @@ class SettingsFile {
}
}
}
}
/// A UUID generator. This will generate unique IDs in the format:
///
/// f47ac10b-58cc-4372-a567-0e02b2c3d479
///
/// The generated UUIDs are 128 bit numbers encoded in a specific string format.
///
/// For more information, see
/// http://en.wikipedia.org/wiki/Universally_unique_identifier.
class
Uuid
{
final
Random
_random
=
Random
();
/// Generate a version 4 (random) UUID. This is a UUID scheme that only uses
/// random numbers as the source of the generated UUID.
String
generateV4
()
{
// Generate xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx / 8-4-4-4-12.
final
int
special
=
8
+
_random
.
nextInt
(
4
);
return
'
${_bitsDigits(16, 4)}${_bitsDigits(16, 4)}
-'
'
${_bitsDigits(16, 4)}
-'
'4
${_bitsDigits(12, 3)}
-'
'
${_printDigits(special, 1)}${_bitsDigits(12, 3)}
-'
'
${_bitsDigits(16, 4)}${_bitsDigits(16, 4)}${_bitsDigits(16, 4)}
'
;
}
String
_bitsDigits
(
int
bitCount
,
int
digitCount
)
=>
_printDigits
(
_generateBits
(
bitCount
),
digitCount
);
int
_generateBits
(
int
bitCount
)
=>
_random
.
nextInt
(
1
<<
bitCount
);
String
_printDigits
(
int
value
,
int
count
)
=>
value
.
toRadixString
(
16
).
padLeft
(
count
,
'0'
);
}
/// Given a data structure which is a Map of String to dynamic values, return
/// Given a data structure which is a Map of String to dynamic values, return
/// the same structure (`Map<String, dynamic>`) with the correct runtime types.
/// the same structure (`Map<String, dynamic>`) with the correct runtime types.
Map
<
String
,
dynamic
>
castStringKeyedMap
(
dynamic
untyped
)
{
Map
<
String
,
dynamic
>
castStringKeyedMap
(
dynamic
untyped
)
{
...
...
packages/flutter_tools/lib/src/commands/create.dart
View file @
4605b51a
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
import
'dart:async'
;
import
'dart:async'
;
import
'package:meta/meta.dart'
;
import
'package:meta/meta.dart'
;
import
'package:uuid/uuid.dart'
;
import
'../android/android.dart'
as
android
;
import
'../android/android.dart'
as
android
;
import
'../android/android_sdk.dart'
as
android_sdk
;
import
'../android/android_sdk.dart'
as
android_sdk
;
...
@@ -610,7 +611,7 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi
...
@@ -610,7 +611,7 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi
'pluginClass'
:
pluginClass
,
'pluginClass'
:
pluginClass
,
'pluginDartClass'
:
pluginDartClass
,
'pluginDartClass'
:
pluginDartClass
,
'pluginCppHeaderGuard'
:
projectName
.
toUpperCase
(),
'pluginCppHeaderGuard'
:
projectName
.
toUpperCase
(),
'pluginProjectUUID'
:
Uuid
().
generateV
4
().
toUpperCase
(),
'pluginProjectUUID'
:
Uuid
().
v
4
().
toUpperCase
(),
'withPluginHook'
:
withPluginHook
,
'withPluginHook'
:
withPluginHook
,
'androidLanguage'
:
androidLanguage
,
'androidLanguage'
:
androidLanguage
,
'iosLanguage'
:
iosLanguage
,
'iosLanguage'
:
iosLanguage
,
...
...
packages/flutter_tools/lib/src/commands/daemon.dart
View file @
4605b51a
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
import
'dart:async'
;
import
'dart:async'
;
import
'package:meta/meta.dart'
;
import
'package:meta/meta.dart'
;
import
'package:uuid/uuid.dart'
;
import
'../base/common.dart'
;
import
'../base/common.dart'
;
import
'../base/context.dart'
;
import
'../base/context.dart'
;
...
@@ -439,7 +440,7 @@ class AppDomain extends Domain {
...
@@ -439,7 +440,7 @@ class AppDomain extends Domain {
static
final
Uuid
_uuidGenerator
=
Uuid
();
static
final
Uuid
_uuidGenerator
=
Uuid
();
static
String
_getNewAppId
()
=>
_uuidGenerator
.
generateV
4
();
static
String
_getNewAppId
()
=>
_uuidGenerator
.
v
4
();
final
List
<
AppInstance
>
_apps
=
<
AppInstance
>[];
final
List
<
AppInstance
>
_apps
=
<
AppInstance
>[];
...
...
packages/flutter_tools/test/general.shard/utils_test.dart
View file @
4605b51a
...
@@ -24,67 +24,6 @@ baz=qux
...
@@ -24,67 +24,6 @@ baz=qux
});
});
});
});
group
(
'uuid'
,
()
{
// xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
test
(
'simple'
,
()
{
final
Uuid
uuid
=
Uuid
();
final
String
result
=
uuid
.
generateV4
();
expect
(
result
.
length
,
36
);
expect
(
result
[
8
],
'-'
);
expect
(
result
[
13
],
'-'
);
expect
(
result
[
18
],
'-'
);
expect
(
result
[
23
],
'-'
);
});
test
(
'can parse'
,
()
{
final
Uuid
uuid
=
Uuid
();
final
String
result
=
uuid
.
generateV4
();
expect
(
int
.
parse
(
result
.
substring
(
0
,
8
),
radix:
16
),
isNotNull
);
expect
(
int
.
parse
(
result
.
substring
(
9
,
13
),
radix:
16
),
isNotNull
);
expect
(
int
.
parse
(
result
.
substring
(
14
,
18
),
radix:
16
),
isNotNull
);
expect
(
int
.
parse
(
result
.
substring
(
19
,
23
),
radix:
16
),
isNotNull
);
expect
(
int
.
parse
(
result
.
substring
(
24
,
36
),
radix:
16
),
isNotNull
);
});
test
(
'special bits'
,
()
{
final
Uuid
uuid
=
Uuid
();
String
result
=
uuid
.
generateV4
();
expect
(
result
[
14
],
'4'
);
expect
(
result
[
19
].
toLowerCase
(),
isIn
(
'89ab'
));
result
=
uuid
.
generateV4
();
expect
(
result
[
19
].
toLowerCase
(),
isIn
(
'89ab'
));
result
=
uuid
.
generateV4
();
expect
(
result
[
19
].
toLowerCase
(),
isIn
(
'89ab'
));
});
test
(
'is pretty random'
,
()
{
final
Set
<
String
>
set
=
<
String
>{};
Uuid
uuid
=
Uuid
();
for
(
int
i
=
0
;
i
<
64
;
i
++)
{
final
String
val
=
uuid
.
generateV4
();
expect
(
set
,
isNot
(
contains
(
val
)));
set
.
add
(
val
);
}
uuid
=
Uuid
();
for
(
int
i
=
0
;
i
<
64
;
i
++)
{
final
String
val
=
uuid
.
generateV4
();
expect
(
set
,
isNot
(
contains
(
val
)));
set
.
add
(
val
);
}
uuid
=
Uuid
();
for
(
int
i
=
0
;
i
<
64
;
i
++)
{
final
String
val
=
uuid
.
generateV4
();
expect
(
set
,
isNot
(
contains
(
val
)));
set
.
add
(
val
);
}
});
});
group
(
'Version'
,
()
{
group
(
'Version'
,
()
{
test
(
'can parse and compare'
,
()
{
test
(
'can parse and compare'
,
()
{
expect
(
Version
.
unknown
.
toString
(),
equals
(
'unknown'
));
expect
(
Version
.
unknown
.
toString
(),
equals
(
'unknown'
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment