You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

面向老年群体的Flutter毕业项目:无需Cloud Functions实现推送通知的方案咨询

Push Notifications for Your Elderly Care Flutter App (No Cloud Functions, No Cost)

Hey there! I get your frustration with Cloud Functions requiring a paid plan—total bummer for a graduation project. Let’s walk through practical, free solutions that fit your skill level and app needs, without needing Laravel or extra costs.

1. Local Notifications for Reminders (No Backend Needed)

For your medication, blood pressure, and glucose measurement reminders, local notification packages are perfect. These work entirely on the device, no cloud services required, and are super straightforward to implement.

  • flutter_local_notifications: The most popular choice for basic to mid-level local notifications. Supports scheduled alerts, custom sounds, and basic UI customization.
  • awesome_notifications: More feature-rich—great if you want custom notification layouts, action buttons (like "Mark as Taken" for meds), or progress indicators.

Quick Example with flutter_local_notifications:

First, add the package to your pubspec.yaml:

dependencies:
  flutter_local_notifications: ^16.1.0

Then, initialize the plugin and schedule a medication reminder:

import 'package:flutter_local_notifications/flutter_local_notifications.dart';

final FlutterLocalNotificationsPlugin _notificationsPlugin = FlutterLocalNotificationsPlugin();

// Initialize in your main app setup
void initNotifications() async {
  const AndroidInitializationSettings androidSettings = AndroidInitializationSettings('@mipmap/ic_launcher');
  const InitializationSettings settings = InitializationSettings(android: androidSettings);
  await _notificationsPlugin.initialize(settings);
}

// Schedule a daily medication reminder
void scheduleMedReminder(Time time) async {
  const AndroidNotificationDetails androidDetails = AndroidNotificationDetails(
    'med_reminder_channel',
    'Medication Reminders',
    channelDescription: 'Alerts for taking medications',
    importance: Importance.high,
  );
  const NotificationDetails notificationDetails = NotificationDetails(android: androidDetails);

  await _notificationsPlugin.showDailyAtTime(
    0,
    'Time to Take Your Meds!',
    'Don’t forget your morning medication.',
    time,
    notificationDetails,
  );
}

This handles all your scheduled reminder needs without touching any cloud services.

2. Firebase Messaging for Caregiver-to-Elder Chat Notifications (No Cloud Functions)

You don’t need Cloud Functions to send FCM notifications—you can send them directly from the Flutter client, as long as you have the recipient’s FCM token. Here’s how:

Step 1: Store FCM Tokens in Firestore

When a user (elder or caregiver) logs in, retrieve their FCM token and save it to your Firestore collection (e.g., users/{userId}/fcmToken). Make sure to listen for token updates (tokens can change when the app is reinstalled or the device is updated):

import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

void saveFcmToken(String userId) async {
  String? token = await FirebaseMessaging.instance.getToken();
  if (token != null) {
    await FirebaseFirestore.instance.collection('users').doc(userId).update({
      'fcmToken': token,
    });
  }

  // Listen for token changes
  FirebaseMessaging.instance.onTokenRefresh.listen((newToken) {
    FirebaseFirestore.instance.collection('users').doc(userId).update({
      'fcmToken': newToken,
    });
  });
}

Step 2: Send Notifications Directly from the Client

When a caregiver sends a chat message to an elder, fetch the elder’s FCM token from Firestore, then use the firebase_messaging package to send the notification:

import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

void sendChatNotification(String elderUserId, String message) async {
  // Fetch elder's FCM token from Firestore
  DocumentSnapshot userDoc = await FirebaseFirestore.instance.collection('users').doc(elderUserId).get();
  String? recipientToken = userDoc['fcmToken'];

  if (recipientToken != null) {
    try {
      await FirebaseMessaging.instance.sendMessage(
        to: recipientToken,
        notification: Notification(
          title: 'New Message from Caregiver',
          body: message,
        ),
        data: {
          'type': 'chat',
          'message': message,
        },
      );
    } catch (e) {
      print('Error sending notification: $e');
    }
  }
}

Key Notes:

  • Firebase’s free tier allows client-to-client FCM messages with a generous quota (way more than you’ll need for a graduation project).
  • Make sure your Firebase project has FCM enabled (it’s enabled by default for most projects).
  • You’ll need to handle notification permissions on iOS and Android (the firebase_messaging docs have clear guides for this).

3. What About Other Packages?

Let’s quickly clear up the other options you mentioned:

  • pusher: A real-time messaging service, but it requires setting up a Pusher account (free tier available) and adds extra complexity. Not necessary when you’re already using Firebase for data storage.
  • Laravel: Definitely skip this—learning a new backend framework just for push notifications is overkill for your project, especially when the above solutions work for free.

Final Recommendation

Combine both approaches:

  • Use flutter_local_notifications or awesome_notifications for all scheduled reminders (meds, blood pressure, glucose).
  • Use client-side Firebase Messaging for caregiver-to-elder chat notifications.

This setup is completely free, requires no Cloud Functions, and plays nicely with your existing Firebase database. It’s also manageable with your current Flutter skills—no need to learn new frameworks!

内容的提问来源于stack exchange,提问作者Manal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 11:32:28