diff --git a/android/app/build.gradle b/android/app/build.gradle index 65a82cd..9ae909c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -24,6 +24,8 @@ if (flutterVersionName == null) { apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" +apply plugin: 'com.android.application' +apply plugin: 'com.google.gms.google-services' android { compileSdkVersion 30 @@ -35,10 +37,11 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.plaso_connect" - minSdkVersion 16 + minSdkVersion 23 targetSdkVersion 30 versionCode flutterVersionCode.toInteger() versionName flutterVersionName + multiDexEnabled true } buildTypes { @@ -56,4 +59,6 @@ flutter { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation platform('com.google.firebase:firebase-bom:27.1.0') + implementation 'com.android.support:multidex:1.0.3' } diff --git a/android/app/google-services.json b/android/app/google-services.json new file mode 100644 index 0000000..9d8a43a --- /dev/null +++ b/android/app/google-services.json @@ -0,0 +1,47 @@ +{ + "project_info": { + "project_number": "738401306408", + "project_id": "plaso-connect-demo", + "storage_bucket": "plaso-connect-demo.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:738401306408:android:ffd9fe0392346ec6ea721d", + "android_client_info": { + "package_name": "com.example.plaso_connect" + } + }, + "oauth_client": [ + { + "client_id": "738401306408-j2pu2fmtuhmkbe2k5sks08ptjlmutik4.apps.googleusercontent.com", + "client_type": 1, + "android_info": { + "package_name": "com.example.plaso_connect", + "certificate_hash": "d7126d7e8df9109930d3da8d61331117d2282ed3" + } + }, + { + "client_id": "738401306408-6vobpdsuchf4ovvrgmvgvvp33fqf3q7e.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyCM2ndPvkDWVKg7-SLGwdTVd5is-OhZ87Q" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [ + { + "client_id": "738401306408-6vobpdsuchf4ovvrgmvgvvp33fqf3q7e.apps.googleusercontent.com", + "client_type": 3 + } + ] + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index 5560710..d165cdf 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -8,6 +8,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:4.1.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath 'com.google.gms:google-services:4.3.5' } } diff --git a/lib/main.dart b/lib/main.dart index f146d84..d600826 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,12 +1,13 @@ +import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:plaso_connect/constants/colors.dart'; -import 'package:plaso_connect/screens/statdashboard.dart'; +import 'package:plaso_connect/screens/donorlist.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); - // await Firebase.initializeApp(); + await Firebase.initializeApp(); SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, ]).then((val) { @@ -29,7 +30,7 @@ class MyApp extends StatelessWidget { primaryColor: kelectronBlue, iconTheme: IconThemeData(color: kelectronBlue), ), - home: TotalStatsDashboard(), + home: DonorList(), ); } } diff --git a/lib/models/donormodel.dart b/lib/models/donormodel.dart new file mode 100644 index 0000000..7763962 --- /dev/null +++ b/lib/models/donormodel.dart @@ -0,0 +1,37 @@ +class DonorModel { + final String name; + final String phone; + final String age; + final String address; + final String pin; + final String bloodGroup; + final String covidStatus; + final String dateOfRecovery; + final String vaccinationStatus; + + DonorModel({ + required this.name, + required this.phone, + required this.age, + required this.address, + required this.pin, + required this.bloodGroup, + required this.covidStatus, + required this.dateOfRecovery, + required this.vaccinationStatus, + }); + + Map toMap() { + return { + 'name': name, + 'phone': phone, + 'age': age, + 'address': address, + 'pin': pin, + 'bloodGroup': bloodGroup, + 'covidStatus': covidStatus, + 'dateOfRecovery': dateOfRecovery, + 'vaccinationStatus': vaccinationStatus, + }; + } +} diff --git a/lib/screens/donorlist.dart b/lib/screens/donorlist.dart new file mode 100644 index 0000000..e53f7f1 --- /dev/null +++ b/lib/screens/donorlist.dart @@ -0,0 +1,140 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:flutter/material.dart'; +import 'package:plaso_connect/constants/colors.dart'; +import 'package:plaso_connect/models/donormodel.dart'; +import 'package:plaso_connect/widgets/boxdecoration.dart'; + +class DonorList extends StatefulWidget { + @override + _DonorListState createState() => _DonorListState(); +} + +class _DonorListState extends State { + // late Stream alldonors; + + // getallDonors() { + // alldonors = DatabaseMethod().getDonors(pin: "733202"); + // setState(() {}); + // } + + // @override + // void initState() { + // super.initState(); + // getallDonors(); + // } + + @override + Widget build(BuildContext context) { + Size size = MediaQuery.of(context).size; + return SafeArea( + child: Scaffold( + appBar: AppBar( + title: Text("Donor List"), + centerTitle: true, + ), + body: Container( + height: size.height, + width: size.width, + child: StreamBuilder( + stream: FirebaseFirestore.instance + .collection("plasmaDonors") + .snapshots(), + builder: + (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.hasData) { + return ListView.builder( + itemCount: snapshot.data!.docs.length, + itemBuilder: (context, index) { + DonorModel donorModel = DonorModel( + name: snapshot.data!.docs[index]["name"], + phone: snapshot.data!.docs[index]["phone"], + age: snapshot.data!.docs[index]["age"], + address: snapshot.data!.docs[index]["address"], + pin: snapshot.data!.docs[index]["pin"], + bloodGroup: snapshot.data!.docs[index]["bloodGroup"], + covidStatus: snapshot.data!.docs[index]["covidStatus"], + dateOfRecovery: snapshot.data!.docs[index] + ["dateOfRecovery"], + vaccinationStatus: snapshot.data!.docs[index] + ["vaccinationStatus"], + ); + return donorCard( + donorModel: donorModel, + size: size, + ); + }, + ); + } else if (snapshot.hasError) { + return Text("Error"); + } else { + return Center( + child: CircularProgressIndicator(), + ); + } + }, + ), + ), + ), + ); + } + + Widget donorCard({required DonorModel donorModel, required Size size}) { + return Container( + margin: EdgeInsets.all(20), + padding: EdgeInsets.all(20), + decoration: newboxDecoration(), + width: size.width, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "${donorModel.name}, ${donorModel.age}, ${donorModel.bloodGroup}", + style: TextStyle( + color: kelectronBlue, + fontSize: 22, + fontWeight: FontWeight.w600, + ), + ), + SizedBox(height: 3), + Text( + donorModel.address, + style: TextStyle( + color: kelectronBlue, + fontSize: 20, + fontWeight: FontWeight.w500, + ), + ), + SizedBox(height: 3), + Text( + "PIN: ${donorModel.pin}", + style: TextStyle( + color: kelectronBlue, + fontSize: 20, + fontWeight: FontWeight.w600, + ), + ), + SizedBox(height: 3), + Text( + "Phone: ${donorModel.phone}", + style: TextStyle( + color: kelectronBlue, + fontSize: 20, + fontWeight: FontWeight.w600, + ), + ), + SizedBox(height: 3), + Text( + (donorModel.vaccinationStatus == "0") + ? "Not Vaccinated yet" + : "Vaccinated", + style: TextStyle( + color: kelectronBlue, + fontSize: 20, + fontWeight: FontWeight.w500, + ), + ), + ], + ), + ); + } +} diff --git a/lib/screens/plasmaform.dart b/lib/screens/plasmaform.dart index 85e5baa..c2b8f48 100644 --- a/lib/screens/plasmaform.dart +++ b/lib/screens/plasmaform.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:plaso_connect/constants/colors.dart'; +import 'package:plaso_connect/models/donormodel.dart'; +import 'package:plaso_connect/services/database.dart'; import 'package:plaso_connect/widgets/inputfield.dart'; class PlasmaDonate extends StatefulWidget { @@ -43,6 +45,34 @@ class _PlasmaDonateState extends State { super.dispose(); } + void donePressed() async { + var donorModel = DonorModel( + name: namecontroller.text, + phone: phonecontroller.text, + age: agecontroller.text, + address: addresscontroller.text, + pin: pincontroller.text, + bloodGroup: bloodGroup, + covidStatus: covidStatus.toString(), + dateOfRecovery: dateOfRecoverycontroller.text, + vaccinationStatus: isVaccinated.toString(), + ); + await DatabaseMethod().uploadDonor(donorModel); + clearInput(); + } + + void clearInput() { + namecontroller.clear(); + phonecontroller.clear(); + agecontroller.clear(); + addresscontroller.clear(); + pincontroller.clear(); + dateOfRecoverycontroller.clear(); + isVaccinated = 1; + bloodGroup = "A+"; + covidStatus = 1; + } + @override Widget build(BuildContext context) { final Size size = MediaQuery.of(context).size; @@ -285,12 +315,14 @@ class _PlasmaDonateState extends State { ], ), ), - inputforPlasma( - controller: dateOfRecoverycontroller, - prefixIcon: Icons.date_range_rounded, - hintText: "Date of Recovery", - textInputType: TextInputType.datetime, - ), + (covidStatus == 1) + ? inputforPlasma( + controller: dateOfRecoverycontroller, + prefixIcon: Icons.date_range_rounded, + hintText: "Date of Recovery", + textInputType: TextInputType.datetime, + ) + : Container(height: 0), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -361,7 +393,7 @@ class _PlasmaDonateState extends State { SizedBox(height: 20), GestureDetector( onTap: () { - print("Done"); + donePressed(); }, child: doneBtn(), ), diff --git a/lib/screens/statdashboard.dart b/lib/screens/statdashboard.dart index 573dfcf..fc3b23c 100644 --- a/lib/screens/statdashboard.dart +++ b/lib/screens/statdashboard.dart @@ -87,10 +87,12 @@ class _TotalStatsDashboardState extends State { } Widget bodyContainer({required Size size}) { - Widget finalWidget = SizedBox( - height: 150, - width: 150, - child: CircularProgressIndicator(), + Widget finalWidget = Center( + child: SizedBox( + height: 50, + width: 50, + child: CircularProgressIndicator(), + ), ); if (!isloading) { diff --git a/lib/services/database.dart b/lib/services/database.dart new file mode 100644 index 0000000..bceb548 --- /dev/null +++ b/lib/services/database.dart @@ -0,0 +1,23 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:plaso_connect/models/donormodel.dart'; + +class DatabaseMethod { + final FirebaseFirestore db = FirebaseFirestore.instance; + + Future uploadDonor(DonorModel donorModel) async { + var userMap = donorModel.toMap(); + try { + await db.collection("plasmaDonors").doc(donorModel.phone).set(userMap); + print("Done"); + } catch (e) { + print(e.toString()); + } + } + + Stream getDonors({required String pin}) { + return db + .collection("plasmaDonors") + .where("pin", isEqualTo: pin) + .snapshots(); + } +} diff --git a/pubspec.lock b/pubspec.lock index c46f303..821f093 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -36,6 +36,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" + cloud_firestore: + dependency: "direct main" + description: + name: cloud_firestore + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.7" + cloud_firestore_platform_interface: + dependency: transitive + description: + name: cloud_firestore_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.3" + cloud_firestore_web: + dependency: transitive + description: + name: cloud_firestore_web + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.7" collection: dependency: transitive description: @@ -78,6 +99,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "6.1.0" + firebase_auth: + dependency: "direct main" + description: + name: firebase_auth + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.2" + firebase_auth_platform_interface: + dependency: transitive + description: + name: firebase_auth_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "4.2.0" + firebase_auth_web: + dependency: transitive + description: + name: firebase_auth_web + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + firebase_core: + dependency: "direct main" + description: + name: firebase_core + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + firebase_core_platform_interface: + dependency: transitive + description: + name: firebase_core_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.0" + firebase_core_web: + dependency: transitive + description: + name: firebase_core_web + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" flutter: dependency: "direct main" description: flutter @@ -95,6 +158,11 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" google_fonts: dependency: "direct main" description: @@ -123,6 +191,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.17.0" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.3" matcher: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index de5ab1e..7f616e0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,7 +27,9 @@ dependencies: google_fonts: ^2.0.0 intl: ^0.17.0 percent_indicator: ^3.0.1 - + firebase_core: ^1.1.0 + firebase_auth: ^1.1.2 + cloud_firestore: ^1.0.7 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.