Skip to content

Commit

Permalink
creating new chats
Browse files Browse the repository at this point in the history
  • Loading branch information
deargosep committed Jan 24, 2022
1 parent 5226460 commit d753227
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutgram/screens/auth.dart';
import 'package:flutgram/screens/chat.dart';
import 'package:flutgram/screens/new_chat.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:firebase_core/firebase_core.dart';
Expand All @@ -17,6 +18,7 @@ void main() async {
GetPage(name: '/', page: () => AuthScreen()),
GetPage(name: '/chats', page: () => Home()),
GetPage(name: '/chat', page: () => ChatScreen()),
GetPage(name: '/new_chat', page: () => NewChatScreen()),
],
));
}
Expand All @@ -30,17 +32,23 @@ class Home extends StatelessWidget {
firebaseAuth.authStateChanges().listen((User? user) {
if (user == null) {
Get.offAllNamed('/');
} else {}
}
});
void logout() {
firebaseAuth.signOut();
}

void newChat() {
Get.toNamed('/new_chat');
}

return Scaffold(
appBar: AppBar(
title: Text('Chats'),
actions: [IconButton(onPressed: logout, icon: Icon(Icons.logout))],
),
floatingActionButton:
FloatingActionButton(onPressed: newChat, child: Icon(Icons.add)),
body: Center(child: Chats()),
);
}
Expand Down
51 changes: 51 additions & 0 deletions lib/screens/new_chat.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:get/get.dart';

class NewChatScreen extends HookWidget {
const NewChatScreen({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
final name = useTextEditingController();
final description = useTextEditingController();
void submit() {
final data = {
"name": name.value.text,
"description": description.value.text
};
FirebaseFirestore.instance.collection('Chats').add(data);
Get.back();
}

return Scaffold(
appBar: AppBar(
title: Text('New Chat'),
),
body: Container(
padding: EdgeInsets.all(20),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextFormField(
controller: name,
onFieldSubmitted: (text) {
submit();
},
decoration: InputDecoration(label: Text('Name')),
),
TextFormField(
controller: description,
onFieldSubmitted: (text) {
submit();
},
decoration: InputDecoration(label: Text('Description')),
),
TextButton(onPressed: submit, child: Text('Submit'))
],
),
),
);
}
}

0 comments on commit d753227

Please sign in to comment.