feat: add alot
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import 'dart:io';
|
||||
import 'dart:async';
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../database/app_database.dart';
|
||||
|
||||
@@ -52,7 +54,9 @@ class DefaultProductSeeder {
|
||||
imagePath = await _copyBundledImage(name, imagesDir);
|
||||
}
|
||||
|
||||
await database.into(database.products).insert(
|
||||
await database
|
||||
.into(database.products)
|
||||
.insert(
|
||||
ProductsCompanion.insert(
|
||||
id: uuid.v4(),
|
||||
name: name,
|
||||
@@ -67,7 +71,7 @@ class DefaultProductSeeder {
|
||||
});
|
||||
} catch (e, stack) {
|
||||
debugPrint('DefaultProductSeeder: seedIfEmpty error: $e');
|
||||
Sentry.captureException(e, stackTrace: stack);
|
||||
unawaited(Sentry.captureException(e, stackTrace: stack));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +99,10 @@ class DefaultProductSeeder {
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> _copyBundledImage(String productName, Directory imagesDir) async {
|
||||
Future<String?> _copyBundledImage(
|
||||
String productName,
|
||||
Directory imagesDir,
|
||||
) async {
|
||||
final slug = _toSlug(productName);
|
||||
|
||||
for (final ext in ['png', 'jpg', 'webp']) {
|
||||
@@ -107,10 +114,9 @@ class DefaultProductSeeder {
|
||||
final destPath = path.join(imagesDir.path, fileName);
|
||||
final destFile = File(destPath);
|
||||
|
||||
await destFile.writeAsBytes(bytes.buffer.asUint8List(
|
||||
bytes.offsetInBytes,
|
||||
bytes.lengthInBytes,
|
||||
));
|
||||
await destFile.writeAsBytes(
|
||||
bytes.buffer.asUint8List(bytes.offsetInBytes, bytes.lengthInBytes),
|
||||
);
|
||||
|
||||
return destPath;
|
||||
} catch (_) {
|
||||
@@ -118,8 +124,10 @@ class DefaultProductSeeder {
|
||||
}
|
||||
}
|
||||
|
||||
debugPrint('DefaultProductSeeder: no bundled image found for "$productName" '
|
||||
'(looked for assets/products/$slug.{png,jpg,webp})');
|
||||
debugPrint(
|
||||
'DefaultProductSeeder: no bundled image found for "$productName" '
|
||||
'(looked for assets/products/$slug.{png,jpg,webp})',
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user