I really liked Hive and recently i decided to try Isar as a local DB for my App ,However i'm facing a problem when trying to create an object into a collection using the Isar inspector as the fields are becoming null after creating the object .
User Class
import 'package:isar/isar.dart';
part 'user_model.g.dart';
#collection
class User {
Id id = Isar.autoIncrement; // you can also use id = null to auto increment
String? name;
int? age;
}
Here is the class that i'm generating the collection from
Creating an object from Isar inspector
and here is a GIF to better discribe the problem
fields are null on creation
any help or info is appreciated thank you
Simply put the text between double quotes on the inspector so instead of simple text be like that "simple text"
Related
How could you store something like that even when the app is closed in Flutter:
Class myList {
String id;
List<Item> list;
}
Class Item{
//Many property’s
}
I thought maybe I could do that with "sqflite", a flutter dependency, but I have no Idea how I could store there this List<Item>. Do you have any idea?
Btw: I need multiple of these "myList" instances.
You can store it using sqflite,hive or shared preferences.Try to save it under flutter shared preferences. These are two methods that you can use.
Using shared preferences
1)First create a shared preference instance
SharedPreferences prefs = await SharedPreferences.getInstance();
Then save the relevant data type.here you need to put a object list so add the list and convert it to the String using jsonEncode.
Map<String,List<Item>> map={mylist.id: mylist.list};
prefs.setString("itemList", json.encode(map));
Then you can retrieve data like this
Map<String,List<Item>> map=json.decode(prefs.getString("itemList")).asMap();
2)Using Hive
First Create the hive databse.you can put any name here
var box = Hive.box('myBox');
Then add the object in to that database
var myList = myList()
..id = your id here
..list = add list here;
var name = box.add(myList);
You can get anywhere this data list.
print(box.getAt(0));
You can try hive package. It is a lightweight local storage passage and it is a good idea to use hive because it has better benchmarks for reading and writes. You can search for the tutorial for the hive. or just read the documentation.
I am trying to access a model class in the second page of my app.
In the first which I have named Main Activity I am able to call the class and write an updated value to it. My class is as follows:
class UserDetails{
String userName = "";
String userSurname = "";
}
In MainActivity I am able to call the above and update the userName and userSurname after reading from Firestore and print in the console:
UserDetails details = UserDetails();
details.userName = userName;
details.userSurname = userSurname;
print(details.userName);
print(details.userSurname);
When I move to the second page and try to call the same first two lines shown below I cannot even autocomplete the details.userName.
UserDetails details = UserDetails();
details.userName = userName;
The package is imported on both MainActivity and the second page. any idea why I cannot get UserDetails in the second? I thought maybe it is not re-usable across pages but even if I remove it from MainActivity it still doesnt allow the usage on the second page.
Essentially what I am trying to do is use userName and userSurname as global variables.
if the class is imported in both of your classes.
Run the command flutter clean. That would solve your problem.
I hope this helps.
I am not able to embed the Address into Person. Controller and views are auto generated. When I click on create I just get a blank page instead of proper UI of grails.
package trydemo
class Person {
String name
Address address
static embedded = ['address']
static constraints = {
}
}
package trydemo
class Address {
String city
static constraints = {
}
}
How to use static embedded in grails 3.3.11?
Assuming you are using GORM For Hibernate, the code you show is correct and is how you use embedded in Grails 3.3.11 (or any other version).
The effect of using embedded in that way is the Address properties will be stored in the same table as the Person properties so when you retrieve a Person, there is no join or foreign key involved. All of the data to make a Person is in 1 row in 1 table.
Separate from that, you can organize your UI however you like.
I'm having difficulties in two areas:
1) When a user successfully logs into their account using phone auth in Firestore, I take them to an "Edit profile" page so they can add their profile information. I get an error saying that I can't add data to a null user class or add data to a class within a class.
I currently have my user class setup something like the following:
class User {
String points;
Name name;
User({this.points, this.name});
}
class Name {
String firstName;
String lastName;
Name({this.firstName, this.lastName})
}
As you can see, I have a class within a class and when I try to add a value, it says I can't. I've tried doing it like
_bloc.user.name.firstName = value
And I've tried like
Name newName = Name();
newName.first = value.
The second one seems to work but it doesn't seem right. I'm hoping you could help me understand how to properly approach adding data for new users when I have a class within a class.
The second issue is understanding how to properly use the Places API. I'm currently learning from the below repo, but it's outdated and there's a couple lines I can't seem to figure out how to change. I also can't seem to find an updated tutorial since the October app crashing update.
https://github.com/alfianlosari/flutter_placez
Thanks in advance for your help!
I have one main document:
#Document
public class MainDocument {
private String name;
private String desc;
private List<Nested> nestedList;
-- More fields/methods --
}
and a document getting embedded:
#Document
public class Nested {
private String nestedUser;
private String nestedTitle;
-- More fields/methods --
}
When attempting to store a new instance of the Nested class in List<Nested>, the fields of the Nested class are getting renamed. For example, nestedTitle becomes title. This wouldn't be a huge deal except for the fact that it is not allowing me to set the value of some of the renamed fields.
I have tried using the #Field("field_name") annotation but the fields will still get renamed and ignore attempts to set their value.
What would be causing some of the fields to get renamed? Am I missing something? About half of the fields get renamed and the rest stay the correct name...
I am testing by using POSTMAN to send JSON requests to the controller for the main document. Even if I use the new field name in the JSON request the value will still not be set.
Figured it out...
Getter method for nestedTitle was named getTitle() so it was renaming it based on the getter methods name. Changed to getNestedTitle() and it stopped getting renamed. Changed the other getter methods for the fields in question and now everything works as expected.
Not sure why it would rename the field's based on the method name but who am I to judge Spring... Posting this answer to save someone else a couple hours of their time.