how to save a Date Time on DB with sqlflite? - database

I have a problem on how to save a DateTime on a data base with sqflite , so even if I change a page the date won't desapear, Could any one help me please ? Thank you .
enter image description here

If you just need to save one date, sqflite is overkill, take a look at shared_preferences.
onPressed: ()async{
final selectedDate= await selectTimePicker(context);
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.seString('date', '$selectedDate');
}

Related

database update function not working sqflite flutter

am quite new to flutter and my code is pretty much a mess but can anyone explain why db. update doesn't work, whenever I try to update it throws this error
"error when trying to update"(https://i.stack.imgur.com/4cCdt.png)
"code"(https://i.stack.imgur.com/yDoIl.png)
"UI" (https://i.stack.imgur.com/HkahR.png)
all that its supposed to do is when the save icon is pressed it takes input from both title and body and saves them as it is shown above, but instead it throws the error when trying to update. can anyone help please ?
this how my update function goes:
Future update(Note note) async {
final db = await instance.database;
final id = await db.update(
tableNotes,
note.toJson(),
where: '${NoteFields.id} = ?',
whereArgs: [note.id]);
return note.copy(id: id);
}
As per your screenshot, the data you are passing is null, that's why it is showing an error, before updating check what data you are sending.
solved it by adding the parameter id which then specifyed what it was adding txt and txt2 to

Firebase GET request orderby 400 bad request

For a get request, I am trying to user order by like below but always get a 400 bad request. Here, multiple users can have multiple blog posts each with a unique id like b1 in screenshot below. The long sequence of characters is the uid of a user under blogs. Each user has their own uid.
https://assignment-c3557-default-rtdb.asia-southeast1.firebasedatabase.app/blogs.json?orderBy="createdAt"
I followed the documentation here
https://firebase.google.com/docs/database/rest/retrieve-data
All I am doing is issuing a simple GET request in react js as follows:
const resp = await fetch(`https://assignment-c3557-default-rtdb.asia-southeast1.firebasedatabase.app/blogs.json?orderBy="createdAt"``)
const data = await resp.json()
if(!resp.ok) { ... }
Below is the database single entry for schema reference
As I said in my previous comment, this URL is invalid:
https://assignment-c3557-default-rtdb.asia-southeast1.firebasedatabase.app/blogs.json/orderBy="createdAt"
                                                                                     ^
The query portion of a URL starts with a ? character.
https://assignment-c3557-default-rtdb.asia-southeast1.firebasedatabase.app/blogs.json?orderBy="createdAt"
                                                                                     ^
Firebase Realtime Database - Adding query to Axios GET request?
I followed the above similar issue resolution to solve my problem

How to Update this mobile no field to firestore database when all the data have route to this screen

How do i update this mobile no field to firestore database i am unable to find the doc id. i tried many times but it showing me error that doc id is missing which doc id should i have to put please make a help for me in this case. Thankyou.
const ItemDetails = ({ route }) => {
const[values, setValue] = useState('')
let data = route.params
console.log(data)
const updateValue = () => {
db.collection("FinalData")
.doc()
.update({
mobile_no: values
})
.then(function () {
alert("Mobile Number Updated Successfully")
})
}
Okay, you do not know which doc id to put.
In Firestore, you can only update an existing document.
Right now, what you want to do with this line db.collection("FinalData").doc().update(...) is to update a document, but you have not told firestore which document to remove the old mobile no from and put the new mobile no in.
Another way to understand this is we can assume that your firestore database is a book. What you want to do with this line db.collection("FinalData").doc().update(...) is to tell firestore to please change mobile no to 'bla bla bla' on page (you didn't give any page number). So you see, firestore can not change anything because it does not which page to change.
So the doc id being referred to is the id of the document you want to correct.
This mobile no, is probably one of your users mobile number, so get the document (which could be something like user-settings, user-details or so) id.
Then you put that document id as shown below:
db.collection("FinalData").doc('PUT-DOC-ID-HERE').update(...)

How to add thumbnails to Discord embeds?

I am creating a Discord bot that displays player statistics from Hypixel, a Minecraft server. I am trying to add their player's avatars as well, as a thumbnail in the embeds the bot sends. To get the avatars I am using Crafatar. This is the code I am using, however, the thumbnail doesn't show up on the embed. I believe this has something to do with the fact that I am using an URL with a variable in it, as I tried with just a regular URL and it worked fine.
.setThumbnail(`https://crafatar.com/avatars/${uuid}.jpg`)
The variable uuid is declared and assigned to a value further up in my code.
EDIT 1
This is the code where I get the uuid variable from. I can't see anything wrong with it, however, I am not particularly skilled in JavaScript.
var uuid = '';
getId(args[1]).then(id => {
uuid = id;
})
getId is a function defined below, which looks like this:
function getId(playername) {
return fetch(`https://api.mojang.com/users/profiles/minecraft/${playername}`)
.then(data => data.json())
.then(player => player.id);
}
This uses the Mojang API to convert the player's display name, which is entered as a command parameter, to their UUID.
From what you've posted, it seems like the problem is from the fact that you're correctly using Promises to set the value of uuid, but you're not waiting for it to be set before setting your embed thumbnail.
You should wait for it either using Promise.then() (as you did elsewhere), or async/await.
Here's an example:
// Using .then():
getId(args[1]).then(uuid => {
let embed = new MessageEmbed()
// You have to set the thumbnail after you get the actual ID:
embed.setThumbnail(`https://crafatar.com/avatars/${uuid}.jpg`)
// You can now send the embed
})
// Using async/await:
let uuid = await getId(args[1])
let embed = new MessageEmbed()
embed.setThumbnail(`https://crafatar.com/avatars/${uuid}.jpg`)

Can't get user avatar

I'm trying to get user's avatars for a welcome message but when someone joins it never shows it. I've tried many different methods. Here is my current code.
bot.on('guildMemberAdd', member => {
const exampleEmbed = new MessageEmbed()
.setColor('#0000FF')
.addField('Welcome!', `Welcome to the server, ${member}! Go to <#channel> for the rules, then grab some roles at <#channel>!`)
.setThumbnail(member.user.displayAvatarURL)
member.guild.channels.cache.get('693219932904751177').send(exampleEmbed);
});
All you need to do it add a () behind the .displayAvatarURL
So the line would look like this:
.setThumbnail(member.user.displayAvatarURL())

Resources