Skip to content

Commit d4909ec

Browse files
committed
fix: add timezone package and fix reminder service DateTime/TZDateTime type mismatch
1 parent c3fec93 commit d4909ec

4 files changed

Lines changed: 75 additions & 75 deletions

File tree

app/lib/features/quest/domain/services/reminder_service.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
2+
import 'package:timezone/timezone.dart' as tz;
23
import '../models/quest_models.dart';
34

45
/// Reminder notification service
@@ -28,7 +29,9 @@ class FakeReminderService implements ReminderService {
2829
@override
2930
Future<void> initialize() async {
3031
// Initialize local notifications
31-
const androidSettings = AndroidInitializationSettings('@mipmap/ic_launcher');
32+
const androidSettings = AndroidInitializationSettings(
33+
'@mipmap/ic_launcher',
34+
);
3235
const iosSettings = DarwinInitializationSettings();
3336
const initSettings = InitializationSettings(
3437
android: androidSettings,
@@ -50,12 +53,15 @@ class FakeReminderService implements ReminderService {
5053
// Reminder time is in the past, show immediately
5154
await _showNotification(reminder);
5255
} else {
56+
// Convert DateTime to TZDateTime
57+
final tzDateTime = tz.TZDateTime.from(reminder.scheduledTime, tz.local);
58+
5359
// Schedule for future time
5460
await _notificationsPlugin.zonedSchedule(
5561
reminder.id.hashCode,
5662
reminder.title,
5763
reminder.description,
58-
reminder.scheduledTime,
64+
tzDateTime,
5965
const NotificationDetails(
6066
android: AndroidNotificationDetails(
6167
'quest_reminders',
@@ -67,8 +73,6 @@ class FakeReminderService implements ReminderService {
6773
iOS: DarwinNotificationDetails(),
6874
),
6975
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
70-
uiLocalNotificationDateInterpretation:
71-
UILocalNotificationDateInterpretation.absoluteTime,
7276
);
7377
}
7478
}
@@ -110,4 +114,3 @@ class FakeReminderService implements ReminderService {
110114
);
111115
}
112116
}
113-

app/lib/features/quest/presentation/screens/quest_upload_screen.dart

Lines changed: 65 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
22
import 'package:flutter_riverpod/flutter_riverpod.dart';
33
import 'package:file_picker/file_picker.dart';
44
import 'package:go_router/go_router.dart';
5-
import '../../../quest/domain/models/quest_models.dart';
65
import '../../../quest/application/providers/quest_provider.dart';
76

87
/// Quest upload screen - upload files and start quest
@@ -41,9 +40,9 @@ class _QuestUploadScreenState extends ConsumerState<QuestUploadScreen> {
4140
}
4241
} catch (e) {
4342
if (mounted) {
44-
ScaffoldMessenger.of(context).showSnackBar(
45-
SnackBar(content: Text('Error picking files: $e')),
46-
);
43+
ScaffoldMessenger.of(
44+
context,
45+
).showSnackBar(SnackBar(content: Text('Error picking files: $e')));
4746
}
4847
}
4948
}
@@ -67,9 +66,7 @@ class _QuestUploadScreenState extends ConsumerState<QuestUploadScreen> {
6766
// Upload files if selected
6867
for (final file in _selectedFiles) {
6968
if (file.path != null) {
70-
await ref.read(
71-
uploadFileProvider((quest.id, file.path!)).future,
72-
);
69+
await ref.read(uploadFileProvider((quest.id, file.path!)).future);
7370
}
7471
}
7572

@@ -79,9 +76,9 @@ class _QuestUploadScreenState extends ConsumerState<QuestUploadScreen> {
7976
}
8077
} catch (e) {
8178
if (mounted) {
82-
ScaffoldMessenger.of(context).showSnackBar(
83-
SnackBar(content: Text('Error creating quest: $e')),
84-
);
79+
ScaffoldMessenger.of(
80+
context,
81+
).showSnackBar(SnackBar(content: Text('Error creating quest: $e')));
8582
}
8683
} finally {
8784
setState(() => _isLoading = false);
@@ -91,10 +88,7 @@ class _QuestUploadScreenState extends ConsumerState<QuestUploadScreen> {
9188
@override
9289
Widget build(BuildContext context) {
9390
return Scaffold(
94-
appBar: AppBar(
95-
title: const Text('New Quest'),
96-
centerTitle: true,
97-
),
91+
appBar: AppBar(title: const Text('New Quest'), centerTitle: true),
9892
body: SingleChildScrollView(
9993
padding: const EdgeInsets.all(16),
10094
child: Column(
@@ -103,16 +97,16 @@ class _QuestUploadScreenState extends ConsumerState<QuestUploadScreen> {
10397
// Title section
10498
Text(
10599
'Create a New Quest',
106-
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
107-
fontWeight: FontWeight.bold,
108-
),
100+
style: Theme.of(
101+
context,
102+
).textTheme.headlineSmall?.copyWith(fontWeight: FontWeight.bold),
109103
),
110104
const SizedBox(height: 8),
111105
Text(
112106
'Upload files and ask AI questions about them',
113-
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
114-
color: Colors.grey,
115-
),
107+
style: Theme.of(
108+
context,
109+
).textTheme.bodyMedium?.copyWith(color: Colors.grey),
116110
),
117111
const SizedBox(height: 24),
118112

@@ -148,9 +142,9 @@ class _QuestUploadScreenState extends ConsumerState<QuestUploadScreen> {
148142
// File upload section
149143
Text(
150144
'Upload Files',
151-
style: Theme.of(context).textTheme.titleMedium?.copyWith(
152-
fontWeight: FontWeight.bold,
153-
),
145+
style: Theme.of(
146+
context,
147+
).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold),
154148
),
155149
const SizedBox(height: 12),
156150

@@ -160,7 +154,10 @@ class _QuestUploadScreenState extends ConsumerState<QuestUploadScreen> {
160154
icon: const Icon(Icons.upload_file),
161155
label: const Text('Select Files'),
162156
style: ElevatedButton.styleFrom(
163-
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
157+
padding: const EdgeInsets.symmetric(
158+
vertical: 12,
159+
horizontal: 16,
160+
),
164161
),
165162
),
166163
const SizedBox(height: 16),
@@ -180,47 +177,47 @@ class _QuestUploadScreenState extends ConsumerState<QuestUploadScreen> {
180177
),
181178
),
182179
const SizedBox(height: 8),
183-
...List.generate(
184-
_selectedFiles.length,
185-
(index) {
186-
final file = _selectedFiles[index];
187-
return Padding(
188-
padding: const EdgeInsets.symmetric(vertical: 4),
189-
child: Row(
190-
children: [
191-
const Icon(Icons.insert_drive_file, size: 20),
192-
const SizedBox(width: 8),
193-
Expanded(
194-
child: Column(
195-
crossAxisAlignment: CrossAxisAlignment.start,
196-
children: [
197-
Text(
198-
file.name,
199-
overflow: TextOverflow.ellipsis,
200-
style: Theme.of(context).textTheme.bodySmall,
201-
),
202-
Text(
203-
'${(file.size / 1024).toStringAsFixed(2)} KB',
204-
style: Theme.of(context).textTheme.bodySmall?.copyWith(
205-
color: Colors.grey,
206-
),
207-
),
208-
],
209-
),
210-
),
211-
IconButton(
212-
icon: const Icon(Icons.close, size: 20),
213-
onPressed: () {
214-
setState(() {
215-
_selectedFiles.removeAt(index);
216-
});
217-
},
180+
...List.generate(_selectedFiles.length, (index) {
181+
final file = _selectedFiles[index];
182+
return Padding(
183+
padding: const EdgeInsets.symmetric(vertical: 4),
184+
child: Row(
185+
children: [
186+
const Icon(Icons.insert_drive_file, size: 20),
187+
const SizedBox(width: 8),
188+
Expanded(
189+
child: Column(
190+
crossAxisAlignment: CrossAxisAlignment.start,
191+
children: [
192+
Text(
193+
file.name,
194+
overflow: TextOverflow.ellipsis,
195+
style: Theme.of(
196+
context,
197+
).textTheme.bodySmall,
198+
),
199+
Text(
200+
'${(file.size / 1024).toStringAsFixed(2)} KB',
201+
style: Theme.of(context)
202+
.textTheme
203+
.bodySmall
204+
?.copyWith(color: Colors.grey),
205+
),
206+
],
218207
),
219-
],
220-
),
221-
);
222-
},
223-
),
208+
),
209+
IconButton(
210+
icon: const Icon(Icons.close, size: 20),
211+
onPressed: () {
212+
setState(() {
213+
_selectedFiles.removeAt(index);
214+
});
215+
},
216+
),
217+
],
218+
),
219+
);
220+
}),
224221
],
225222
),
226223
),
@@ -237,10 +234,10 @@ class _QuestUploadScreenState extends ConsumerState<QuestUploadScreen> {
237234
),
238235
child: _isLoading
239236
? const SizedBox(
240-
height: 20,
241-
width: 20,
242-
child: CircularProgressIndicator(strokeWidth: 2),
243-
)
237+
height: 20,
238+
width: 20,
239+
child: CircularProgressIndicator(strokeWidth: 2),
240+
)
244241
: const Text('Create Quest'),
245242
),
246243
),
@@ -250,4 +247,3 @@ class _QuestUploadScreenState extends ConsumerState<QuestUploadScreen> {
250247
);
251248
}
252249
}
253-

app/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ packages:
11561156
source: hosted
11571157
version: "0.7.6"
11581158
timezone:
1159-
dependency: transitive
1159+
dependency: "direct main"
11601160
description:
11611161
name: timezone
11621162
sha256: dd14a3b83cfd7cb19e7888f1cbc20f258b8d71b54c06f79ac585f14093a287d1

app/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ dependencies:
7272
url_launcher: ^6.3.2
7373
file_picker: ^10.3.3
7474
flutter_local_notifications: ^19.5.0
75+
timezone: ^0.10.1
7576

7677
dev_dependencies:
7778
flutter_test:

0 commit comments

Comments
 (0)