Commit e2b4bc7d authored by GayaniPKarunaratne's avatar GayaniPKarunaratne

Coneect to Firebase

parent b5fc977c
......@@ -35,7 +35,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.covidefender"
minSdkVersion 16
minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
......@@ -56,4 +56,8 @@ flutter {
dependencies {
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 {
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.8'
}
}
......
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class AddLocation extends StatefulWidget {
@override
......@@ -7,119 +8,113 @@ class AddLocation extends StatefulWidget {
class AddLocationState extends State<AddLocation> {
String _fName;
String _lName;
String _age;
String _address;
String _nic;
String _phoneNumber;
String _riskLocation;
String _hotelName;
String _date;
String _time;
String userName;
String phoneNumber;
String riskLocation;
String hotelName;
String date;
String time;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
getUserName(name){
this.userName= name;
}
Widget _buildFName(){
return TextFormField(
decoration: InputDecoration(labelText: 'First Name'),
validator: (String value){
if (value.isEmpty) {
return '*First Name is Required';
}
},
onSaved: (String value){
_fName = value;
},
);
getPhoneNumber(pno){
this.phoneNumber= pno;
}
Widget _buildLName(){
return TextFormField(
decoration: InputDecoration(labelText: 'Last Name'),
validator: (String value){
if (value.isEmpty) {
return '*Last Name is Required';
}
},
onSaved: (String value){
_lName = value;
},
);
getRiskLocation(location){
this.riskLocation= location;
}
Widget _buildAge(){
return TextFormField(
decoration: InputDecoration(labelText: 'Age'),
validator: (String value){
if (value.isEmpty) {
return '*Age is Required';
}
},
onSaved: (String value){
_age = value;
},
);
getHotelName(hotelname){
this.hotelName= hotelname;
}
Widget _buildAddress(){
return TextFormField(
decoration: InputDecoration(labelText: 'Address'),
validator: (String value){
if (value.isEmpty) {
return '*Address is Required';
}
},
onSaved: (String value){
_address = value;
},
);
getDate(date){
this.date= date;
}
getTime(time){
this.time= time;
}
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");
});
}
Widget _buildNIC(){
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
//---------------------------------------------User Name-----------------------------------------------------
Widget _buildName(){
return TextFormField(
decoration: InputDecoration(labelText: 'NIC'),
decoration: InputDecoration(labelText: 'Full Name'),
validator: (String value){
if (value.isEmpty) {
return '*NIC is Required';
return '*Full Name is Required';
}
},
onSaved: (String value){
_nic = value;
// onSaved: (String value){
// _fName = value;
// },
onChanged: (String name){
getUserName(name);
},
);
}
Widget _buildPhoneNumber(){
//---------------------------------------------Phone Number-----------------------------------------------------
Widget _buildPNo(){
return TextFormField(
decoration: InputDecoration(labelText: 'Phone Number'),
keyboardType: TextInputType.phone,
maxLength: 10,
validator: (String value){
if (value.isEmpty) {
return '*Phone Number is Required';
}
},
onSaved: (String value){
_phoneNumber = value;
// onSaved: (String value){
// _lName = value;
// },
onChanged: (String id){
getPhoneNumber(phoneNumber);
},
);
}
Widget _buildRiskLocation(){
//---------------------------------------------Risk Location-----------------------------------------------------
Widget _buildLocation(){
return TextFormField(
decoration: InputDecoration(labelText: 'Risk Location'),
validator: (String value){
if (value.isEmpty) {
return '*Location is Required';
return '*Risk Location is Required';
}
},
onSaved: (String value){
_riskLocation = value;
// onSaved: (String value){
// _age = value;
// },
onChanged: (String riskLocation){
getRiskLocation(riskLocation);
},
);
}
//---------------------------------------------Hotel Name-----------------------------------------------------
Widget _buildHotelName(){
return TextFormField(
decoration: InputDecoration(labelText: 'Hotel Name'),
......@@ -128,37 +123,49 @@ Widget _buildHotelName(){
return '*Hotel Name is Required';
}
},
onSaved: (String value){
_hotelName = value;
// onSaved: (String value){
// _address = value;
// },
onChanged: (String hotelName){
getHotelName(hotelName);
},
);
}
//---------------------------------------------Date-----------------------------------------------------
Widget _buildDate(){
return TextFormField(
decoration: InputDecoration(labelText: 'Date'),
keyboardType: TextInputType.datetime,
validator: (String value){
if (value.isEmpty) {
return '*Date is Required';
}
},
onSaved: (String value){
_date = value;
// onSaved: (String value){
// _nic = value;
// },
onChanged: (String date){
getDate(date);
},
);
}
//---------------------------------------------Time-----------------------------------------------------
Widget _buildTime(){
return TextFormField(
decoration: InputDecoration(labelText: 'Time'),
keyboardType: TextInputType.phone,
maxLength: 10,
validator: (String value){
if (value.isEmpty) {
return '*Time is Required';
}
},
onSaved: (String value){
_time = value;
// onSaved: (String value){
// _phoneNumber = value;
// },
onChanged: (String time){
getTime(time);
},
);
}
......@@ -177,18 +184,15 @@ Widget _buildTime(){
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_buildFName(),
_buildLName(),
_buildAge(),
_buildAddress(),
_buildNIC(),
_buildPhoneNumber(),
_buildRiskLocation(),
_buildHotelName(),
_buildDate(),
_buildTime(),
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_buildName(),
_buildPNo(),
_buildLocation(),
_buildHotelName(),
_buildDate(),
_buildTime(),
SizedBox(height: 100),
RaisedButton(
......@@ -201,23 +205,24 @@ Widget _buildTime(){
return;
}
_formKey.currentState.save();
// _formKey.currentState.save();
print(_fName);
print(_lName);
print(_age);
print(_address);
print(_nic);
print(_phoneNumber);
print(_riskLocation);
print(_hotelName);
print(_date);
print(_time);
// print(_fName);
// print(_lName);
// print(_age);
// print(_address);
// print(_nic);
// print(_phoneNumber);
// print(_riskLocation);
// print(_hotelName);
// print(_date);
// print(_time);
createData();
} ,
)
],
),),
),
......
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.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 {
Widget build(BuildContext context) {
......
......@@ -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: "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:
dependency: transitive
description:
......@@ -57,6 +78,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
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:
dependency: "direct main"
description: flutter
......@@ -74,6 +116,25 @@ packages:
description: flutter
source: sdk
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:
dependency: transitive
description:
......@@ -116,6 +177,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
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:
dependency: transitive
description: flutter
......@@ -127,7 +202,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
......@@ -162,7 +237,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19"
version: "0.3.0"
typed_data:
dependency: transitive
description:
......
......@@ -21,9 +21,12 @@ environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
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