Skip to content

Commit

Permalink
Merge pull request #6 from niloysikdar/database
Browse files Browse the repository at this point in the history
Database
  • Loading branch information
niloysikdar authored May 1, 2021
2 parents 09b624a + 84c7355 commit f3faba7
Show file tree
Hide file tree
Showing 11 changed files with 381 additions and 16 deletions.
7 changes: 6 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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'
}
47 changes: 47 additions & 0 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down
7 changes: 4 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -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<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// await Firebase.initializeApp();
await Firebase.initializeApp();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]).then((val) {
Expand All @@ -29,7 +30,7 @@ class MyApp extends StatelessWidget {
primaryColor: kelectronBlue,
iconTheme: IconThemeData(color: kelectronBlue),
),
home: TotalStatsDashboard(),
home: DonorList(),
);
}
}
37 changes: 37 additions & 0 deletions lib/models/donormodel.dart
Original file line number Diff line number Diff line change
@@ -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<String, dynamic> toMap() {
return {
'name': name,
'phone': phone,
'age': age,
'address': address,
'pin': pin,
'bloodGroup': bloodGroup,
'covidStatus': covidStatus,
'dateOfRecovery': dateOfRecovery,
'vaccinationStatus': vaccinationStatus,
};
}
}
140 changes: 140 additions & 0 deletions lib/screens/donorlist.dart
Original file line number Diff line number Diff line change
@@ -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<DonorList> {
// 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<QuerySnapshot> 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,
),
),
],
),
);
}
}
46 changes: 39 additions & 7 deletions lib/screens/plasmaform.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -43,6 +45,34 @@ class _PlasmaDonateState extends State<PlasmaDonate> {
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;
Expand Down Expand Up @@ -285,12 +315,14 @@ class _PlasmaDonateState extends State<PlasmaDonate> {
],
),
),
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: [
Expand Down Expand Up @@ -361,7 +393,7 @@ class _PlasmaDonateState extends State<PlasmaDonate> {
SizedBox(height: 20),
GestureDetector(
onTap: () {
print("Done");
donePressed();
},
child: doneBtn(),
),
Expand Down
10 changes: 6 additions & 4 deletions lib/screens/statdashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ class _TotalStatsDashboardState extends State<TotalStatsDashboard> {
}

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) {
Expand Down
Loading

0 comments on commit f3faba7

Please sign in to comment.