
Configures the ObjectBox ProductEntity to allow assigning IDs. Adds a helper to convert ProductStruct to ProductEntity for easier storage. Saves scanned products directly to the local ObjectBox store. Updates the ProductListPage to fetch and display locally stored products from ObjectBox upon initialization. Includes minor UI adjustments in the scanned product component and scanner page, and fixes loading state handling in HomePageModel.
248 lines
7.8 KiB
Dart
248 lines
7.8 KiB
Dart
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
// This code was generated by ObjectBox. To update it run the generator again
|
|
// with `dart run build_runner build`.
|
|
// See also https://docs.objectbox.io/getting-started#generate-objectbox-code
|
|
|
|
// ignore_for_file: camel_case_types, depend_on_referenced_packages
|
|
// coverage:ignore-file
|
|
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
|
import 'package:objectbox/internal.dart'
|
|
as obx_int; // generated code can access "internal" functionality
|
|
import 'package:objectbox/objectbox.dart' as obx;
|
|
import 'package:objectbox_flutter_libs/objectbox_flutter_libs.dart';
|
|
|
|
import '../../backend/objectbox/entities/product/product_entity.dart';
|
|
|
|
export 'package:objectbox/objectbox.dart'; // so that callers only have to import this file
|
|
|
|
final _entities = <obx_int.ModelEntity>[
|
|
obx_int.ModelEntity(
|
|
id: const obx_int.IdUid(1, 6757833172062715556),
|
|
name: 'ProductEntity',
|
|
lastPropertyId: const obx_int.IdUid(7, 1825580906382154543),
|
|
flags: 0,
|
|
properties: <obx_int.ModelProperty>[
|
|
obx_int.ModelProperty(
|
|
id: const obx_int.IdUid(1, 1853465479129290672),
|
|
name: 'id',
|
|
type: 6,
|
|
flags: 129,
|
|
),
|
|
obx_int.ModelProperty(
|
|
id: const obx_int.IdUid(2, 4521897043130066476),
|
|
name: 'code',
|
|
type: 9,
|
|
flags: 0,
|
|
),
|
|
obx_int.ModelProperty(
|
|
id: const obx_int.IdUid(3, 2561289170534233438),
|
|
name: 'name',
|
|
type: 9,
|
|
flags: 0,
|
|
),
|
|
obx_int.ModelProperty(
|
|
id: const obx_int.IdUid(4, 6084891210993334692),
|
|
name: 'description',
|
|
type: 9,
|
|
flags: 0,
|
|
),
|
|
obx_int.ModelProperty(
|
|
id: const obx_int.IdUid(5, 883454706727408240),
|
|
name: 'price',
|
|
type: 9,
|
|
flags: 0,
|
|
),
|
|
obx_int.ModelProperty(
|
|
id: const obx_int.IdUid(6, 7033704955625644592),
|
|
name: 'quantity',
|
|
type: 9,
|
|
flags: 0,
|
|
),
|
|
obx_int.ModelProperty(
|
|
id: const obx_int.IdUid(7, 1825580906382154543),
|
|
name: 'image',
|
|
type: 9,
|
|
flags: 0,
|
|
),
|
|
],
|
|
relations: <obx_int.ModelRelation>[],
|
|
backlinks: <obx_int.ModelBacklink>[],
|
|
),
|
|
];
|
|
|
|
/// Shortcut for [obx.Store.new] that passes [getObjectBoxModel] and for Flutter
|
|
/// apps by default a [directory] using `defaultStoreDirectory()` from the
|
|
/// ObjectBox Flutter library.
|
|
///
|
|
/// Note: for desktop apps it is recommended to specify a unique [directory].
|
|
///
|
|
/// See [obx.Store.new] for an explanation of all parameters.
|
|
///
|
|
/// For Flutter apps, also calls `loadObjectBoxLibraryAndroidCompat()` from
|
|
/// the ObjectBox Flutter library to fix loading the native ObjectBox library
|
|
/// on Android 6 and older.
|
|
Future<obx.Store> openStore({
|
|
String? directory,
|
|
int? maxDBSizeInKB,
|
|
int? maxDataSizeInKB,
|
|
int? fileMode,
|
|
int? maxReaders,
|
|
bool queriesCaseSensitiveDefault = true,
|
|
String? macosApplicationGroup,
|
|
}) async {
|
|
await loadObjectBoxLibraryAndroidCompat();
|
|
return obx.Store(
|
|
getObjectBoxModel(),
|
|
directory: directory ?? (await defaultStoreDirectory()).path,
|
|
maxDBSizeInKB: maxDBSizeInKB,
|
|
maxDataSizeInKB: maxDataSizeInKB,
|
|
fileMode: fileMode,
|
|
maxReaders: maxReaders,
|
|
queriesCaseSensitiveDefault: queriesCaseSensitiveDefault,
|
|
macosApplicationGroup: macosApplicationGroup,
|
|
);
|
|
}
|
|
|
|
/// Returns the ObjectBox model definition for this project for use with
|
|
/// [obx.Store.new].
|
|
obx_int.ModelDefinition getObjectBoxModel() {
|
|
final model = obx_int.ModelInfo(
|
|
entities: _entities,
|
|
lastEntityId: const obx_int.IdUid(1, 6757833172062715556),
|
|
lastIndexId: const obx_int.IdUid(0, 0),
|
|
lastRelationId: const obx_int.IdUid(0, 0),
|
|
lastSequenceId: const obx_int.IdUid(0, 0),
|
|
retiredEntityUids: const [],
|
|
retiredIndexUids: const [],
|
|
retiredPropertyUids: const [],
|
|
retiredRelationUids: const [],
|
|
modelVersion: 5,
|
|
modelVersionParserMinimum: 5,
|
|
version: 1,
|
|
);
|
|
|
|
final bindings = <Type, obx_int.EntityDefinition>{
|
|
ProductEntity: obx_int.EntityDefinition<ProductEntity>(
|
|
model: _entities[0],
|
|
toOneRelations: (ProductEntity object) => [],
|
|
toManyRelations: (ProductEntity object) => {},
|
|
getId: (ProductEntity object) => object.id,
|
|
setId: (ProductEntity object, int id) {
|
|
object.id = id;
|
|
},
|
|
objectToFB: (ProductEntity object, fb.Builder fbb) {
|
|
final codeOffset = object.code == null
|
|
? null
|
|
: fbb.writeString(object.code!);
|
|
final nameOffset = object.name == null
|
|
? null
|
|
: fbb.writeString(object.name!);
|
|
final descriptionOffset = object.description == null
|
|
? null
|
|
: fbb.writeString(object.description!);
|
|
final priceOffset = object.price == null
|
|
? null
|
|
: fbb.writeString(object.price!);
|
|
final quantityOffset = object.quantity == null
|
|
? null
|
|
: fbb.writeString(object.quantity!);
|
|
final imageOffset = object.image == null
|
|
? null
|
|
: fbb.writeString(object.image!);
|
|
fbb.startTable(8);
|
|
fbb.addInt64(0, object.id);
|
|
fbb.addOffset(1, codeOffset);
|
|
fbb.addOffset(2, nameOffset);
|
|
fbb.addOffset(3, descriptionOffset);
|
|
fbb.addOffset(4, priceOffset);
|
|
fbb.addOffset(5, quantityOffset);
|
|
fbb.addOffset(6, imageOffset);
|
|
fbb.finish(fbb.endTable());
|
|
return object.id;
|
|
},
|
|
objectFromFB: (obx.Store store, ByteData fbData) {
|
|
final buffer = fb.BufferContext(fbData);
|
|
final rootOffset = buffer.derefObject(0);
|
|
final idParam = const fb.Int64Reader().vTableGet(
|
|
buffer,
|
|
rootOffset,
|
|
4,
|
|
0,
|
|
);
|
|
final codeParam = const fb.StringReader(
|
|
asciiOptimization: true,
|
|
).vTableGetNullable(buffer, rootOffset, 6);
|
|
final nameParam = const fb.StringReader(
|
|
asciiOptimization: true,
|
|
).vTableGetNullable(buffer, rootOffset, 8);
|
|
final descriptionParam = const fb.StringReader(
|
|
asciiOptimization: true,
|
|
).vTableGetNullable(buffer, rootOffset, 10);
|
|
final priceParam = const fb.StringReader(
|
|
asciiOptimization: true,
|
|
).vTableGetNullable(buffer, rootOffset, 12);
|
|
final quantityParam = const fb.StringReader(
|
|
asciiOptimization: true,
|
|
).vTableGetNullable(buffer, rootOffset, 14);
|
|
final imageParam = const fb.StringReader(
|
|
asciiOptimization: true,
|
|
).vTableGetNullable(buffer, rootOffset, 16);
|
|
final object = ProductEntity(
|
|
id: idParam,
|
|
code: codeParam,
|
|
name: nameParam,
|
|
description: descriptionParam,
|
|
price: priceParam,
|
|
quantity: quantityParam,
|
|
image: imageParam,
|
|
);
|
|
|
|
return object;
|
|
},
|
|
),
|
|
};
|
|
|
|
return obx_int.ModelDefinition(model, bindings);
|
|
}
|
|
|
|
/// [ProductEntity] entity fields to define ObjectBox queries.
|
|
class ProductEntity_ {
|
|
/// See [ProductEntity.id].
|
|
static final id = obx.QueryIntegerProperty<ProductEntity>(
|
|
_entities[0].properties[0],
|
|
);
|
|
|
|
/// See [ProductEntity.code].
|
|
static final code = obx.QueryStringProperty<ProductEntity>(
|
|
_entities[0].properties[1],
|
|
);
|
|
|
|
/// See [ProductEntity.name].
|
|
static final name = obx.QueryStringProperty<ProductEntity>(
|
|
_entities[0].properties[2],
|
|
);
|
|
|
|
/// See [ProductEntity.description].
|
|
static final description = obx.QueryStringProperty<ProductEntity>(
|
|
_entities[0].properties[3],
|
|
);
|
|
|
|
/// See [ProductEntity.price].
|
|
static final price = obx.QueryStringProperty<ProductEntity>(
|
|
_entities[0].properties[4],
|
|
);
|
|
|
|
/// See [ProductEntity.quantity].
|
|
static final quantity = obx.QueryStringProperty<ProductEntity>(
|
|
_entities[0].properties[5],
|
|
);
|
|
|
|
/// See [ProductEntity.image].
|
|
static final image = obx.QueryStringProperty<ProductEntity>(
|
|
_entities[0].properties[6],
|
|
);
|
|
}
|