Skip to content

damages glitchy behaviour bug fix #672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 13, 2025
Merged
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
56 changes: 37 additions & 19 deletions lib/src/features/damages/pages/damages_list_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_pagination/firebase_pagination.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
Expand All @@ -19,34 +18,53 @@ class DamagesListPage extends ConsumerWidget {
automaticallyImplyLeading: true,
title: const Text('Schademeldingen'),
),
body: FirestorePagination(
query: FirebaseFirestore.instance
body: StreamBuilder<QuerySnapshot<Damage>>(
stream: FirebaseFirestore.instance
.collectionGroup("damages")
.withConverter<Damage>(
fromFirestore: (snapshot, _) =>
Damage.fromJson(snapshot.data() ?? {}),
toFirestore: (reservation, _) => reservation.toJson(),
)
.orderBy('critical', descending: true)
.orderBy('createdTime', descending: true),
itemBuilder: (context, snap, index) {
final pollSnapshot = snap as QueryDocumentSnapshot<Damage>;
.orderBy('createdTime', descending: true)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
}
if (snapshot.hasError) {
return const Center(child: Text('Error loading damages'));
}
if (!snapshot.hasData || snapshot.data!.docs.isEmpty) {
return const Center(child: Text('No damages found'));
}

return DamageTileWidget(
showDamage: () => context.goNamed('Show Damage', queryParameters: {
'id': pollSnapshot.id,
'reservationObjectId': pollSnapshot.data().parent.id,
}),
editDamage: () => context.goNamed('Edit Damage', queryParameters: {
'id': pollSnapshot.id,
'reservationObjectId': pollSnapshot.data().parent.id,
}),
damageSnapshot: pollSnapshot,
final damages = snapshot.data!.docs;

return ListView.separated(
padding: const EdgeInsets.all(8),
itemCount: damages.length,
itemBuilder: (context, index) {
final pollSnapshot = damages[index];

return DamageTileWidget(
showDamage: () =>
context.goNamed('Show Damage', queryParameters: {
'id': pollSnapshot.id,
'reservationObjectId': pollSnapshot.data().parent.id,
}),
editDamage: () =>
context.goNamed('Edit Damage', queryParameters: {
'id': pollSnapshot.id,
'reservationObjectId': pollSnapshot.data().parent.id,
}),
damageSnapshot: pollSnapshot,
);
},
separatorBuilder: (context, index) => const SizedBox(height: gapY),
);
},
separatorBuilder: (context, index) => const SizedBox(height: gapY),
isLive: true,
padding: const EdgeInsets.all(8),
),
floatingActionButton: FirebaseAuth.instance.currentUser !=
null // Only show button if user is logged in.
Expand Down
4 changes: 2 additions & 2 deletions lib/src/features/forms/widgets/form_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ class FormCard extends ConsumerWidget {
),
if (form.maximumNumberIsVisible == true)
countAnswerProvider.when(
data: (count) => Text(
"Aantal antwoorden: $count / ${form.maximumNumberOfAnswers ?? '∞'}",
data: (answerCount) => Text(
"Aantal antwoorden: $answerCount / ${form.maximumNumberOfAnswers ?? '∞'}",
style: textTheme.bodyMedium
?.copyWith(color: colorScheme.outline),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ class CreatePushNotificationPageState
);

// Show confirmation message
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content:
Text("Push notificatie is verstuurd en opgeslagen."),
),
);
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content:
Text("Push notificatie is verstuurd en opgeslagen."),
),
);

Navigator.of(context).pop();
Navigator.of(context).pop();
}
},
child: const Text('Verstuur'),
),
Expand Down