diff --git a/images/add-volunteer.svg b/images/add-volunteer.svg new file mode 100644 index 0000000..8e1db04 --- /dev/null +++ b/images/add-volunteer.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/lib/screens/feed/feed.dart b/lib/screens/feed/feed.dart index 18b2774..2e5c738 100644 --- a/lib/screens/feed/feed.dart +++ b/lib/screens/feed/feed.dart @@ -3,6 +3,7 @@ import 'package:covid_care/constants/colors.dart'; import 'package:covid_care/view_model/feed/feed_list_item_view_model.dart'; import 'package:covid_care/view_model/feed/feed_list_view_model.dart'; import 'package:covid_care/view_model/feed/feed_view_model.dart'; +import 'package:covid_care/widgets/not_found.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:toast/toast.dart'; @@ -21,66 +22,76 @@ class FeedPage extends StatelessWidget { return StreamBuilder( stream: feedViewModel.donarsAsStream(), builder: (context, snapshot) { - if (snapshot.hasData) { + if (snapshot.connectionState == ConnectionState.active) { final feedList = FeedListViewModel.fromSnapshot(snapshot.data); - donors = feedList.donors; - return Container( - width: size.width, - height: size.height, - child: ListView.builder( - itemCount: donors.length, - itemBuilder: (context, index) { - return Center( - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(8), - color: BrandColors.lightBlue, - ), - height: 200, - width: size.width * .8, - child: Column( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - Padding( - padding: const EdgeInsets.symmetric( - horizontal: 16, vertical: 8), - child: Column( - children: [ - SizedBox(height: 8), - _cardTextWidget( - donors[index].volunteer.name, - "Name"), - SizedBox(height: 8), - _cardTextWidget( - donors[index].volunteer.bloodGroup, - "Blood Group"), - SizedBox(height: 8), - _cardTextWidget( - '${donors[index].volunteer.city}, ${donors[index].volunteer.location}', - "Location"), - SizedBox(height: 8), - _cardTextWidget( - donors[index].volunteer.covidMonth, - "Recovered\nfrom Covid"), - ], + if (feedList.donors.length > 0) { + donors = feedList.donors; + return Container( + width: size.width, + height: size.height, + child: ListView.builder( + itemCount: donors.length, + itemBuilder: (context, index) { + return Center( + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8), + color: BrandColors.lightBlue, + ), + height: 200, + width: size.width * .8, + child: Column( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 16, vertical: 8), + child: Column( + children: [ + SizedBox(height: 8), + _cardTextWidget( + donors[index].volunteer.name, + "Name"), + SizedBox(height: 8), + _cardTextWidget( + donors[index] + .volunteer + .bloodGroup, + "Blood Group"), + SizedBox(height: 8), + _cardTextWidget( + '${donors[index].volunteer.city}, ${donors[index].volunteer.location}', + "Location"), + SizedBox(height: 8), + _cardTextWidget( + donors[index] + .volunteer + .covidMonth, + "Recovered\nfrom Covid"), + ], + ), ), - ), - _callNowButton( - donors[index], feedViewModel, context) - ], + _callNowButton( + donors[index], feedViewModel, context) + ], + ), ), ), - ), - ); - }, - )); - } else + ); + }, + )); + } else { + return VolunteerNotFound( + "No Donars found for this blood group"); + } + } else { return Center( child: CircularProgressIndicator( backgroundColor: BrandColors.blue)); + } }); }, ); diff --git a/lib/screens/volunteer/register_volunteer/volunteer_page.dart b/lib/screens/volunteer/register_volunteer/volunteer_page.dart index 42e972a..fb14742 100644 --- a/lib/screens/volunteer/register_volunteer/volunteer_page.dart +++ b/lib/screens/volunteer/register_volunteer/volunteer_page.dart @@ -14,6 +14,7 @@ class VolunteerPage extends StatelessWidget { child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ + SizedBox(), VolunteerFeed(), GestureDetector( onTap: () { diff --git a/lib/screens/volunteer/volunteer_feed/volunteer_feed.dart b/lib/screens/volunteer/volunteer_feed/volunteer_feed.dart index 4dbcd97..321ac95 100644 --- a/lib/screens/volunteer/volunteer_feed/volunteer_feed.dart +++ b/lib/screens/volunteer/volunteer_feed/volunteer_feed.dart @@ -3,6 +3,7 @@ import 'package:covid_care/constants/colors.dart'; import 'package:covid_care/view_model/volunteer/volunteer_feed/volunteer_feed_view_model.dart'; import 'package:covid_care/view_model/volunteer/volunteer_feed/volunteer_item_view_model.dart'; import 'package:covid_care/view_model/volunteer/volunteer_feed/volunteer_list_view_model.dart'; +import 'package:covid_care/widgets/not_found.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:toast/toast.dart'; @@ -20,95 +21,103 @@ class VolunteerFeed extends StatelessWidget { return StreamBuilder( stream: volunteerFeedViewModel.volunteerDetailsAsStream, builder: (context, snapshot) { - if (snapshot.hasData) { + if (snapshot.connectionState == ConnectionState.active) { final feedList = VolunteerListViewModel.fromSnapshot(snapshot.data); volunteers = feedList.volunteers; - return Expanded( - child: ListView.builder( - itemCount: volunteers.length, - itemBuilder: (context, index) { - return Center( - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(8), - color: BrandColors.lightBlue, - ), - height: 200, - width: size.width * .8, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Padding( - padding: const EdgeInsets.symmetric( - horizontal: 16, vertical: 8), - child: Column( - children: [ - SizedBox(height: 8), - _cardTextWidget( - volunteers[index].volunteer.name, - "Name"), - SizedBox(height: 8), - _cardTextWidget( - volunteers[index].volunteer.bloodGroup, - "Blood Group"), - SizedBox(height: 8), - _cardTextWidget( - volunteers[index].volunteer.location, - "Location"), - SizedBox(height: 8), - _cardTextWidget( - volunteers[index].volunteer.covidMonth, - "Recovered\nfrom Covid"), - ], + if (volunteers.isNotEmpty) { + return Expanded( + child: ListView.builder( + itemCount: volunteers.length, + itemBuilder: (context, index) { + return Center( + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8), + color: BrandColors.lightBlue, + ), + height: 200, + width: size.width * .8, + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 16, vertical: 8), + child: Column( + children: [ + SizedBox(height: 8), + _cardTextWidget( + volunteers[index].volunteer.name, + "Name"), + SizedBox(height: 8), + _cardTextWidget( + volunteers[index] + .volunteer + .bloodGroup, + "Blood Group"), + SizedBox(height: 8), + _cardTextWidget( + '${volunteers[index].volunteer.location}, ${volunteers[index].volunteer.city}', + "Location"), + SizedBox(height: 8), + _cardTextWidget( + volunteers[index] + .volunteer + .covidMonth, + "Recovered\nfrom Covid"), + ], + ), ), - ), - _pauseAndDeleteButton(() { - showDialog( - context: context, - builder: (context) { - return Center( - child: Container( - width: 250, - height: 100, - color: Colors.white, - child: Column( - mainAxisAlignment: - MainAxisAlignment.center, - children: [ - SizedBox(height: 10), - Text("Are you sure?"), - SizedBox(height: 10), - MaterialButton( - minWidth: 100, - onPressed: () { - volunteerFeedViewModel - .deleteVolunteer( - volunteers[index]); - Toast.show( - "Volunteer deleted sucessfully!", - context); - Navigator.pop(context); - }, - color: BrandColors.red, - textColor: Colors.white, - child: Text("Delete"), - ), - ], + _pauseAndDeleteButton(() { + showDialog( + context: context, + builder: (context) { + return Center( + child: Container( + width: 250, + height: 100, + color: Colors.white, + child: Column( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + SizedBox(height: 10), + Text("Are you sure?"), + SizedBox(height: 10), + MaterialButton( + minWidth: 100, + onPressed: () { + volunteerFeedViewModel + .deleteVolunteer( + volunteers[index]); + Toast.show( + "Volunteer deleted sucessfully!", + context); + Navigator.pop(context); + }, + color: BrandColors.red, + textColor: Colors.white, + child: Text("Delete"), + ), + ], + ), ), - ), - ); - }); - }) - ], + ); + }); + }) + ], + ), ), ), - ), - ); - }, - )); + ); + }, + )); + } else { + return VolunteerNotFound("Register a donar too see here"); + } } else return Center( child: CircularProgressIndicator( diff --git a/lib/view_model/feed/feed_list_item_view_model.dart b/lib/view_model/feed/feed_list_item_view_model.dart index 887cc52..82e7f58 100644 --- a/lib/view_model/feed/feed_list_item_view_model.dart +++ b/lib/view_model/feed/feed_list_item_view_model.dart @@ -1,11 +1,15 @@ import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:covid_care/models/volunteer_model.dart'; +/// This ViewModel controls single item of Feed page + class FeedListItemViewModel { VolunteerModel volunteer; String id; FeedListItemViewModel(this.volunteer, this.id); + + /// constructor to create a [FeedListViewModel] object from firebase factory FeedListItemViewModel.fromSnapshot( QueryDocumentSnapshot querySnapshot) { VolunteerModel volunteerModel = diff --git a/lib/view_model/feed/feed_list_view_model.dart b/lib/view_model/feed/feed_list_view_model.dart index 7b84d4e..4aa0f9b 100644 --- a/lib/view_model/feed/feed_list_view_model.dart +++ b/lib/view_model/feed/feed_list_view_model.dart @@ -1,10 +1,12 @@ import 'package:cloud_firestore/cloud_firestore.dart'; -import 'package:covid_care/models/volunteer_model.dart'; import 'package:covid_care/view_model/feed/feed_list_item_view_model.dart'; +/// ViewModel to control the list of Volunteers on Feed class FeedListViewModel { List donors = []; FeedListViewModel(this.donors); + + ///constructor to create a [FeedListViewModel] object from firebase factory FeedListViewModel.fromSnapshot(QuerySnapshot querySnapshot) { var donors = querySnapshot.docs .map((item) => FeedListItemViewModel.fromSnapshot(item)) diff --git a/lib/view_model/feed/feed_view_model.dart b/lib/view_model/feed/feed_view_model.dart index e580c77..52bf5da 100644 --- a/lib/view_model/feed/feed_view_model.dart +++ b/lib/view_model/feed/feed_view_model.dart @@ -1,14 +1,19 @@ import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:covid_care/models/volunteer_model.dart'; import 'package:covid_care/view_model/feed/feed_list_item_view_model.dart'; -import 'package:covid_care/view_model/volunteer/volunteer_feed/volunteer_item_view_model.dart'; import 'package:flutter/cupertino.dart'; +///ViewModel to control the Feed class FeedViewModel extends ChangeNotifier { + /// default location var _currentLocation = 'Delhi'; + + /// default blood group var _currentBloodGroup = 'O+'; List donars = []; + /// method to return a [Stream] of [donars] from firebase based on [currentLocation] + /// and [currentBloodGroup] Stream donarsAsStream() => FirebaseFirestore.instance .collection('plasma') .doc(_currentLocation) @@ -16,11 +21,14 @@ class FeedViewModel extends ChangeNotifier { .where('bloodGroup', isEqualTo: _currentBloodGroup) .snapshots(); + /// method to change the currentLocation void changeLocation(String location) { _currentLocation = location; notifyListeners(); } + ///method to increase the value of [calledTimes] + ///here [calledTimes] refers to how many times a donar is called void updateCalled(FeedListItemViewModel itemViewModel) { FirebaseFirestore.instance .collection('plasma') @@ -31,6 +39,7 @@ class FeedViewModel extends ChangeNotifier { notifyListeners(); } + /// method to change the currentBloodGroup void changeBloodGroup(String bloodGroup) { _currentBloodGroup = bloodGroup; notifyListeners(); diff --git a/lib/view_model/volunteer/volunteer_feed/volunteer_feed_view_model.dart b/lib/view_model/volunteer/volunteer_feed/volunteer_feed_view_model.dart index 47d9cbd..6f2f720 100644 --- a/lib/view_model/volunteer/volunteer_feed/volunteer_feed_view_model.dart +++ b/lib/view_model/volunteer/volunteer_feed/volunteer_feed_view_model.dart @@ -26,6 +26,8 @@ class VolunteerFeedViewModel extends ChangeNotifier { .delete(); } + /// this method is not currently in use but plan is to implement feature of pausing account + /// there this will come handy void pauseVolunteer(VolunteerListItemViewModel viewModel) { FirebaseFirestore.instance .collection('users') diff --git a/lib/widgets/not_found.dart b/lib/widgets/not_found.dart new file mode 100644 index 0000000..424f849 --- /dev/null +++ b/lib/widgets/not_found.dart @@ -0,0 +1,24 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_svg/flutter_svg.dart'; + +class VolunteerNotFound extends StatelessWidget { + final title; + VolunteerNotFound(this.title); + @override + Widget build(BuildContext context) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SvgPicture.asset( + 'images/add-volunteer.svg', + width: 300, + ), + SizedBox(height: 40), + Text(title), + ], + ), + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index b68f807..7b156c5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: A new Flutter application. publish_to: "none" -version: 1.0.0+1 +version: 1.0.0+2 environment: sdk: ">=2.7.0 <3.0.0"