From 49fab3f63b20f11cbb6970beffbdae8299e617ed Mon Sep 17 00:00:00 2001 From: Aditi Goyal <56929057+gaditi123@users.noreply.github.com> Date: Thu, 1 Oct 2020 00:30:05 +0530 Subject: [PATCH] formatted code and ui improvements --- .idea/.gitignore | 3 + .idea/Flutter-Chat-App.iml | 14 ++ .idea/codeStyles/Project.xml | 116 +++++++++ .idea/libraries/Dart_Packages.xml | 324 ++++++++++++++++++++++++++ .idea/libraries/Dart_SDK.xml | 29 +++ .idea/modules.xml | 8 + .idea/vcs.xml | 6 + chat_app/lib/screens/chat_screen.dart | 19 +- chat_app/lib/widgets/auth_form.dart | 19 +- chat_app/lib/widgets/md.dart | 65 +++--- chat_app/lib/widgets/messages.dart | 47 ++-- chat_app/lib/widgets/new_message.dart | 25 +- 12 files changed, 600 insertions(+), 75 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/Flutter-Chat-App.iml create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/libraries/Dart_Packages.xml create mode 100644 .idea/libraries/Dart_SDK.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..0e40fe8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ + +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/Flutter-Chat-App.iml b/.idea/Flutter-Chat-App.iml new file mode 100644 index 0000000..343f2c6 --- /dev/null +++ b/.idea/Flutter-Chat-App.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml new file mode 100644 index 0000000..4bff185 --- /dev/null +++ b/.idea/libraries/Dart_Packages.xml @@ -0,0 +1,324 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml new file mode 100644 index 0000000..e766a65 --- /dev/null +++ b/.idea/libraries/Dart_SDK.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..35d05c3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/chat_app/lib/screens/chat_screen.dart b/chat_app/lib/screens/chat_screen.dart index be72264..1f47b78 100644 --- a/chat_app/lib/screens/chat_screen.dart +++ b/chat_app/lib/screens/chat_screen.dart @@ -2,7 +2,8 @@ import 'package:flutter/material.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_auth/firebase_auth.dart'; import '../widgets/messages.dart'; -import'package:chat_app/widgets/new_message.dart'; +import 'package:chat_app/widgets/new_message.dart'; + class ChatScreen extends StatelessWidget { @override Widget build(BuildContext context) { @@ -13,15 +14,20 @@ class ChatScreen extends StatelessWidget { DropdownButton( icon: Icon( Icons.more_vert, - color: Theme.of(context).primaryIconTheme.color, + color: Theme + .of(context) + .primaryIconTheme + .color, ), items: [ DropdownMenuItem( child: Container( child: Row( children: [ - Icon(Icons.exit_to_app), - SizedBox(width: 8), + Icon( + Icons.exit_to_app, + ), + SizedBox(width: 10), Text('Logout'), ], ), @@ -39,9 +45,10 @@ class ChatScreen extends StatelessWidget { ), body: Container( child: Column( - children:[ + children: [ Expanded( - child: Messages(),), + child: Messages(), + ), NewMessage(), ], ), diff --git a/chat_app/lib/widgets/auth_form.dart b/chat_app/lib/widgets/auth_form.dart index 580d599..6f43567 100644 --- a/chat_app/lib/widgets/auth_form.dart +++ b/chat_app/lib/widgets/auth_form.dart @@ -42,6 +42,8 @@ class _AuthFormState extends State { return Center( child: Card( margin: EdgeInsets.all(20), + elevation: 10, + shadowColor: Colors.purple, child: SingleChildScrollView( child: Padding( padding: EdgeInsets.all(16), @@ -88,7 +90,9 @@ class _AuthFormState extends State { } return null; }, - decoration: InputDecoration(labelText: 'Password'), + decoration: InputDecoration( + labelText: 'Password', + ), obscureText: true, onSaved: (value) { _userPassword = value; @@ -98,15 +102,20 @@ class _AuthFormState extends State { if (widget.isLoading) CircularProgressIndicator(), if (!widget.isLoading) RaisedButton( - child: Text(_isLogin ? 'Login' : 'Signup'), + elevation: 3, + child: Text( + _isLogin ? 'Login' : 'Signup', + ), onPressed: _trySubmit, ), if (!widget.isLoading) FlatButton( textColor: Theme.of(context).primaryColor, - child: Text(_isLogin - ? 'Create new account' - : 'I already have an account'), + child: Text( + _isLogin + ? 'Create new account' + : 'I already have an account', + ), onPressed: () { setState(() { _isLogin = !_isLogin; diff --git a/chat_app/lib/widgets/md.dart b/chat_app/lib/widgets/md.dart index 8c747e9..b6430f8 100644 --- a/chat_app/lib/widgets/md.dart +++ b/chat_app/lib/widgets/md.dart @@ -13,45 +13,46 @@ class MD extends StatelessWidget { @override Widget build(BuildContext context) { return Row( - mainAxisAlignment: - isMe ? MainAxisAlignment.end : MainAxisAlignment.start, - children: [ - Container( - decoration: BoxDecoration( - color: isMe ? Colors.blue : Theme.of(context).accentColor, - borderRadius: BorderRadius.only( - topRight: Radius.circular(8), - bottomRight: isMe ? Radius.circular(0) : Radius.circular(12), - topLeft: Radius.circular(8), - bottomLeft: !isMe ? Radius.circular(0) : Radius.circular(8), - ), + mainAxisAlignment: isMe ? MainAxisAlignment.end : MainAxisAlignment.start, + children: [ + Container( + decoration: BoxDecoration( + color: isMe ? Colors.blue : Theme.of(context).accentColor, + borderRadius: BorderRadius.only( + topRight: Radius.circular(8), + bottomRight: isMe ? Radius.circular(0) : Radius.circular(12), + topLeft: Radius.circular(8), + bottomLeft: !isMe ? Radius.circular(0) : Radius.circular(8), ), - width: 180, - padding: EdgeInsets.all(12), - margin: EdgeInsets.all(3), - child: Column( - crossAxisAlignment: isMe?CrossAxisAlignment.end:CrossAxisAlignment.start, - children: [ - - Text( - username, - style: TextStyle( - color: isMe - ? Colors.black - : Theme.of(context).accentTextTheme.title.color, - fontWeight: FontWeight.bold, - ), - ), + ), + width: 180, + padding: EdgeInsets.all(12), + margin: EdgeInsets.all(3), + child: Column( + crossAxisAlignment: + isMe ? CrossAxisAlignment.end : CrossAxisAlignment.start, + children: [ + Text( + username, + style: TextStyle( + color: isMe + ? Colors.black + : Theme.of(context).accentTextTheme.headline6.color, + fontWeight: FontWeight.bold, + ), + ), Text( message, style: TextStyle( color: isMe ? Colors.black - : Theme.of(context).accentTextTheme.title.color), - textAlign: isMe?TextAlign.end:TextAlign.start, + : Theme.of(context).accentTextTheme.headline6.color), + textAlign: isMe ? TextAlign.end : TextAlign.start, ), - ]), + ], ), - ]); + ), + ], + ); } } diff --git a/chat_app/lib/widgets/messages.dart b/chat_app/lib/widgets/messages.dart index b301a29..86be5f7 100644 --- a/chat_app/lib/widgets/messages.dart +++ b/chat_app/lib/widgets/messages.dart @@ -9,30 +9,33 @@ class Messages extends StatelessWidget { Widget build(BuildContext context) { return FutureBuilder( future: FirebaseAuth.instance.currentUser(), - builder:(ctx,futureSnapshot) { - if(futureSnapshot.connectionState==ConnectionState.waiting){ - return Center( - child:CircularProgressIndicator() - ); + builder: (ctx, futureSnapshot) { + if (futureSnapshot.connectionState == ConnectionState.waiting) { + return Center(child: CircularProgressIndicator()); } return StreamBuilder( - stream: Firestore.instance.collection('chat').orderBy( - 'ts', descending: true).snapshots(), - builder: (ctx, chatSnapshot) { - if (chatSnapshot.connectionState == ConnectionState.waiting) { - return Center( - child: CircularProgressIndicator(), - ); - } - final chatDocs = chatSnapshot.data.documents; - return ListView.builder( - reverse: true, - itemCount: chatDocs.length, - itemBuilder: (ctx, index) => - MD(chatDocs[index]['text'], - chatDocs[index]['username'],chatDocs[index]['sender']==futureSnapshot.data.uid, - key: ValueKey(chatDocs[index].documentID),), - );}); + stream: Firestore.instance + .collection('chat') + .orderBy('ts', descending: true) + .snapshots(), + builder: (ctx, chatSnapshot) { + if (chatSnapshot.connectionState == ConnectionState.waiting) { + return Center( + child: CircularProgressIndicator(), + ); + } + final chatDocs = chatSnapshot.data.documents; + return ListView.builder( + reverse: true, + itemCount: chatDocs.length, + itemBuilder: (ctx, index) => MD( + chatDocs[index]['text'], + chatDocs[index]['username'], + chatDocs[index]['sender'] == futureSnapshot.data.uid, + key: ValueKey(chatDocs[index].documentID), + ), + ); + }); }, ); } diff --git a/chat_app/lib/widgets/new_message.dart b/chat_app/lib/widgets/new_message.dart index 54f6749..8f177cb 100644 --- a/chat_app/lib/widgets/new_message.dart +++ b/chat_app/lib/widgets/new_message.dart @@ -1,26 +1,30 @@ import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:flutter/material.dart'; import 'package:firebase_auth/firebase_auth.dart'; + class NewMessage extends StatefulWidget { @override _NewMessageState createState() => _NewMessageState(); } class _NewMessageState extends State { - var enteredMessage=''; - var _controller=new TextEditingController(); - void _sendMessage()async{ + var enteredMessage = ''; + var _controller = new TextEditingController(); + + void _sendMessage() async { FocusScope.of(context).unfocus(); - final user=await FirebaseAuth.instance.currentUser(); - final userData=await Firestore.instance.collection('users').document(user.uid).get(); + final user = await FirebaseAuth.instance.currentUser(); + final userData = + await Firestore.instance.collection('users').document(user.uid).get(); Firestore.instance.collection('chat').add({ - 'text':enteredMessage, - 'ts':Timestamp.now(), - 'sender':user.uid, - 'username':userData['username'] + 'text': enteredMessage, + 'ts': Timestamp.now(), + 'sender': user.uid, + 'username': userData['username'] }); _controller.clear(); } + @override Widget build(BuildContext context) { return Container( @@ -34,6 +38,7 @@ class _NewMessageState extends State { decoration: InputDecoration(labelText: 'Write a message!'), onChanged: (value) { enteredMessage=value; + print('message added'); }, ), ), @@ -42,7 +47,7 @@ class _NewMessageState extends State { onPressed: enteredMessage.trim().isEmpty?null: _sendMessage, color: Theme.of(context).accentColor, - ) + ), ], ), );