Creating model: lib/objectbox-model.json - flutter

I am trying to create a Objectbox model in flutter app
But it shows me the following error
/////////////
\[INFO\] Generating build script completed, took 221ms
\[INFO\] Reading cached asset graph completed, took 46ms
\[INFO\] Checking for updates since last build completed, took 521ms
\[WARNING\] objectbox_generator:generator on lib/$lib$:
Creating model: lib/objectbox-model.json
\[INFO\] Running build completed, took 7.7s
\[INFO\] Caching finalized dependency graph completed, took 24ms
\[INFO\] Succeeded after 7.7s with 1 outputs (5 actions)
////////////////
my model:
#Entity()
class Templates {
#Id()
int id = 0;
String? templateId;
String? templateName;
String? valuables;
}
#Entity()
class Services {
#Id()
int id = 0;
String? serviceId;
String? serviceName;
}

Related

skipping data entries in a for loop in dart

a for loop runs to enter the data from an API call into a class the calls work fine but suddenly skip a few entries or enter previous entries into the list causing data to be lost.
for( int i = 0; i < pinarray.length; i++) {
String value = pinarray[i];
//print(value);
final response = await http.get(Uri.parse('http://api/api/getPin/?id=$value'));
final pinsData = json.decode(response.body) as Map<String, dynamic>;
print(pinsData);
//the problem is here
viewPins.add(Pin(
id: pinsData['id'],
location: pinsData['location'],
description: pinsData['description'],
qrcode: pinsData['qrcode'],
ttl: pinsData['ttl'],
tier: pinsData['tier'],
type: pinsData['type'],
user: pinsData['user'],
images: pinsData['images'],
viewable_users: pinsData['viewable_users']));
//print(i);
print(viewPins[i].id);
pincount = i;
}
the print(viewPins) shows that the wrong data is fetched but the data is still correct before it is entered into the list, there was a setState also in the code but was removed to see if it caused the problem but the issue remained.

Problem with Hive while saving the information

Wanna make function which will save the information after clicking the buttom (Save)
But Hive gives error...Screen of VS
Error is in this line:
static Box notes = Hive.box(HiveKeys.notesKey);
Exception has occurred.
HiveError (HiveError: The box "notes" is already open and of type Box.)
First of all you can not directly type hive data into a specific model. You need to get data from the box as dynamic and then cast that data to desired type, and the second thing is it seems that you have already opened this box somewhere in your code. It would be nice if you can share the code where you have opened hive box
If you want to store data in list form then please follow below step
Step 1: put in main.dart file
await Hive.openBox<List>("hiveTable");
Step 2: make a model class that contains the adapter of the hive
part 'hive_clean_entity.freezed.dart';
part 'hive_clean_entity.g.dart';
#freezed
#HiveType(typeId: 6, adapterName: "ContactCleanHiveAdapter")
#freezed
class HiveCleanEntity with _$HiveCleanEntity {
const factory HiveCleanEntity({
#HiveField(0) #Default("") String contactId,
#HiveField(1) #Default("") String displayName,
#HiveField(2) #Default("") String givenName,
#HiveField(3) #Default("") String phoneNumber,
}) = _HiveCleanEntity;
factory HiveCleanEntity.initial() => const HiveCleanEntity(
contactId: "",
displayName: "",
givenName: "",
phoneNumber: "",
);
}
like this - you can pass typeId of your choice
Step 3: run the build_runner command so they generate 2 file of model dto
flutter pub run build_runner watch --delete-conflicting-outputs
Step 4: Now open box where you want to store data :
ListHiveCleanEntity putlist = [];
HiveCleanEntity hiveCleanEntity =
HiveCleanEntity(
contactId: “1”,
displayName: "2",
givenName: "xyz",
phoneNumber:”+91”);
putlist.add(hiveCleanEntity);
final cleanContactBox = Hive.box<List>("hiveTable");
cleanContactBox.put("subTable",putlist);
Step 5: getting data into local storage
final list = cleanContactBox.get("subTable")?.cast<HiveCleanEntity>() ?? [];

Why tests passes individually and fail on terminal CLI execution?

I'm writting tests to ensure a set of initialization rules on an object with an optional parameter, like the one below:
part 'example.g.dart';
#JsonSerializable(createToJson: false)
class Example {
String req1;
String req2;
String? opt;
Example({required this.req1, required this.req2, this.opt});
factory Example.fromJson(Map<String, dynamic> json) =>
_$ExampleFromJson(json);
}
My .g.dart is the following:
Example _$ExampleFromJson(Map<String, dynamic> json) {
return Example(
req1: json['req1'] as String,
req2: json['req2'] as String,
opt: json['opt'] as String?,
);
}
The following two tests passes when executed individually, through android studio GUI, and fail through in flutter test CLI execution.
test('should fail when json without req1 is provided', () {
var testJson = {
'req2': 'a-req2',
};
expect(() => Example.fromJson(testJson), throwsA(isA<TypeError>()));
});
test('should fail when json without req2 is provided', () {
var testJson = {
'req1': 'a-req1',
};
expect(() => Example.fromJson(testJson), throwsA(isA<TypeError>()));
});
Dart version from android studio and terminal are different (2.10 and 2.17.6), but the execution also fails in our CI, which has the same version of GUI, which works.
The error presented when the pipeline executes is the following:
Expected: throws <Instance of 'TypeError'>
Actual: <Closure: () => Example>
Which: returned <Instance of 'Example'>
So the object does get instantiated, even with null value in required fields.
Any idea why?

Should I close store while using "runAsync" method of Flutter Objectbox (Objectbox version 1.5.0)

Should close the store when interacting whith objectbox store in other thread with its method. (Flutter version 3.0.0, Objectbox version 1.5.0)
String? readNameAndRemove(Store store, int objectId){
var box = store.box<User>();
final nameOrNull = box.get(objectId)?.name;
box.remove(objectId);
return nameOrNull;
}
await store.runAsync(readNameAndRemove, objectId);

"ResourceContainerAccessDenied" returned as value of CloudTask.ExecutionInformation.FailureInformation.Code but not in TaskFailureInformationCodes

I have a .net core 3.0 application using the Microsoft.Azure.Batch 12.0.0 C# nuget package.
I create a job containing one task with a resource file like this (pseudo codeish):
var source = ResourceFile.FromStorageContainerUrl(settings.Input.Container.GetAccessUrl());
var cloudTask = new CloudTask(_taskId, commandline)
{
...
ResourceFiles = new[] { source, },
...
}
await _batchClient.JobOperations.AddTaskAsync("jobid", cloudTask,
cancellationToken: cancellationToken);
when i now request the status of the task
var cloudJob = await _batchClient.JobOperations.GetJobAsync("jobId", cancellationToken:
cancellationToken);
var cloudTask = cloudJob.ListTasks().SingleOrDefault();
var code = cloudTask.ExecutionInformation.FailureInformation,Code
code can be of value "ResourceContainerAccessDenied" if indeed we do not have access to the ResourceCondainer - "ResourceContainerAccessDenied" is not
a member of Microsoft.Azure.Batch.Common.TaskFailureInformationCodes and not documented anywhere as far as i can see.
Is this a bug in the Azure Batch C# SDK? Am i overlooking something? Where can i get a list of all possible code values?
The fact that this error code is not included in the C# SDK is indeed a bug.
I will be fixing this bug as part of an upcoming SDK release (ETA ~1 week).