I am making a todo app with notifications and am using flutter local notifications plugin, How do I generate a unique integer as id for a specific todo so that I can also cancel notification of that specific todo using that unique integer. and the value f the integer must be an int which and the first value must be 0 and then it increment by one .
i used
class data {
final String name = "test" ;
final notificationId = UniqueKey().hashCode;
}
but it gives random values and in my case i need values starts from 0 and increment by 1 .How to do it ? is there any others packages
you can use Shared Preference to store last int value and increase it on next notification, i hope that will help you.
If you are using local database to store notification, then create a column of int type with auto increments, and use that id to cancel that notification
For your reference read here about Shared Preference
Related
I want to add some extra features after new user login with a google login in Flutter.so I need to know if a user is new or not . if the user is new then I want to add some user information. other wise navigate to another page.
So how can I check If the User is new or not?
The User object has a metadata property, which has two properties: creationTime and lastSignInTime. When those are no more than a few milliseconds apart, the user was just created. If they're further apart, the user was created in a previous session.
FirebaseAuth User contains this data in metadata prop. I used the following chunk of code. You can change the number of seconds if you want.
bool isNewUser(User user) {
DateTime now = DateTime.now();
DateTime cTime = user.metadata.creationTime;
int longAgo = 15; // to check account creation under last 15 seconds
return now.difference(cTime).inSeconds > longAgo;
}
I am trying to inject agents from a database into a specific source block. The database consists of 2 columns of "OrderType" & "OrderAmount". I wish to inject "OrderAmount" of agents of their corresponding "OrderType" into this source, while retaining the differentiation (I.E. by storing a parameter attribute ID of each entry/agent in the corresponding agenttype of the source block).
I have saved the entries from the database in collections and constructed a table as such (For both arrays; type = double):
double [][] ArrayCustomerOrders = new double [coll_CustomerOrderType.size()][2];
for (int i = 0; i < coll_CustomerOrderType.size(); i++) {
ArrayCustomerOrders[i][0] = coll_CustomerOrderType.get(i);
ArrayCustomerOrders[i][1] = coll_CustomerOrderAmount.get(i);
}
I tried playing around with the source block calls of inject() function in the same event as I constructed the order table in, but was unable to inject eligible arguments.
Does anyone have a suggestion on how to go about this?
In your case, you can simply replace the Source block with an Enter block (named "myEnterBlock"):
Create an empty agent population pop_Orders with an agent type that has 2 parameters p_Type and p_Amount.
In your for-loop code, when you have the current order type and amount, create such an agent and push it into the Enter block directly:
myEnterBlock.take(add_pop_Orders(currentType, currentAmount))
From the app Automate, I would like to send a Glympse. Automate's App Start block takes the following inputs. I assume not all of them have to be specified.
Package
Activity Class
Action
Data URI
Mime Type
Category
Extras
Flags
What should I set for the above values?
I am reading some code and looking at some documentation. I figured out that the Package should be com.glympse.android.glympse and the Activity Class should be com.glympse.android.intent.Create. The extras input should be set to a dictionary object. The dictionary should have a message key with a string value. The duration key has a long value which holds the number of milliseconds to share the location. I haven't figured out the rest of the keys or their formats.
Here are the steps...
Create a dictionary named recipient with these keys:
type with a string value of sms
address with a string value of 5425551212 // replace with the actual phone number
Create another dictionary named options with these keys:
recipients with a string value of jsonEncode(recipient) // this will convert the recipient dictionary into a JSON string
message with a string value of whatever you want to say
duration with a long value of the number of milliseconds to share the Glympse location (e.g. 1800000 for 30 minutes)
Use the App Start block with the following inputs:
Package is set to com.glympse.android.glympse
Activity Class is set to com.glympse.android.intent.Create
Action is set to Run
Extras is set to options // the dictionary created above
This will cause the Glympse screen to show up so that the user only has to hit the Create button.
I try in Grails service save an object to mongodb:
Cover saveCover = new Cover()
saveCover.id = url
saveCover.url = url
saveCover.name = name
saveCover.sku = sku
saveCover.price = price
saveCover.save()
Cover domain looks like this:
class Cover {
String id
String name
String url
String sku
String price
}
So I want to have custom id based on url, but during save process I get error:
Could not commit Datastore transaction; nested exception is
org.grails.datastore.mapping.core.OptimisticLockingException: The
instance was updated by another user while you were editing
But if I didn`t use setters and just pass all values in constructor, the exception is gone. Why?
As reported in the documentation here:
Note that if you manually assign an identifier, then you will need to use the insert method instead of the save method, otherwise GORM can't work out whether you are trying to achieve an insert or an update
so you need to use insert method instead of save when id generator is assigned
cover.insert(failOnError: true)
if you do not define the mapping like this:
static mapping = {
id generator: 'assigned'
}
and will use insert method you'll get an auto-generated objectId:
"_id" : "5496e904e4b03b155725ebdb"
This exception occurs when you assign an id to a new model and try to save it because GORM thinks it should be doing an update.
Why this exception occurs
When I ran into this issue I was using 1.3.0 of the grails-mongo plugin. That uses 1.1.9 of the grails datastore core code. I noticed that the exception gets generated on line 847(ish) of NativeEntryEntityPersister. This code updates an existing domain object in the db.
Above that on line 790 is where isUpdate is created which is used to see if it's an update or not. isInsert is false as it is only true when an insert is forced and readObjectIdentifier will return the id that has been assigned to the object so isUpdate will end up evaluating as true.
Fixing the exception
Thanks to && !isInsert on line 791 if you force an insert the insert code will get called and sure enough the exception will go away. However when I did this the assigned id wasn't saved and instead a generated object id was used. I saw that the fix for this was on line 803 where it checks to see if the generator is set to "assigned".
To fix that you can add the following mapping.
class Cover {
String id
String name
String url
String sku
String price
static mapping = {
id generator: 'assigned'
}
}
A side effect of this is that you will always need to assign an id for new Cover domain objects.
I'm trying to input an error check for my form. I have the user entering the name and I would like a prompt to inform them if they are attempting to use a Name already in the records.
Example: the Person table has 3 records with FNames being: Jeff, Kyle, Darren.
If on the add person form in the Fname Box Kyle is entered, the after update event will notify the user that this name has been claimed and null the field. Where as if Greg was enter no notifications will occur.
I just don't know how to compare a text field value to values in a filtered query list, and Google searches have other loosely related links in the way.
Thank you for help!
If all fnames must be unique, add a unique index to the table. This will prevent duplicates being entered. The form error property will allow you to provide a custom error.
You can also check if the name exists in the Before Update event of the control.
In this example, the control and field are both called AText. Generally, you should rename controls so they are not the same as fields.
Private Sub AText_BeforeUpdate(Cancel As Integer)
Dim IsOk As Boolean
''One of the very few places where the .Text property is used
sLookUp = Me.AText.Text
IsOk = IsNull(DLookup("Atext", "Table1", "Atext='" & sLookUp & "'"))
If Not IsOk Then
MsgBox "Found!"
Cancel = True
End If
End Sub