Created
December 12, 2018 14:56
-
-
Save jrhml05/eb1a1df5c9a3a53514522601394b8dec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:flutter/material.dart'; | |
import '../navigation.dart'; | |
import 'package:location/location.dart'; | |
import 'package:flutter/services.dart'; | |
import 'package:cloud_firestore/cloud_firestore.dart'; | |
import '../global.dart' as global; | |
import 'householder.dart'; | |
import 'package:latlong/latlong.dart'; | |
import 'package:flutter/services.dart'; | |
void main() => runApp(new AddHouseHolder()); | |
class AddHouseHolder extends StatefulWidget { | |
@override | |
_AddHouseHolderState createState() => new _AddHouseHolderState(); | |
} | |
// class _LoginPageState extends State<LoginPage> { | |
class _AddHouseHolderState extends State<AddHouseHolder> { | |
String age; | |
String contactNo; | |
String fullAdd; | |
String gender; | |
String language; | |
GeoPoint loc; | |
String name; | |
String origin; | |
String spouse; | |
final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); | |
@override | |
Widget build(BuildContext context) { | |
// TODO: implement build | |
return MaterialApp( | |
home: Scaffold( | |
// drawer: NavigationDraw(), | |
appBar: AppBar( | |
title: Text('Add House Holder'), | |
), | |
body: SingleChildScrollView( | |
child: Container( | |
padding: EdgeInsets.all(5.0), | |
child: Column( | |
children: <Widget>[ | |
Form( | |
child: Column( | |
children: <Widget>[ | |
TextField( | |
onChanged: (value) { | |
this.name = value; | |
}, | |
decoration: InputDecoration( | |
labelText: 'Name', hintText: 'Name'), | |
), | |
TextField( | |
onChanged: (value) { | |
this.gender = value; | |
}, | |
decoration: InputDecoration( | |
labelText: 'Gender', hintText: 'Gender'), | |
), | |
TextField( | |
onChanged: (value) { | |
this.age = value; | |
}, | |
decoration: InputDecoration( | |
labelText: 'Age', hintText: 'Age'), | |
keyboardType: TextInputType.number, | |
), | |
TextField( | |
onChanged: (value) { | |
this.spouse = value; | |
}, | |
decoration: InputDecoration( | |
labelText: 'Spouse', hintText: 'Spouse'), | |
), | |
TextField( | |
onChanged: (value) { | |
this.fullAdd = value; | |
}, | |
decoration: InputDecoration( | |
labelText: 'Address', hintText: 'Address'), | |
), | |
TextField( | |
controller: TextEditingController.fromValue( | |
new TextEditingValue(text: 'loc')), | |
decoration: InputDecoration( | |
labelText: 'Location', hintText: 'Location'), | |
// onTap: () {}, | |
), | |
TextField( | |
onChanged: (value) { | |
this.contactNo = value; | |
}, | |
decoration: InputDecoration( | |
labelText: 'Contact Number', | |
hintText: 'Contact Number'), | |
keyboardType: TextInputType.number, | |
), | |
TextField( | |
onChanged: (value) { | |
this.origin = value; | |
}, | |
decoration: InputDecoration( | |
labelText: 'Origin', hintText: 'Origin'), | |
), | |
TextField( | |
onChanged: (value) { | |
this.language = value; | |
}, | |
decoration: InputDecoration( | |
labelText: 'Language', hintText: 'Language'), | |
), | |
Padding( | |
padding: const EdgeInsets.only(top: 10.0), | |
), | |
new RaisedButton( | |
color: Colors.blue, | |
textColor: Colors.white, | |
child: new Text('SAVE'), | |
onPressed: () { | |
saveHouseHolder(); | |
}, | |
splashColor: Colors.black, | |
) | |
], | |
), | |
) | |
], | |
)))), | |
); | |
} | |
Future<void> saveHouseHolder() async { | |
Firestore.instance.runTransaction((Transaction transaction) async { | |
CollectionReference reference = Firestore.instance | |
.collection('municipality') | |
.document(global.mundocid) | |
.collection('Barangay') | |
.document(global.brgydocid) | |
.collection('HouseHolderList'); | |
await reference.add({ | |
'Name': name, | |
'Gender': gender, | |
'Age': age, | |
'Spouse': spouse, | |
'FullAddress': fullAdd, | |
// 'Location':new GeoPoint(latitude, longitude), | |
'ContactNumber': contactNo, | |
'Origin': origin, | |
'Language': language | |
}); | |
}); | |
Navigator.of(context) | |
.push(MaterialPageRoute(builder: (context) => HouseHolder())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment