Définit les tables Drift et les identifiants locaux (local_id.dart, tables.dart), régénère app_database.g.dart. build_runner, flutter analyze et build APK debug validés. Versionne les fichiers générés .g.dart : projet solo sans pipeline CI qui relance build_runner, on privilégie un clone immédiatement buildable. Retire la règle **/*.g.dart (et freezed/gr.dart, non utilisés) du .gitignore en conséquence. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
29 lines
810 B
Dart
29 lines
810 B
Dart
import 'dart:math';
|
|
|
|
const _crockfordBase32 = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
|
|
|
|
final class LocalIdGenerator {
|
|
LocalIdGenerator({Random? random}) : _random = random ?? Random.secure();
|
|
|
|
final Random _random;
|
|
|
|
String newUlid({DateTime? now}) {
|
|
final timestamp = (now ?? DateTime.now().toUtc()).millisecondsSinceEpoch;
|
|
final buffer = StringBuffer();
|
|
|
|
var remainingTimestamp = timestamp;
|
|
final timestampChars = List<String>.filled(10, '0');
|
|
for (var index = 9; index >= 0; index--) {
|
|
timestampChars[index] = _crockfordBase32[remainingTimestamp & 0x1F];
|
|
remainingTimestamp >>= 5;
|
|
}
|
|
buffer.writeAll(timestampChars);
|
|
|
|
for (var index = 0; index < 16; index++) {
|
|
buffer.write(_crockfordBase32[_random.nextInt(32)]);
|
|
}
|
|
|
|
return buffer.toString();
|
|
}
|
|
}
|