29 lines
738 B
Dart
29 lines
738 B
Dart
import 'package:firebase_database/firebase_database.dart';
|
|
|
|
class DatabaseService {
|
|
final DatabaseReference _db = FirebaseDatabase.instance.ref();
|
|
|
|
Future<void> saveScore({
|
|
required String userId,
|
|
required int score,
|
|
required String formattedTime,
|
|
required String levelName,
|
|
required String category,
|
|
}) async {
|
|
try {
|
|
await _db.child('scores').push().set({
|
|
'userId': userId,
|
|
'score': score,
|
|
'time': formattedTime,
|
|
'level': levelName,
|
|
'category': category,
|
|
'timestamp': DateTime.now().toIso8601String(),
|
|
});
|
|
} catch (e) {
|
|
print('Error saving score: $e');
|
|
// You might want to handle this error differently
|
|
rethrow;
|
|
}
|
|
}
|
|
}
|