
Enables viewing and editing existing product details by passing the product ID to the form page. The form now loads and displays the product data based on the provided ID. Adds a delete button to each item in the product list, allowing users to remove products directly from the list view. Updates navigation from the product list and scanner pages to pass the product ID when navigating to the product form. Includes minor code style changes by applying the `sort_constructors_first` lint rule and updates dependencies (`flutter_lints`, `lints`).
36 lines
1.0 KiB
Dart
36 lines
1.0 KiB
Dart
import 'dart:io';
|
|
import 'package:path/path.dart' as p;
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
import 'package:barcode_scanner/backend/objectbox/objectbox.g.dart';
|
|
export 'package:barcode_scanner/backend/objectbox/objectbox.g.dart';
|
|
|
|
late ObjectboxManager objectboxManager;
|
|
|
|
class ObjectboxManager {
|
|
ObjectboxManager._create(this.store);
|
|
|
|
/// The Store of this app.
|
|
late final Store store;
|
|
|
|
/// Create an instance of ObjectBox to use throughout the app.
|
|
static Future<ObjectboxManager> create() async {
|
|
Directory directory;
|
|
if (Platform.isIOS) {
|
|
directory = await getLibraryDirectory();
|
|
} else {
|
|
directory = await getApplicationSupportDirectory();
|
|
}
|
|
// Future<Store> openStore() {...} is defined in the generated objectbox.g.dart
|
|
final store = await openStore(
|
|
directory: p.join(directory.path, "objectbox_db"),
|
|
);
|
|
return ObjectboxManager._create(store);
|
|
}
|
|
|
|
/// Call it before `runApp()` in main.dart
|
|
static Future init() async {
|
|
objectboxManager = await ObjectboxManager.create();
|
|
}
|
|
}
|