Skip to content

Commit 2ebd209

Browse files
committed
Up
1 parent 305258e commit 2ebd209

47 files changed

Lines changed: 478 additions & 340 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/controllers/feed_controller.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,28 @@ class FeedNotifier extends Notifier<FeedState> {
255255
}
256256
}
257257

258+
// -------------------------------------------------------------------------
259+
// Update Post
260+
// -------------------------------------------------------------------------
261+
Future<bool> updatePost({
262+
required String postId,
263+
required String caption,
264+
}) async {
265+
try {
266+
final updatedPost = await feedRepository.updatePost(
267+
postId: postId,
268+
caption: caption,
269+
);
270+
state = state.copyWith(
271+
posts: state.posts.map((p) => p.id == postId ? updatedPost : p).toList(),
272+
);
273+
return true;
274+
} catch (e) {
275+
state = state.copyWith(error: 'Failed to update post: $e');
276+
return false;
277+
}
278+
}
279+
258280
// -------------------------------------------------------------------------
259281
// Delete Post
260282
// -------------------------------------------------------------------------

lib/driver_main.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'package:flutter_driver/driver_extension.dart';
2+
import 'package:pet_dating_app/main.dart' as app;
3+
4+
void main() {
5+
enableFlutterDriverExtension();
6+
app.main();
7+
}

lib/main.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'controllers/theme_controller.dart';
1010
import 'utils/routes.dart';
1111
import 'utils/supabase_config.dart';
1212
import 'utils/theme_bootstrap.dart';
13-
import 'theme/app_theme_v2_material3.dart';
13+
import 'theme/app_theme.dart';
1414

1515
/// Set via `flutter test integration_test/... --dart-define=INTEGRATION_TEST=true`
1616
/// so [IntegrationTestWidgetsFlutterBinding] is not replaced by Marionette.
@@ -22,7 +22,7 @@ const bool _kIntegrationTest = bool.fromEnvironment(
2222
/// `flutter drive` + [enableFlutterDriverExtension] needs a normal binding in debug.
2323
const bool _kFlutterDriverTest = bool.fromEnvironment(
2424
'FLUTTER_DRIVER_TEST',
25-
defaultValue: false,
25+
defaultValue: true,
2626
);
2727

2828
Future<void> main() async {
@@ -65,8 +65,8 @@ class PetSphereApp extends ConsumerWidget {
6565
return _AppLifecycleBootstrapSync(
6666
child: MaterialApp.router(
6767
title: 'PetSphere',
68-
theme: AppThemeV2.lightTheme,
69-
darkTheme: AppThemeV2.darkTheme,
68+
theme: AppTheme.lightTheme,
69+
darkTheme: AppTheme.darkTheme,
7070
themeMode: themeMode,
7171
routerConfig: goRouter,
7272
debugShowCheckedModeBanner: false,

lib/models/pet_activity_log_model.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ class PetActivityLog {
4949

5050
/// Color for the intensity level.
5151
Color get intensityColor => switch (intensity) {
52-
'low' => Colors.green,
53-
'high' => Colors.orange,
54-
_ => Colors.blue,
52+
'low' => const Color(0xFF5BA3F5), // tertiary
53+
'high' => const Color(0xFFFFA726), // secondary
54+
_ => const Color(0xFF2979FF), // primary
5555
};
5656

5757
factory PetActivityLog.fromJson(Map<String, dynamic> json) {

lib/models/pet_expense_model.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ enum ExpenseCategory {
5050
Color get color {
5151
switch (this) {
5252
case ExpenseCategory.food:
53-
return Colors.orange;
53+
return const Color(0xFFFFA726); // secondary
5454
case ExpenseCategory.health:
55-
return Colors.redAccent;
55+
return const Color(0xFFE85D75); // error
5656
case ExpenseCategory.toys:
57-
return Colors.purpleAccent;
57+
return const Color(0xFF5BA3F5); // tertiary
5858
case ExpenseCategory.grooming:
59-
return Colors.blueAccent;
59+
return const Color(0xFF2979FF); // primary
6060
case ExpenseCategory.insurance:
61-
return Colors.teal;
61+
return const Color(0xFF1D1D1F); // deepNavy
6262
case ExpenseCategory.training:
63-
return Colors.indigo;
63+
return const Color(0xFF86868B); // midNavy
6464
case ExpenseCategory.other:
65-
return Colors.grey;
65+
return const Color(0xFF86868B); // midNavy
6666
}
6767
}
6868
}

lib/models/pet_health_extended_models.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ class PetAllergy {
204204
Color get severityColor {
205205
switch (severity) {
206206
case 'life_threatening':
207-
return Colors.red;
207+
return const Color(0xFFE85D75); // error
208208
case 'severe':
209-
return Colors.deepOrange;
209+
return const Color(0xFFE85D75); // error
210210
case 'moderate':
211211
return AppTheme.primaryAccent;
212212
default:
@@ -303,7 +303,7 @@ class ParasitePrevention {
303303
}
304304

305305
Color get urgencyColor {
306-
if (isOverdue) return Colors.red;
306+
if (isOverdue) return const Color(0xFFE85D75); // error
307307
final days = daysUntilDue;
308308
if (days != null && days <= 7) return AppTheme.primaryAccent;
309309
return AppTheme.secondaryAccent;

lib/models/pet_health_models.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class PetSymptom {
2929
Color get severityColor {
3030
switch (severity) {
3131
case 'severe':
32-
return Colors.red;
32+
return const Color(0xFFE85D75);
3333
case 'moderate':
3434
return AppTheme.primaryAccent;
3535
default:

lib/repositories/feed_repository.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,34 @@ class FeedRepository {
257257
.toList();
258258
}
259259

260+
// -------------------------------------------------------------------------
261+
// Update a post
262+
// -------------------------------------------------------------------------
263+
Future<PostModel> updatePost({
264+
required String postId,
265+
required String caption,
266+
String? location,
267+
List<String>? taggedPetIds,
268+
List<String>? taggedPetNames,
269+
}) async {
270+
final payload = {
271+
'caption': caption,
272+
'location': ?location,
273+
'tagged_pet_ids': ?taggedPetIds,
274+
'tagged_pet_names': ?taggedPetNames,
275+
};
276+
277+
final data = await supabase
278+
.from('posts')
279+
.update(payload)
280+
.eq('id', postId)
281+
.select(
282+
'*, pets!posts_pet_id_fkey(*), post_likes(pet_id), comments(*, pets!comments_pet_id_fkey(name, id))')
283+
.single();
284+
285+
return PostModel.fromJson(data);
286+
}
287+
260288
// -------------------------------------------------------------------------
261289
// Delete a post and its related data
262290
// -------------------------------------------------------------------------

lib/utils/post_actions.dart

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_riverpod/flutter_riverpod.dart';
3+
import '../models/post_model.dart';
4+
import '../controllers/feed_controller.dart';
5+
6+
void showEditPostDialog(BuildContext context, WidgetRef ref, PostModel post) {
7+
final controller = TextEditingController(text: post.caption);
8+
showDialog(
9+
context: context,
10+
builder: (ctx) => AlertDialog(
11+
title: const Text('Edit Post'),
12+
content: TextField(
13+
controller: controller,
14+
decoration: const InputDecoration(hintText: 'Enter new caption...'),
15+
maxLines: 3,
16+
),
17+
actions: [
18+
TextButton(
19+
onPressed: () => Navigator.pop(ctx),
20+
child: const Text('Cancel'),
21+
),
22+
FilledButton(
23+
onPressed: () async {
24+
final success = await ref
25+
.read(feedProvider.notifier)
26+
.updatePost(postId: post.id, caption: controller.text);
27+
if (ctx.mounted) {
28+
Navigator.pop(ctx);
29+
if (success) {
30+
ScaffoldMessenger.of(context).showSnackBar(
31+
const SnackBar(content: Text('Post updated!')),
32+
);
33+
}
34+
}
35+
},
36+
child: const Text('Save'),
37+
),
38+
],
39+
),
40+
);
41+
}
42+
43+
void showDeletePostDialog(BuildContext context, WidgetRef ref, PostModel post, {VoidCallback? onDeleteSuccess}) {
44+
showDialog(
45+
context: context,
46+
builder: (ctx) => AlertDialog(
47+
title: const Text('Delete Post'),
48+
content: const Text('Are you sure you want to delete this post? This action cannot be undone.'),
49+
actions: [
50+
TextButton(
51+
onPressed: () => Navigator.pop(ctx),
52+
child: const Text('Cancel'),
53+
),
54+
FilledButton(
55+
onPressed: () async {
56+
final success = await ref
57+
.read(feedProvider.notifier)
58+
.deletePost(post.id);
59+
if (ctx.mounted) {
60+
Navigator.pop(ctx);
61+
if (success) {
62+
ScaffoldMessenger.of(context).showSnackBar(
63+
const SnackBar(content: Text('Post deleted.')),
64+
);
65+
onDeleteSuccess?.call();
66+
}
67+
}
68+
},
69+
style: FilledButton.styleFrom(
70+
backgroundColor: Theme.of(context).colorScheme.error,
71+
foregroundColor: Theme.of(context).colorScheme.onError,
72+
),
73+
child: const Text('Delete'),
74+
),
75+
],
76+
),
77+
);
78+
}

lib/utils/routes.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ final routerProvider = Provider<GoRouter>((ref) {
291291
child: Column(
292292
mainAxisSize: MainAxisSize.min,
293293
children: [
294-
const Icon(Icons.error_outline,
295-
size: 56, color: Colors.redAccent),
294+
Icon(Icons.error_outline,
295+
size: 56, color: Theme.of(context).colorScheme.error),
296296
const SizedBox(height: 12),
297297
Text(
298298
'We could not find what you were looking for.',

0 commit comments

Comments
 (0)