-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsimplefirecrud.dart
89 lines (78 loc) · 2.48 KB
/
simplefirecrud.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//main.dart
//dependency
//add cloud_firebase in pubspec.yaml
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
home: Adddatatofirestore(),
);
}
}
class Adddatatofirestore extends StatefulWidget {
@override
_AdddatatofirestoreState createState() => _AdddatatofirestoreState();
}
class _AdddatatofirestoreState extends State<Adddatatofirestore> {
final db = Firestore.instance;
final _controller = TextEditingController();
final _controller2 = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Material App Bar'),
),
body: ListView(
children: <Widget>[
Column(
children: <Widget>[
Text('Nama Student:'),
TextField(controller: _controller,),
Text('Student ID:'),
TextField(controller: _controller2,),
RaisedButton(
child:Text('Submit'),
onPressed: () async {
await db.collection('info').add(
{
'studentname': _controller.text,
'studentic': _controller2.text,
},
);
},
),
StreamBuilder<QuerySnapshot>(
stream: db.collection('info').snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Column(
children: snapshot.data.documents.map((doc) {
return ListTile(
title: Text(doc.data['studentname']),
subtitle: Text(doc.data['studentic']),
);
}).toList(),
);
} else {
return SizedBox();
}
}),
],
),
],
),
);
}
}
//ERROR ISSUE:
//if you have error in Android it's because of Multidex
//just add Multidex support to your App Gradle file under defaultConfig section as shown below
//defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
// multiDexEnabled true
// }