Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ ignore
# Platform-specific build folders
/android/
/ios/
# Except Podfile
!/ios/Podfile
/linux/
/macos/
/windows/
Expand Down
5 changes: 5 additions & 0 deletions example/lib/constants/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ import 'package:flutter/material.dart';

const titleBackgroundColor = Color(0xFFF0E4D7);

class AppConstants {
static const shortName = 'Demopod';
static const longName = 'Solid Pod Demonstrator';
}

// const dataFile = 'key-value.ttl';
const dataFile = 'keyvalue/key-value.ttl';

Expand Down
5 changes: 3 additions & 2 deletions example/lib/dialogs/about.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import 'package:flutter/material.dart';

import 'package:solidpod/solidpod.dart';

import 'package:demopod/constants/app.dart';

Future<void> aboutDialog(BuildContext context) async {
final appInfo = await getAppNameVersion();

Expand All @@ -37,8 +39,7 @@ Future<void> aboutDialog(BuildContext context) async {
if (context.mounted) {
showAboutDialog(
context: context,
applicationName:
'${appInfo.name[0].toUpperCase()}${appInfo.name.substring(1)}',
applicationName: AppConstants.shortName,
applicationVersion: appInfo.version,
applicationLegalese: '© 2024 Software Innovation Institute ANU',
applicationIcon: Image.asset(
Expand Down
167 changes: 167 additions & 0 deletions example/lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,153 @@ class HomeState extends State<Home> with SingleTickerProviderStateMixin {
}
}

Future<void> _showSendNotificationDialog() async {
final loggedIn = await loginIfRequired(context);
if (!loggedIn) return;

final recipientController = TextEditingController();
final titleController = TextEditingController();
final contentController = TextEditingController();
int selectedPriority = 1;
String? recipientError;
String? titleError;

await showDialog(
context: context,
builder: (dialogContext) {
return StatefulBuilder(
builder: (stfContext, setDialogState) {
return AlertDialog(
title: const Text('Send Notification'),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: recipientController,
decoration: InputDecoration(
labelText: 'Recipient WebID *',
errorText: recipientError,
),
),
const SizedBox(height: 12),
TextField(
controller: titleController,
decoration: InputDecoration(
labelText: 'Title *',
errorText: titleError,
),
),
const SizedBox(height: 12),
TextField(
controller: contentController,
decoration: const InputDecoration(
labelText: 'Content (optional)',
),
maxLines: 3,
),
const SizedBox(height: 12),
DropdownButtonFormField<int>(
initialValue: selectedPriority,
decoration: const InputDecoration(
labelText: 'Priority',
),
items: const [
DropdownMenuItem(value: 0, child: Text('Low')),
DropdownMenuItem(value: 1, child: Text('Medium')),
DropdownMenuItem(value: 2, child: Text('High')),
],
onChanged: (value) {
setDialogState(() {
selectedPriority = value ?? 1;
});
},
),
],
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(dialogContext),
child: const Text('Cancel'),
),
ElevatedButton(
onPressed: () async {
final recipient = recipientController.text.trim();
final notifTitle = titleController.text.trim();

final hasErrors = recipient.isEmpty || notifTitle.isEmpty;

setDialogState(() {
recipientError = recipient.isEmpty
? 'Recipient WebID is required'
: null;
titleError =
notifTitle.isEmpty ? 'Title is required' : null;
});

if (hasErrors) return;

Navigator.pop(dialogContext);

try {
await sendNotification(
recipientWebId: recipient,
title: notifTitle,
content: contentController.text.trim().isEmpty
? null
: contentController.text.trim(),
priority: selectedPriority,
);

if (context.mounted) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('Success'),
content: const Text(
'Notification sent successfully.',
),
actions: [
ElevatedButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('OK'),
),
],
),
);
}
} on Exception catch (e) {
debugPrint('Failed to send notification: $e');
if (context.mounted) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('Error'),
content: Text(
'Failed to send notification:\n$e',
),
actions: [
ElevatedButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('OK'),
),
],
),
);
}
}
},
child: const Text('Send'),
),
],
);
},
);
},
);
}

Widget _build(BuildContext context, String title) {
// Build the widget.

Expand Down Expand Up @@ -465,6 +612,26 @@ class HomeState extends State<Home> with SingleTickerProviderStateMixin {

largeGapV,

const Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Notifications',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
),
),
],
),
smallGapV,
ElevatedButton(
onPressed: _showSendNotificationDialog,
child: const Text('Send Notification'),
),

largeGapV,

const Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand Down
7 changes: 4 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import 'package:flutter/material.dart';
import 'package:solidui/solidui.dart' show SolidLogin, InfoButtonStyle;
import 'package:window_manager/window_manager.dart';

import 'package:demopod/constants/app.dart';
import 'package:demopod/home.dart';
import 'package:demopod/utils/is_desktop.dart';

Expand Down Expand Up @@ -78,13 +79,13 @@ class DemoPod extends StatelessWidget {

@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Solid Pod Demonstrator',
return MaterialApp(
title: AppConstants.longName,
home: SolidLogin(
// Images generated using Bing Image Creator from Designer, powered by
// DALL-E3.

title: 'SOLID POD DEMONSTRATOR',
title: AppConstants.longName.toUpperCase(),
appDirectory: 'exampleApp',
image: AssetImage('assets/images/demopod_image.png'),
logo: AssetImage('assets/images/demopod_logo.png'),
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependency_overrides:
solidui:
git:
url: https://github.com/anusii/solidui.git
ref: dev
ref: tony/257_notification

dev_dependencies:
dependency_validator: ^5.0.4
Expand Down
12 changes: 11 additions & 1 deletion lib/solidpod.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export 'src/solid/utils/exceptions.dart'
AccessForbiddenException,
AccessFailedException,
NotLoggedInException,
RecipientNotReadyException,
ResourceNotExistException,
SecurityKeyNotAvailableException;

Expand Down Expand Up @@ -237,11 +238,20 @@ export 'src/solid/read_external_pod.dart';

export 'src/solid/write_external_pod.dart';

/// Send notifications to another user's POD

export 'src/solid/send_notification.dart';

/// Data model for POD notifications

export 'src/solid/models/pod_notification.dart' show PodNotification;

/// 20250917 gjw Extras that were required for notepod. Not yet documented.
/// 20251103 jesscmoore In common.dart, only authUserPred is
/// used by notepod

export 'src/solid/constants/common.dart' show dataDir, profCard, authUserPred;
export 'src/solid/constants/common.dart'
show appDirName, dataDir, profCard, authUserPred, notificationDir;

/// Function to get resources in a user's POD

Expand Down
1 change: 1 addition & 0 deletions lib/src/solid/constants/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const sharingDir = 'sharing';
const sharedDir = 'shared';
const encDir = 'encryption';
const logsDir = 'logs';
const notificationDir = 'notification';

/// String terms used as predicates in ttl files.

Expand Down
101 changes: 101 additions & 0 deletions lib/src/solid/models/pod_notification.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/// Data model for POD notifications.
///
/// Copyright (C) 2026, Software Innovation Institute, ANU.
///
/// Licensed under the MIT License (the "License").
///
/// License: https://choosealicense.com/licenses/mit/.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
///
/// Authors: Tony Chen

library;

/// A notification to be stored in a recipient's POD.
///
/// Each notification is serialised as a JSON file in the recipient's
/// `appDirName/notification/` folder. The file is named after its
/// [timestamp] (Unix epoch milliseconds) for chronological sorting.

class PodNotification {
/// WebID of the user who sent the notification.

final String senderWebId;

/// WebID of the intended recipient.

final String recipientWebId;

/// Short summary of the notification.

final String title;

/// Optional detailed body text.

final String? content;

/// Priority level (0 = low, 1 = medium, 2 = high).

final int priority;

/// Unix timestamp in milliseconds when the notification was created.

final int timestamp;

const PodNotification({
required this.senderWebId,
required this.recipientWebId,
required this.title,
this.content,
required this.priority,
required this.timestamp,
});

/// Serialise to a JSON-compatible map.

Map<String, dynamic> toJson() => {
'senderWebId': senderWebId,
'recipientWebId': recipientWebId,
'title': title,
if (content != null) 'content': content,
'priority': priority,
'timestamp': timestamp,
};

/// Deserialise from a JSON-compatible map.

factory PodNotification.fromJson(Map<String, dynamic> json) =>
PodNotification(
senderWebId: json['senderWebId'] as String,
recipientWebId: json['recipientWebId'] as String,
title: json['title'] as String,
content: json['content'] as String?,
priority: json['priority'] as int,
timestamp: json['timestamp'] as int,
);

@override
String toString() => 'PodNotification('
'sender: $senderWebId, '
'recipient: $recipientWebId, '
'title: $title, '
'priority: $priority, '
'timestamp: $timestamp)';
}
Loading
Loading