Commit e2b4bc7d authored by GayaniPKarunaratne's avatar GayaniPKarunaratne

Coneect to Firebase

parent b5fc977c
...@@ -35,7 +35,7 @@ android { ...@@ -35,7 +35,7 @@ android {
defaultConfig { defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.covidefender" applicationId "com.example.covidefender"
minSdkVersion 16 minSdkVersion 21
targetSdkVersion 30 targetSdkVersion 30
versionCode flutterVersionCode.toInteger() versionCode flutterVersionCode.toInteger()
versionName flutterVersionName versionName flutterVersionName
...@@ -56,4 +56,8 @@ flutter { ...@@ -56,4 +56,8 @@ flutter {
dependencies { dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-analytics'
} }
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
{
"project_info": {
"project_number": "206817019032",
"firebase_url": "https://covidefender-5b8b1-default-rtdb.firebaseio.com",
"project_id": "covidefender-5b8b1",
"storage_bucket": "covidefender-5b8b1.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:206817019032:android:8c981d64ba61069de4bced",
"android_client_info": {
"package_name": "com.example.covidefender"
}
},
"oauth_client": [
{
"client_id": "206817019032-grv9328g4hup8db6vp987rt6nmrdmd3b.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyDTZ7KVRrYQylCKI58uqhe6ugoKhti1t8E"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "206817019032-grv9328g4hup8db6vp987rt6nmrdmd3b.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
\ No newline at end of file
...@@ -8,6 +8,7 @@ buildscript { ...@@ -8,6 +8,7 @@ buildscript {
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.1.0' classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.8'
} }
} }
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class AddLocation extends StatefulWidget { class AddLocation extends StatefulWidget {
@override @override
...@@ -7,119 +8,113 @@ class AddLocation extends StatefulWidget { ...@@ -7,119 +8,113 @@ class AddLocation extends StatefulWidget {
class AddLocationState extends State<AddLocation> { class AddLocationState extends State<AddLocation> {
String _fName; String userName;
String _lName; String phoneNumber;
String _age; String riskLocation;
String _address; String hotelName;
String _nic; String date;
String _phoneNumber; String time;
String _riskLocation;
String _hotelName;
String _date;
String _time;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); getUserName(name){
this.userName= name;
}
Widget _buildFName(){ getPhoneNumber(pno){
return TextFormField( this.phoneNumber= pno;
decoration: InputDecoration(labelText: 'First Name'),
validator: (String value){
if (value.isEmpty) {
return '*First Name is Required';
}
},
onSaved: (String value){
_fName = value;
},
);
} }
Widget _buildLName(){ getRiskLocation(location){
return TextFormField( this.riskLocation= location;
decoration: InputDecoration(labelText: 'Last Name'),
validator: (String value){
if (value.isEmpty) {
return '*Last Name is Required';
}
},
onSaved: (String value){
_lName = value;
},
);
} }
Widget _buildAge(){ getHotelName(hotelname){
return TextFormField( this.hotelName= hotelname;
decoration: InputDecoration(labelText: 'Age'),
validator: (String value){
if (value.isEmpty) {
return '*Age is Required';
}
},
onSaved: (String value){
_age = value;
},
);
} }
Widget _buildAddress(){ getDate(date){
return TextFormField( this.date= date;
decoration: InputDecoration(labelText: 'Address'), }
validator: (String value){
if (value.isEmpty) { getTime(time){
return '*Address is Required'; this.time= time;
}
},
onSaved: (String value){
_address = value;
},
);
} }
Widget _buildNIC(){ createData(){
print("object");
DocumentReference documentReference = Firestore.instance.collection("RiskLocation").document(userName);
Map<String, dynamic> locations ={
"userName": userName,
"phoneNumber": phoneNumber,
"riskLocation": riskLocation,
"hotelName": hotelName,
"date": date,
"time": time
};
documentReference.setData(locations).whenComplete(() {
print("$userName created");
});
}
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
//---------------------------------------------User Name-----------------------------------------------------
Widget _buildName(){
return TextFormField( return TextFormField(
decoration: InputDecoration(labelText: 'NIC'), decoration: InputDecoration(labelText: 'Full Name'),
validator: (String value){ validator: (String value){
if (value.isEmpty) { if (value.isEmpty) {
return '*NIC is Required'; return '*Full Name is Required';
} }
}, },
onSaved: (String value){ // onSaved: (String value){
_nic = value; // _fName = value;
// },
onChanged: (String name){
getUserName(name);
}, },
); );
} }
Widget _buildPhoneNumber(){ //---------------------------------------------Phone Number-----------------------------------------------------
Widget _buildPNo(){
return TextFormField( return TextFormField(
decoration: InputDecoration(labelText: 'Phone Number'), decoration: InputDecoration(labelText: 'Phone Number'),
keyboardType: TextInputType.phone,
maxLength: 10,
validator: (String value){ validator: (String value){
if (value.isEmpty) { if (value.isEmpty) {
return '*Phone Number is Required'; return '*Phone Number is Required';
} }
}, },
onSaved: (String value){ // onSaved: (String value){
_phoneNumber = value; // _lName = value;
// },
onChanged: (String id){
getPhoneNumber(phoneNumber);
}, },
); );
} }
Widget _buildRiskLocation(){ //---------------------------------------------Risk Location-----------------------------------------------------
Widget _buildLocation(){
return TextFormField( return TextFormField(
decoration: InputDecoration(labelText: 'Risk Location'), decoration: InputDecoration(labelText: 'Risk Location'),
validator: (String value){ validator: (String value){
if (value.isEmpty) { if (value.isEmpty) {
return '*Location is Required'; return '*Risk Location is Required';
} }
}, },
onSaved: (String value){ // onSaved: (String value){
_riskLocation = value; // _age = value;
// },
onChanged: (String riskLocation){
getRiskLocation(riskLocation);
}, },
); );
} }
//---------------------------------------------Hotel Name-----------------------------------------------------
Widget _buildHotelName(){ Widget _buildHotelName(){
return TextFormField( return TextFormField(
decoration: InputDecoration(labelText: 'Hotel Name'), decoration: InputDecoration(labelText: 'Hotel Name'),
...@@ -128,37 +123,49 @@ Widget _buildHotelName(){ ...@@ -128,37 +123,49 @@ Widget _buildHotelName(){
return '*Hotel Name is Required'; return '*Hotel Name is Required';
} }
}, },
onSaved: (String value){ // onSaved: (String value){
_hotelName = value; // _address = value;
// },
onChanged: (String hotelName){
getHotelName(hotelName);
}, },
); );
} }
//---------------------------------------------Date-----------------------------------------------------
Widget _buildDate(){ Widget _buildDate(){
return TextFormField( return TextFormField(
decoration: InputDecoration(labelText: 'Date'), decoration: InputDecoration(labelText: 'Date'),
keyboardType: TextInputType.datetime,
validator: (String value){ validator: (String value){
if (value.isEmpty) { if (value.isEmpty) {
return '*Date is Required'; return '*Date is Required';
} }
}, },
onSaved: (String value){ // onSaved: (String value){
_date = value; // _nic = value;
// },
onChanged: (String date){
getDate(date);
}, },
); );
} }
//---------------------------------------------Time-----------------------------------------------------
Widget _buildTime(){ Widget _buildTime(){
return TextFormField( return TextFormField(
decoration: InputDecoration(labelText: 'Time'), decoration: InputDecoration(labelText: 'Time'),
keyboardType: TextInputType.phone,
maxLength: 10,
validator: (String value){ validator: (String value){
if (value.isEmpty) { if (value.isEmpty) {
return '*Time is Required'; return '*Time is Required';
} }
}, },
onSaved: (String value){ // onSaved: (String value){
_time = value; // _phoneNumber = value;
// },
onChanged: (String time){
getTime(time);
}, },
); );
} }
...@@ -179,17 +186,14 @@ Widget _buildTime(){ ...@@ -179,17 +186,14 @@ Widget _buildTime(){
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
_buildFName(), _buildName(),
_buildLName(), _buildPNo(),
_buildAge(), _buildLocation(),
_buildAddress(),
_buildNIC(),
_buildPhoneNumber(),
_buildRiskLocation(),
_buildHotelName(), _buildHotelName(),
_buildDate(), _buildDate(),
_buildTime(), _buildTime(),
SizedBox(height: 100), SizedBox(height: 100),
RaisedButton( RaisedButton(
child: Text( child: Text(
...@@ -201,23 +205,24 @@ Widget _buildTime(){ ...@@ -201,23 +205,24 @@ Widget _buildTime(){
return; return;
} }
_formKey.currentState.save(); // _formKey.currentState.save();
print(_fName); // print(_fName);
print(_lName); // print(_lName);
print(_age); // print(_age);
print(_address); // print(_address);
print(_nic); // print(_nic);
print(_phoneNumber); // print(_phoneNumber);
print(_riskLocation); // print(_riskLocation);
print(_hotelName); // print(_hotelName);
print(_date); // print(_date);
print(_time); // print(_time);
createData();
} , } ,
) )
], ],
),), ),),
), ),
......
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'home_screen.dart'; import 'home_screen.dart';
void main() => runApp(MyApp()); // void main() => runApp(MyApp());
void main() async{
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -36,6 +36,27 @@ packages: ...@@ -36,6 +36,27 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.0" version: "1.1.0"
cloud_firestore:
dependency: "direct main"
description:
name: cloud_firestore
url: "https://pub.dartlang.org"
source: hosted
version: "0.14.4"
cloud_firestore_platform_interface:
dependency: transitive
description:
name: cloud_firestore_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.1"
cloud_firestore_web:
dependency: transitive
description:
name: cloud_firestore_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.1+2"
collection: collection:
dependency: transitive dependency: transitive
description: description:
...@@ -57,6 +78,27 @@ packages: ...@@ -57,6 +78,27 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0" version: "1.2.0"
firebase_core:
dependency: "direct main"
description:
name: firebase_core
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.3"
firebase_core_platform_interface:
dependency: transitive
description:
name: firebase_core_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
firebase_core_web:
dependency: transitive
description:
name: firebase_core_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.1+1"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
...@@ -74,6 +116,25 @@ packages: ...@@ -74,6 +116,25 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.4"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:
...@@ -116,6 +177,20 @@ packages: ...@@ -116,6 +177,20 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "4.1.0" version: "4.1.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.5"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
...@@ -127,7 +202,7 @@ packages: ...@@ -127,7 +202,7 @@ packages:
name: source_span name: source_span
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.0" version: "1.8.1"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
...@@ -162,7 +237,7 @@ packages: ...@@ -162,7 +237,7 @@ packages:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.19" version: "0.3.0"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
......
...@@ -21,9 +21,12 @@ environment: ...@@ -21,9 +21,12 @@ environment:
sdk: ">=2.7.0 <3.0.0" sdk: ">=2.7.0 <3.0.0"
dependencies: dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
flutter_svg: ^0.22.0 flutter_svg: ^0.22.0
cloud_firestore: ^0.14.3
firebase_core : ^0.5.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment