-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
265 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import 'package:uuid/uuid.dart'; | ||
|
||
import 'uuid_bit_layout.dart'; | ||
|
||
class UuidAnalysis extends UuidValue { | ||
UuidAnalysis(super.uuid) { | ||
super.validate(); | ||
} | ||
|
||
String get variant { | ||
String variantByte = uuid.substring(19, 20).toUpperCase(); | ||
|
||
int? variantInt = int.tryParse(variantByte); | ||
if (variantInt != null && variantInt >= 1 && variantInt <= 7) { | ||
return '为 NCS 兼容性保留'; | ||
} else if (["8", "9", "A", "B"].contains(variantByte)) { | ||
return '在 RFC 9562 中指定'; | ||
} else if (["C", "D"].contains(variantByte)) { | ||
return '为与 Microsoft 兼容而保留'; | ||
} else if (["E", "F"].contains(variantByte)) { | ||
return '保留以供将来定义'; | ||
} else { | ||
return "未知变种"; | ||
} | ||
} | ||
|
||
int get timeLow { | ||
return int.parse(uuid.substring(0, 8), radix: 16); | ||
} | ||
|
||
int get timeMid { | ||
return int.parse(uuid.substring(9, 13), radix: 16); | ||
} | ||
|
||
int get timeHigh { | ||
return int.parse(uuid.substring(14, 18), radix: 16); | ||
} | ||
|
||
@override | ||
int get time { | ||
if (version == 1) { | ||
return ((timeHigh & 0xfff) << 48) | (timeMid << 32) | timeLow; | ||
} | ||
if (version == 6) { | ||
return (timeLow << 28) | (timeMid << 12) | ((timeLow & 0x0FFF)); | ||
} | ||
if (version == 7) { | ||
return int.parse(uuid.substring(0, 8) + uuid.substring(9, 13), radix: 16); | ||
} | ||
return -1; | ||
} | ||
|
||
String get bitLayout { | ||
return switch (version) { | ||
1 => UuidBitLayout.v1, | ||
3 => UuidBitLayout.v3, | ||
4 => UuidBitLayout.v4, | ||
5 => UuidBitLayout.v5, | ||
6 => UuidBitLayout.v6, | ||
7 => UuidBitLayout.v7, | ||
8 => UuidBitLayout.v8, | ||
_ => "未知版本" | ||
}; | ||
} | ||
|
||
DateTime get timeValue { | ||
if ([1, 6].contains(version)) { | ||
return DateTime.utc(1582, 10, 15).add(Duration(microseconds: time ~/ 10)); | ||
} | ||
if (version == 7) { | ||
return DateTime.fromMillisecondsSinceEpoch(time, isUtc: true); | ||
} | ||
return DateTime.fromMillisecondsSinceEpoch(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
class UuidBitLayout { | ||
static const String v1 = """ | ||
0 1 2 3 | ||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| time_low | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| time_mid | ver | time_high | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
|var| clock_seq | node | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| node | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
"""; | ||
|
||
static const String v3 = """ | ||
0 1 2 3 | ||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| md5_high | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| md5_high | ver | md5_mid | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
|var| md5_low | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| md5_low | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
"""; | ||
|
||
static const String v4 = """ | ||
0 1 2 3 | ||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| random_a | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| random_a | ver | random_b | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
|var| random_c | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| random_c | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
"""; | ||
|
||
static const String v5 = """ | ||
0 1 2 3 | ||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| sha1_high | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| sha1_high | ver | sha1_mid | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
|var| sha1_low | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| sha1_low | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
"""; | ||
|
||
static const String v6 = """ | ||
0 1 2 3 | ||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| time_high | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| time_mid | ver | time_low | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
|var| clock_seq | node | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| node | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
"""; | ||
|
||
static const String v7 = """ | ||
0 1 2 3 | ||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| unix_ts_ms | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| unix_ts_ms | ver | rand_a | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
|var| rand_b | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| rand_b | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
"""; | ||
|
||
static const String v8 = """ | ||
0 1 2 3 | ||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| custom_a | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| custom_a | ver | custom_b | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
|var| custom_c | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| custom_c | | ||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
"""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:refreshed/refreshed.dart'; | ||
import 'package:tools/utils/uuid/uuid_analysis.dart'; | ||
|
||
class UuidToolsController extends GetxController { | ||
final TextEditingController textEditingController = TextEditingController(); | ||
|
||
final RxString helper = "".obs; | ||
|
||
final Rx<Color> borderColor = Rx<Color>(Colors.grey); | ||
|
||
void onEditingComplete() { | ||
try { | ||
final UuidAnalysis analysis = UuidAnalysis(textEditingController.text); | ||
} catch (e) { | ||
if (e is FormatException) { | ||
borderColor.value = Colors.red; | ||
// textEditingController. | ||
helper.value = "UUID格式错误"; | ||
update(); | ||
} | ||
print(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:refreshed/refreshed.dart'; | ||
import 'package:tools/uuid_tools/controller.dart'; | ||
|
||
class UuidToolsPage extends StatelessWidget { | ||
const UuidToolsPage({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return GetBuilder<UuidToolsController>( | ||
init: UuidToolsController(), | ||
builder: (UuidToolsController controller) { | ||
return Center( | ||
child: TextField( | ||
controller: controller.textEditingController, | ||
// onChanged: controller.onChanged, | ||
onEditingComplete: controller.onEditingComplete, | ||
|
||
/// 输入框样式 | ||
decoration: InputDecoration( | ||
/// 输入框内部填充 | ||
// label: const Text("UUID"), | ||
labelText: "请在此处输入需要解析的UUID", | ||
// labelStyle: const TextStyle(color: Colors.grey), | ||
helper: ValueListenableBuilder<String>( | ||
valueListenable: controller.helper, | ||
builder: (BuildContext context, String value, Widget? child) { | ||
return Text( | ||
controller.helper.value, | ||
style: const TextStyle(color: Colors.grey), | ||
); | ||
}, | ||
), | ||
contentPadding: const EdgeInsets.all(10), | ||
|
||
/// 输入框边框 | ||
border: OutlineInputBorder( | ||
borderRadius: BorderRadius.circular(10), | ||
borderSide: | ||
BorderSide(color: controller.borderColor.value)), | ||
|
||
/// 输入框填充颜色 | ||
filled: true, | ||
|
||
/// 输入框提示文字 | ||
hintText: "请在此处输入需要解析的UUID", | ||
|
||
/// 输入框提示文字样式 | ||
hintStyle: const TextStyle(color: Colors.grey), | ||
), | ||
), | ||
); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters