Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/75 implement logic to delete childs picture from firebase storage #93

2 changes: 1 addition & 1 deletion .fvm/flutter_sdk
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ android {
defaultConfig {
// Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.hershel.parental_control"
minSdkVersion 29
minSdkVersion 28
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
9 changes: 6 additions & 3 deletions lib/app/pages/child_details_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:parental_control/app/helpers/parsing_extension.dart';
Expand Down Expand Up @@ -37,7 +37,10 @@ class ChildDetailsPage extends StatefulWidget {
}

class _ChildDetailsPageState extends State<ChildDetailsPage> {
Future<void> _delete(BuildContext context, ChildModel model) async {
Future<void> _deleteUserPictureAndChild(
BuildContext context,
ChildModel model,
) async {
try {
await widget.database.deleteChild(model);
} on FirebaseException catch (e) {
Expand Down Expand Up @@ -378,7 +381,7 @@ class _ChildDetailsPageState extends State<ChildDetailsPage> {
cancelActionText: 'Cancel',
);
if (didConfirmDelete == true) {
await _delete(context, model);
await _deleteUserPictureAndChild(context, model);
Navigator.of(context).pop();
}
return;
Expand Down
5 changes: 4 additions & 1 deletion lib/services/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ class FirestoreDatabase implements Database {

@override
Future<void> deleteChild(ChildModel model) async {
await _service.deleteData(path: APIPath.child(uid, model.id));
await _service.deleteData(
path: APIPath.child(uid, model.id),
image: model.image,
);
}

@override
Expand Down
12 changes: 9 additions & 3 deletions lib/services/firestore_service.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/foundation.dart';

class FirestoreService {
Expand Down Expand Up @@ -38,15 +39,20 @@ class FirestoreService {
required String path,
required Map<String, dynamic> data,
}) async {
// await FirebaseFirestore.instance.collection('Notifications').
// doc().set({'message': 'HomeWork Time'});
final reference = FirebaseFirestore.instance.collection(path).doc();
debugPrint('$path: $data');
await reference.set(data);
}

Future<void> deleteData({required String path}) async {
Future<void> deleteData({required String path, String? image}) async {
final reference = FirebaseFirestore.instance.doc(path);

/// Deleting the child's picture
if (image != null) {
final storageReference = FirebaseStorage.instance.refFromURL(image);
await storageReference.delete();
}

debugPrint('delete: $path');
await reference.delete();
}
Expand Down
10 changes: 1 addition & 9 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ packages:
source: hosted
version: "5.2.2"
firebase_core:
dependency: "direct main"
dependency: transitive
description:
name: firebase_core
sha256: ed611fb8e67e43ecc7956f242cecca383d87cf71aace27287aa5dd4bdba4ac07
Expand Down Expand Up @@ -488,14 +488,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.1"
google_fonts:
dependency: "direct main"
description:
name: google_fonts
sha256: "927573f2e8a8d65c17931e21918ad0ab0666b1b636537de7c4932bdb487b190f"
url: "https://pub.dev"
source: hosted
version: "4.0.3"
google_identity_services_web:
dependency: transitive
description:
Expand Down
Loading