text stringlengths 1 474 |
|---|
// Update the given Dog. |
await db.update( |
'dogs', |
dog.toMap(), |
// Ensure that the Dog has a matching id. |
where: 'id = ?', |
// Pass the Dog's id as a whereArg to prevent SQL injection. |
whereArgs: [dog.id], |
); |
} |
Future<void> deleteDog(int id) async { |
// Get a reference to the database. |
final db = await database; |
// Remove the Dog from the database. |
await db.delete( |
'dogs', |
// Use a `where` clause to delete a specific dog. |
where: 'id = ?', |
// Pass the Dog's id as a whereArg to prevent SQL injection. |
whereArgs: [id], |
); |
} |
// Create a Dog and add it to the dogs table |
var fido = Dog( |
id: 0, |
name: 'Fido', |
age: 35, |
); |
await insertDog(fido); |
// Now, use the method above to retrieve all the dogs. |
print(await dogs()); // Prints a list that include Fido. |
// Update Fido's age and save it to the database. |
fido = Dog( |
id: fido.id, |
name: fido.name, |
age: fido.age + 7, |
); |
await updateDog(fido); |
// Print the updated results. |
print(await dogs()); // Prints Fido with age 42. |
// Delete Fido from the database. |
await deleteDog(fido.id); |
// Print the list of dogs (empty). |
print(await dogs()); |
} |
class Dog { |
final int id; |
final String name; |
final int age; |
Dog({ |
required this.id, |
required this.name, |
required this.age, |
}); |
// Convert a Dog into a Map. The keys must correspond to the names of the |
// columns in the database. |
Map<String, Object?> toMap() { |
return { |
'id': id, |
'name': name, |
'age': age, |
}; |
} |
// Implement toString to make it easier to see information about |
// each dog when using the print statement. |
@override |
String toString() { |
return 'Dog{id: $id, name: $name, age: $age}'; |
} |
}<code_end> |
<topic_end> |
<topic_start>Firebase |
<topic_end> |
<topic_start> |
Introduction |
Firebase is a Backend-as-a-Service (BaaS) app development platform |
that provides hosted backend services such as a realtime database, |
cloud storage, authentication, crash reporting, machine learning, |
remote configuration, and hosting for your static files.<topic_end> |
<topic_start> |
Flutter and Firebase resources |
Firebase supports Flutter. To learn more, |
check out the following resources.<topic_end> |
<topic_start> |
Documentation |
<topic_end> |
<topic_start> |
Blog Posts |
Use Firebase to host your Flutter app on the web<topic_end> |
<topic_start> |
Tutorials |
Get to know Firebase for Flutter<topic_end> |
<topic_start> |
Flutter and Firebase community resources |
The Flutter community created the following useful resources.<topic_end> |
<topic_start> |
Blog Posts |
Building chat app with Flutter and Firebase<topic_end> |
<topic_start> |
Videos |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.