Skip to content

Commit e324b1e

Browse files
committed
fb login fixed and user can post once every 5 min
1 parent 6cd7e08 commit e324b1e

5 files changed

Lines changed: 68 additions & 9 deletions

File tree

.flutter-plugins-dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"firebase_auth","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_auth-0.15.5+2\\\\","dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core-0.4.4+3\\\\","dependencies":[]},{"name":"firebase_database","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_database-3.1.3\\\\","dependencies":["firebase_core"]},{"name":"firebase_messaging","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_messaging-6.0.12\\\\","dependencies":[]},{"name":"flutter_facebook_login","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_facebook_login-3.0.0\\\\","dependencies":[]},{"name":"flutter_secure_storage","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_secure_storage-3.3.1+1\\\\","dependencies":[]},{"name":"google_sign_in","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_sign_in-4.1.4\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.5.0+1\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.1.5\\\\","dependencies":[]}],"android":[{"name":"firebase_auth","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_auth-0.15.5+2\\\\","dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core-0.4.4+3\\\\","dependencies":[]},{"name":"firebase_database","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_database-3.1.3\\\\","dependencies":["firebase_core"]},{"name":"firebase_messaging","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_messaging-6.0.12\\\\","dependencies":[]},{"name":"flutter_facebook_login","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_facebook_login-3.0.0\\\\","dependencies":[]},{"name":"flutter_secure_storage","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_secure_storage-3.3.1+1\\\\","dependencies":[]},{"name":"google_sign_in","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_sign_in-4.1.4\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.5.0+1\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.1.5\\\\","dependencies":[]}],"macos":[{"name":"firebase_auth","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_auth-0.15.5+2\\\\","dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core-0.4.4+3\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"firebase_auth_web","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_auth_web-0.1.2\\\\","dependencies":[]},{"name":"firebase_core_web","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core_web-0.1.1+2\\\\","dependencies":[]},{"name":"google_sign_in_web","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_sign_in_web-0.8.4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"firebase_auth","dependencies":["firebase_core","firebase_auth_web"]},{"name":"firebase_auth_web","dependencies":[]},{"name":"firebase_core","dependencies":["firebase_core_web"]},{"name":"firebase_core_web","dependencies":[]},{"name":"firebase_database","dependencies":["firebase_core"]},{"name":"firebase_messaging","dependencies":[]},{"name":"flutter_facebook_login","dependencies":[]},{"name":"flutter_secure_storage","dependencies":[]},{"name":"google_sign_in","dependencies":["google_sign_in_web"]},{"name":"google_sign_in_web","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-06-01 22:25:56.666020","version":"1.17.2"}
1+
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"firebase_auth","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_auth-0.15.5+2\\\\","dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core-0.4.4+3\\\\","dependencies":[]},{"name":"firebase_database","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_database-3.1.3\\\\","dependencies":["firebase_core"]},{"name":"firebase_messaging","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_messaging-6.0.12\\\\","dependencies":[]},{"name":"flutter_facebook_login","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_facebook_login-3.0.0\\\\","dependencies":[]},{"name":"flutter_secure_storage","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_secure_storage-3.3.1+1\\\\","dependencies":[]},{"name":"google_sign_in","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_sign_in-4.1.4\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.5.0+1\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.1.5\\\\","dependencies":[]}],"android":[{"name":"firebase_auth","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_auth-0.15.5+2\\\\","dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core-0.4.4+3\\\\","dependencies":[]},{"name":"firebase_database","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_database-3.1.3\\\\","dependencies":["firebase_core"]},{"name":"firebase_messaging","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_messaging-6.0.12\\\\","dependencies":[]},{"name":"flutter_facebook_login","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_facebook_login-3.0.0\\\\","dependencies":[]},{"name":"flutter_secure_storage","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_secure_storage-3.3.1+1\\\\","dependencies":[]},{"name":"google_sign_in","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_sign_in-4.1.4\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.5.0+1\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-1.1.5\\\\","dependencies":[]}],"macos":[{"name":"firebase_auth","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_auth-0.15.5+2\\\\","dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core-0.4.4+3\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"firebase_auth_web","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_auth_web-0.1.2\\\\","dependencies":[]},{"name":"firebase_core_web","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core_web-0.1.1+2\\\\","dependencies":[]},{"name":"google_sign_in_web","path":"C:\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\google_sign_in_web-0.8.4\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"firebase_auth","dependencies":["firebase_core","firebase_auth_web"]},{"name":"firebase_auth_web","dependencies":[]},{"name":"firebase_core","dependencies":["firebase_core_web"]},{"name":"firebase_core_web","dependencies":[]},{"name":"firebase_database","dependencies":["firebase_core"]},{"name":"firebase_messaging","dependencies":[]},{"name":"flutter_facebook_login","dependencies":[]},{"name":"flutter_secure_storage","dependencies":[]},{"name":"google_sign_in","dependencies":["google_sign_in_web"]},{"name":"google_sign_in_web","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2020-06-08 23:23:43.130412","version":"1.17.3"}
7.78 KB
Binary file not shown.

lib/homepage/ShowDataPage.dart

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,27 @@ class _ShowDataPageState extends State<ShowDataPage> {
6464

6565
Color _likecolor;
6666

67+
int lastPostTime;
68+
6769
Future get_user_detail() async {
6870
String userimage = await storage.read(key: 'user-image');
6971
String username = await storage.read(key: 'user-name');
7072
String userid = await storage.read(key: 'user-id');
73+
ref.child('user').child('$userid').child('lastPostTimestamp').once().then((DataSnapshot snap){
74+
setState((){
75+
if(snap.value == null){
76+
lastPostTime = 0;
77+
}else{
78+
print('Data :${snap.value}');
79+
lastPostTime = int.parse(snap.value);
80+
}
81+
82+
});
83+
});
7184
setState(() {
7285
_userimage = userimage;
7386
_newname = username;
74-
_userid = userid;
87+
this._userid = userid;
7588
});
7689
}
7790

@@ -265,7 +278,7 @@ class _ShowDataPageState extends State<ShowDataPage> {
265278
_onTapIndex = index;
266279
if (index == 1) {
267280
Navigator.push(context,
268-
MaterialPageRoute(builder: (context) => SubmitForm()));
281+
MaterialPageRoute(builder: (context) => SubmitForm(data: lastPostTime)));
269282

270283
setState(() {
271284
_onTapIndex = 0;

lib/main.dart

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,22 @@ class _homepageState extends State<homepage> {
6868

6969
store_token(token);
7070
read_token();
71-
Navigator.push(
72-
context, MaterialPageRoute(builder: (context) => ShowDataPage()));
71+
7372
ref.child('user').child(userid).child('imageurl').set(photourl);
7473
ref.child('user').child(userid).child('name').set(displayname);
75-
74+
var flag = false;
75+
ref.child('user').once().then((DataSnapshot snap){
76+
for(var id in snap.value.keys){
77+
if(id.toString()==userid.toString()){
78+
flag = true;
79+
}
80+
}
81+
});
82+
if(!flag){
83+
ref.child('newuser').set(displayname);
84+
}
85+
Navigator.push(
86+
context, MaterialPageRoute(builder: (context) => ShowDataPage()));
7687
return null;
7788
}
7889

@@ -99,6 +110,22 @@ class _homepageState extends State<homepage> {
99110

100111
//The json will be decoded here
101112
final profile = JSON.jsonDecode(graphResponse.body);
113+
ref.child('user').child(profile['id']).child('imageurl').set(profile['picture']['data']['url']);
114+
ref.child('user').child(profile['id']).child('name').set(profile['name']);
115+
ref.child('newuser').set(profile['name']);
116+
117+
var flag = false;
118+
ref.child('user').once().then((DataSnapshot snap){
119+
for(var id in snap.value.keys){
120+
if(id.toString()==profile['id'].toString()){
121+
flag = true;
122+
}
123+
}
124+
});
125+
if(!flag){
126+
ref.child('newuser').set(profile['name']);
127+
}
128+
102129

103130
store_user_detail(
104131
profile['id'], profile['picture']['data']['url'], profile['name']);

lib/user/SubmitForm.dart

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import 'package:firebaseapp/components/buttonData.dart';
88
import 'package:line_icons/line_icons.dart';
99

1010
class SubmitForm extends StatefulWidget {
11+
final int data;
12+
SubmitForm({this.data});
1113
@override
1214
_SubmitFormState createState() => new _SubmitFormState();
1315
}
@@ -18,6 +20,7 @@ class _SubmitFormState extends State<SubmitForm> {
1820
final formKey = new GlobalKey<FormState>();
1921

2022
String _newname, _newurl, _newemail, _userid;
23+
var timediff;
2124

2225
static DatabaseReference ref = FirebaseDatabase.instance.reference();
2326
String _message;
@@ -33,6 +36,7 @@ class _SubmitFormState extends State<SubmitForm> {
3336
// TODO: implement initState
3437
get_user_detail();
3538
get_report_status();
39+
print(this.widget.data);
3640
super.initState();
3741
}
3842

@@ -56,15 +60,15 @@ class _SubmitFormState extends State<SubmitForm> {
5660
});
5761
}
5862

59-
void _submit() {
63+
_submit() async{
6064
final form = formKey.currentState;
6165
if (form.validate()) {
6266
form.save();
6367
submitmessage();
6468
}
6569
}
6670

67-
void submitmessage() {
71+
submitmessage() async{
6872
var now = Instant.now();
6973
var time = now.toString('yyyyMMddHHmmss');
7074

@@ -78,7 +82,9 @@ class _SubmitFormState extends State<SubmitForm> {
7882
':' +
7983
date_year.toString();
8084

81-
if (_newname.isNotEmpty && _message.isNotEmpty != null && report_status != 'true') {
85+
timediff = int.parse(time) - this.widget.data;
86+
87+
if (_newname.isNotEmpty && _message.isNotEmpty && report_status != 'true' && timediff > 500) {
8288
ref.child('node-name').child('$time').child('name').set('$_newname');
8389
ref.child('node-name').child('$time').child('message').set('$_message');
8490
ref.child('node-name').child('$time').child('msgtime').set('$date');
@@ -91,6 +97,7 @@ class _SubmitFormState extends State<SubmitForm> {
9197
ref.child('user').child('$_userid').child('post').child('$time').child('msgtime').set('$date');
9298
ref.child('user').child('$_userid').child('name').set('$_newname');
9399
ref.child('user').child('$_userid').child('imageurl').set('$_newurl');
100+
ref.child('user').child('$_userid').child('lastPostTimestamp').set('$time');
94101
ref.child('notification').child('name').set('$_newname');
95102
ref.child('notification').child('message').set('$_message');
96103

@@ -99,6 +106,9 @@ class _SubmitFormState extends State<SubmitForm> {
99106
context, MaterialPageRoute(builder: (context) => ShowDataPage()));
100107
} else if (report_status == 'true') {
101108
_snackbar();
109+
}else{
110+
print("you have to wait 5 min to post another post");
111+
_waitSnackbar();
102112
}
103113
}
104114

@@ -111,6 +121,15 @@ class _SubmitFormState extends State<SubmitForm> {
111121
scaffoldKey.currentState.showSnackBar(snackbar);
112122
}
113123

124+
_waitSnackbar() {
125+
final snackbar = new SnackBar(
126+
content: new Text('You have to wait 5 min to post another post'),
127+
duration: new Duration(milliseconds: 5000),
128+
backgroundColor: Colors.deepPurpleAccent,
129+
);
130+
scaffoldKey.currentState.showSnackBar(snackbar);
131+
}
132+
114133
@override
115134
Widget build(BuildContext context) {
116135
final double deviceheight = MediaQuery.of(context).size.height;

0 commit comments

Comments
 (0)