How do you get the download URL after uploading a file?
After uploading, call getDownloadURL() on the storage reference to get the public URL.
Upload files to Cloud Storage and send push notifications
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
Having trouble? AI is here to help
Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.
Use the AI button at the bottom of the screen
Firebase Cloud Storage allows your app to upload and download user-generated files such as profile pictures, videos, documents, and any other binary data. Files are stored in Google Cloud Storage buckets and can be accessed via secure download URLs that you save in Firestore. Firebase Cloud Messaging (FCM) is the push notification service that lets you send messages to individual devices or groups of users. Push notifications are essential for keeping users engaged by alerting them about new messages, updates, promotions, or important events even when the app is closed.
1// ── CLOUD STORAGE ──2// pubspec.yaml: firebase_storage: ^11.5.03import 'package:firebase_storage/firebase_storage.dart';4import 'dart:io';56final storage = FirebaseStorage.instance;78// Upload a file9Future<String> uploadImage(File file) async {10final ref = storage.ref().child('images/${DateTime.now().millisecondsSinceEpoch}.jpg');1112final uploadTask = ref.putFile(file);1314// Track progress15uploadTask.snapshotEvents.listen((event) {16final progress = event.bytesTransferred / event.totalBytes;17print('Upload: ${(progress * 100).toStringAsFixed(0)}%');18});1920await uploadTask;21final downloadUrl = await ref.getDownloadURL();22return downloadUrl; // Store this URL in Firestore23}2425// Delete a file26await storage.ref().child('images/photo.jpg').delete();
1// ── PUSH NOTIFICATIONS (FCM) ──2// pubspec.yaml: firebase_messaging: ^14.7.03import 'package:firebase_messaging/firebase_messaging.dart';45final messaging = FirebaseMessaging.instance;67// Request permission (iOS)8await messaging.requestPermission(9alert: true,10badge: true,11sound: true,12);1314// Get device token (send to your server)15final token = await messaging.getToken();16print('FCM Token: $token');1718// Handle foreground messages19FirebaseMessaging.onMessage.listen((RemoteMessage message) {20print('Title: ${message.notification?.title}');21print('Body: ${message.notification?.body}');22// Show local notification23});2425// Handle notification tap (app in background)26FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {27// Navigate to specific screen28print('Notification tapped: ${message.data}');29});
For background message handling, define a top-level function annotated with @pragma(vm:entry-point) that takes a RemoteMessage parameter and calls Firebase.initializeApp() inside it. Register this handler using FirebaseMessaging.onBackgroundMessage(yourHandler). The function must be top-level (not inside a class) because the OS runs it in a separate isolate when the app is in the background.
Treat uploads and notifications as one coordinated user flow:
This sequence avoids broken links, stale payloads, and confusing notification behavior.
Upload files to Cloud Storage and send push notifications. Backend integration connects app actions to real user data and secure business workflows.
Think in architecture, reliability, and team-level maintainability.
Define data model and access rules before writing convenience helper methods.
Security and data integrity issues can damage user trust faster than UI bugs.
Security rules are part of architecture, not optional deployment polish.
As your app grows, keep UI, state, and data responsibilities separate so each part stays testable and easier to modify.
After uploading, call getDownloadURL() on the storage reference to get the public URL.
FirebaseMessaging.onMessage fires when a notification arrives while the app is in the foreground.
The FCM token uniquely identifies a device so your server can send push notifications to it.
Something seems incorrect, unclear, or missing? Let us know.
FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.
Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.
Sign in to continue with exercises and quiz for this lesson.
Sign In to Continue