ActivitiesView _old.dart 3.56 KB
Newer Older
Uditha Prabhasha 's avatar
Uditha Prabhasha committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
// import 'package:flutter/material.dart';
// import 'package:cloud_firestore/cloud_firestore.dart';
// import 'package:cached_network_image/cached_network_image.dart';
// import 'package:video_player/video_player.dart';

// class UserActivitiesScreen extends StatelessWidget {
//   final String userId;

//   UserActivitiesScreen({required this.userId});

//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//       appBar: AppBar(
//         title: Text('User Activities'),
//       ),
//       body: StreamBuilder<QuerySnapshot>(
//         stream: FirebaseFirestore.instance
//             .collection('activities')
//             .where('user', isEqualTo: userId)
//             .snapshots(),
//         builder: (context, snapshot) {
//           if (snapshot.connectionState == ConnectionState.waiting) {
//             return CircularProgressIndicator(); // Loading indicator
//           }
//           if (snapshot.hasError) {
//             return Text('Error: ${snapshot.error}'); // Error handling
//           }
//           if (snapshot.data == null || snapshot.data!.docs.isEmpty) {
//             return Center(
//               child: Text('No activities found for this user.'),
//             ); // No activities found
//           }

//           return ListView(
//             children: snapshot.data!.docs.map((document) {
//               final videoUrl = document['videoUrl'];
//               final imageUrl = document['imageUrl'];

//               if (videoUrl != null) {
//                 return _buildVideoItem(videoUrl);
//               } else if (imageUrl != null) {
//                 return _buildImageItem(imageUrl);
//               } else {
//                 return SizedBox(); // Return an empty widget if neither video nor image URL is available
//               }
//             }).toList(),
//           );
//         },
//       ),
//     );
//   }

//   Widget _buildVideoItem(String videoUrl) {
//     return ListTile(
//       title: Text('Activity Video'),
//       leading: FutureBuilder(
//         future: VideoPlayerController.network(videoUrl).initialize(),
//         builder: (context, snapshot) {
//           if (snapshot.connectionState == ConnectionState.waiting) {
//             return CircularProgressIndicator(); // Placeholder while video loads
//           }
//           if (snapshot.hasError) {
//             return Text('Error: ${snapshot.error}');
//           }
//           if (snapshot.connectionState == ConnectionState.done) {
//             try {
//               final controller = VideoPlayerController.network(videoUrl);
//               return AspectRatio(
//                 aspectRatio: controller.value.aspectRatio,
//                 child: VideoPlayer(controller),
//               );
//             } catch (e) {
//               return Text('Error playing video: $e');
//             }
//           } else {
//             return SizedBox(); // Return empty widget if still loading
//           }
//         },
//       ),
//       onTap: () {
//         // Handle tap, e.g., navigate to a detail screen
//       },
//     );
//   }

//   Widget _buildImageItem(String imageUrl) {
//     return ListTile(
//       title: Text('Activity Image'),
//       leading: CachedNetworkImage(
//         imageUrl: imageUrl,
//         placeholder: (context, url) =>
//             CircularProgressIndicator(), // Placeholder while image loads
//         errorWidget: (context, url, error) => Icon(Icons.error),
//       ),
//       onTap: () {
//         // Handle tap, e.g., navigate to a detail screen
//       },
//     );
//   }
// }