diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index a56e35f..7d63c32 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"cloud_firestore","dependencies":["firebase_core"]},{"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":[]}]} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"cloud_firestore","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\cloud_firestore-0.14.4\\\\","dependencies":["firebase_core"]},{"name":"firebase_auth","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_auth-0.18.4+1\\\\","dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core-0.5.3\\\\","dependencies":[]}],"android":[{"name":"cloud_firestore","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\cloud_firestore-0.14.4\\\\","dependencies":["firebase_core"]},{"name":"firebase_auth","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_auth-0.18.4+1\\\\","dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core-0.5.3\\\\","dependencies":[]}],"macos":[{"name":"cloud_firestore","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\cloud_firestore-0.14.4\\\\","dependencies":["firebase_core"]},{"name":"firebase_auth","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_auth-0.18.4+1\\\\","dependencies":["firebase_core"]},{"name":"firebase_core","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core-0.5.3\\\\","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"cloud_firestore_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\cloud_firestore_web-0.2.1+2\\\\","dependencies":["firebase_core_web"]},{"name":"firebase_auth_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_auth_web-0.3.2+3\\\\","dependencies":["firebase_core_web"]},{"name":"firebase_core_web","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\firebase_core_web-0.2.1+1\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"cloud_firestore","dependencies":["firebase_core","cloud_firestore_web"]},{"name":"cloud_firestore_web","dependencies":["firebase_core","firebase_core_web"]},{"name":"firebase_auth","dependencies":["firebase_core","firebase_auth_web"]},{"name":"firebase_auth_web","dependencies":["firebase_core","firebase_core_web"]},{"name":"firebase_core","dependencies":["firebase_core_web"]},{"name":"firebase_core_web","dependencies":[]}],"date_created":"2020-12-31 23:16:03.941206","version":"1.22.5"} \ No newline at end of file diff --git a/README.md b/README.md index c1192c6..76c93ca 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,11 @@ ![App Brewery Banner](https://github.com/londonappbrewery/Images/blob/master/AppBreweryBanner.png) - # Flash Chat ⚡️ ## Our Goal The objective of this tutorial is to learn how to incorporate Firebase into our Flutter apps. We'll be using Firebase Cloud Firestore as well as the Firebase authentication package to equip our app with a cloud based NoSQL database and secure authentication methods. - ## What you will create We’re going to build a modern messaging app where users can sign up and log in to chat. @@ -25,8 +23,6 @@ We’re going to build a modern messaging app where users can sign up and log in - Learn to use ListViews to build scrolling views. - How to use Firebase Cloud Firestore to store and retrieve data on the fly. - - ->This is a companion project to The App Brewery's Complete Flutter Development Bootcamp, check out the full course at [www.appbrewery.co](https://www.appbrewery.co/) +> This is a companion project to The App Brewery's Complete Flutter Development Bootcamp, check out the full course at [www.appbrewery.co](https://www.appbrewery.co/) ![End Banner](https://github.com/londonappbrewery/Images/blob/master/readme-end-banner.png) diff --git a/android/app/src/main/ic_launcher-web.png b/android/app/src/main/ic_launcher-web.png index 9ca2dce..94cc4e8 100644 Binary files a/android/app/src/main/ic_launcher-web.png and b/android/app/src/main/ic_launcher-web.png differ diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png index 7ce6201..5a204a2 100644 Binary files a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png index d5753e4..aa3c2df 100644 Binary files a/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png and b/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png differ diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png index e0097f7..dae8ebe 100644 Binary files a/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png index 0cd6975..933b6c0 100644 Binary files a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png index 6a03f76..c2bf714 100644 Binary files a/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png and b/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png index c1d2220..4e8ae6f 100644 Binary files a/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png index 8356999..0920d80 100644 Binary files a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png index 3697775..77d0810 100644 Binary files a/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png index 551a334..2de6316 100644 Binary files a/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png index 56c1aa3..439080e 100644 Binary files a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png index bfb2e1d..724fd51 100644 Binary files a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png index f517716..5720c15 100644 Binary files a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png index 19ecdb6..bc46029 100644 Binary files a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png index cff5797..6c03ab8 100644 Binary files a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png index 887976a..165366b 100644 Binary files a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/android/build.gradle b/android/build.gradle index 9234dae..24ef52d 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -27,4 +27,4 @@ subprojects { task clean(type: Delete) { delete rootProject.buildDir -} +} \ No newline at end of file diff --git a/android/gradle.properties b/android/gradle.properties index b6e61b6..4f4a628 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,4 +1,6 @@ android.enableJetifier=true android.useAndroidX=true org.gradle.jvmargs=-Xmx1536M +android.useAndroidX=true +android.enableJetifier=true android.enableR8=true diff --git a/ios/Flutter/flutter_export_environment.sh b/ios/Flutter/flutter_export_environment.sh new file mode 100644 index 0000000..b35bebf --- /dev/null +++ b/ios/Flutter/flutter_export_environment.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# This is a generated file; do not edit or check into version control. +export "FLUTTER_ROOT=C:\src\flutter" +export "FLUTTER_APPLICATION_PATH=C:\Users\harshit\AndroidStudioProjects\flash-chat-flutter" +export "FLUTTER_TARGET=lib\main.dart" +export "FLUTTER_BUILD_DIR=build" +export "SYMROOT=${SOURCE_ROOT}/../build\ios" +export "OTHER_LDFLAGS=$(inherited) -framework Flutter" +export "FLUTTER_FRAMEWORK_DIR=C:\src\flutter\bin\cache\artifacts\engine\ios" +export "FLUTTER_BUILD_NAME=1.0.0" +export "FLUTTER_BUILD_NUMBER=1" +export "DART_OBFUSCATION=false" +export "TRACK_WIDGET_CREATION=false" +export "TREE_SHAKE_ICONS=false" +export "PACKAGE_CONFIG=.packages" diff --git a/lib/components/rounded_button.dart b/lib/components/rounded_button.dart index 4ace8df..308c7b2 100644 --- a/lib/components/rounded_button.dart +++ b/lib/components/rounded_button.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; class RoundedButton extends StatelessWidget { - RoundedButton({this.title, this.colour, @required this.onPressed}); - final Color colour; - final String title; - final Function onPressed; + final String textToShow; + final Function onPress; + + const RoundedButton({@required this.onPress, this.textToShow, this.colour}); @override Widget build(BuildContext context) { @@ -13,14 +13,14 @@ class RoundedButton extends StatelessWidget { padding: EdgeInsets.symmetric(vertical: 16.0), child: Material( elevation: 5.0, - color: colour, + color: colour, //Colors.lightBlueAccent, borderRadius: BorderRadius.circular(30.0), child: MaterialButton( - onPressed: onPressed, + onPressed: onPress, minWidth: 200.0, height: 42.0, child: Text( - title, + textToShow, //'Log In', style: TextStyle( color: Colors.white, ), diff --git a/lib/constants.dart b/lib/constants.dart index 5bfb6e5..4ce21f2 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -17,9 +17,8 @@ const kMessageContainerDecoration = BoxDecoration( top: BorderSide(color: Colors.lightBlueAccent, width: 2.0), ), ); - -const kTextFieldDecoration = InputDecoration( - hintText: 'Enter a value', +const kInputTextDecoration = InputDecoration( + hintText: 'Set hint text', contentPadding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0), border: OutlineInputBorder( borderRadius: BorderRadius.all(Radius.circular(32.0)), diff --git a/lib/main.dart b/lib/main.dart index a6a6b5f..c24b603 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,8 +3,16 @@ import 'package:flash_chat/screens/welcome_screen.dart'; import 'package:flash_chat/screens/login_screen.dart'; import 'package:flash_chat/screens/registration_screen.dart'; import 'package:flash_chat/screens/chat_screen.dart'; +import 'package:firebase_core/firebase_core.dart'; +import 'screens/chat_screen.dart'; +import 'screens/login_screen.dart'; +import 'screens/welcome_screen.dart'; -void main() => runApp(FlashChat()); +void main() async { + WidgetsFlutterBinding.ensureInitialized(); + await Firebase.initializeApp(); + runApp(FlashChat()); +} class FlashChat extends StatelessWidget { @override diff --git a/lib/screens/chat_screen.dart b/lib/screens/chat_screen.dart index 1c1530c..8015b6c 100644 --- a/lib/screens/chat_screen.dart +++ b/lib/screens/chat_screen.dart @@ -1,10 +1,11 @@ +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flash_chat/constants.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; -final _firestore = Firestore.instance; -FirebaseUser loggedInUser; +final _firestore = FirebaseFirestore.instance; +User loggedInUser; class ChatScreen extends StatefulWidget { static const String id = 'chat_screen'; @@ -13,29 +14,29 @@ class ChatScreen extends StatefulWidget { } class _ChatScreenState extends State { - final messageTextController = TextEditingController(); + String messages; final _auth = FirebaseAuth.instance; - String messageText; - - @override - void initState() { - super.initState(); - - getCurrentUser(); - } - void getCurrentUser() async { try { - final user = await _auth.currentUser(); + final user = await _auth.currentUser; if (user != null) { loggedInUser = user; + print(loggedInUser.email); } } catch (e) { print(e); } } + final messageTextController = TextEditingController(); + + @override + void initState() { + super.initState(); + getCurrentUser(); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -57,7 +58,7 @@ class _ChatScreenState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - MessagesStream(), + MessageStream(), Container( decoration: kMessageContainerDecoration, child: Row( @@ -67,16 +68,18 @@ class _ChatScreenState extends State { child: TextField( controller: messageTextController, onChanged: (value) { - messageText = value; + //Do something with the user input. + messages = value; }, decoration: kMessageTextFieldDecoration, ), ), FlatButton( onPressed: () { + //Implement send functionality. messageTextController.clear(); _firestore.collection('messages').add({ - 'text': messageText, + 'text': messages, 'sender': loggedInUser.email, }); }, @@ -95,39 +98,39 @@ class _ChatScreenState extends State { } } -class MessagesStream extends StatelessWidget { +class MessageStream extends StatelessWidget { @override Widget build(BuildContext context) { - return StreamBuilder( + return StreamBuilder( stream: _firestore.collection('messages').snapshots(), builder: (context, snapshot) { + List messageBubbles = []; if (!snapshot.hasData) { return Center( child: CircularProgressIndicator( - backgroundColor: Colors.lightBlueAccent, + backgroundColor: Colors.lightBlue, ), ); } - final messages = snapshot.data.documents.reversed; - List messageBubbles = []; - for (var message in messages) { - final messageText = message.data['text']; - final messageSender = message.data['sender']; - final currentUser = loggedInUser.email; + final messages = snapshot.data.docs.reversed; + for (var message in messages) { + final messageData = message.data(); + final messageText = messageData['text']; + final messageSender = messageData['sender']; final messageBubble = MessageBubble( - sender: messageSender, text: messageText, - isMe: currentUser == messageSender, + sender: messageSender, + isMe: messageSender == loggedInUser.email, ); - messageBubbles.add(messageBubble); } + return Expanded( child: ListView( reverse: true, - padding: EdgeInsets.symmetric(horizontal: 10.0, vertical: 20.0), + padding: EdgeInsets.symmetric(horizontal: 10, vertical: 20), children: messageBubbles, ), ); @@ -137,48 +140,36 @@ class MessagesStream extends StatelessWidget { } class MessageBubble extends StatelessWidget { - MessageBubble({this.sender, this.text, this.isMe}); - - final String sender; final String text; + final String sender; final bool isMe; - + MessageBubble({this.text, this.sender, this.isMe}); @override Widget build(BuildContext context) { return Padding( - padding: EdgeInsets.all(10.0), + padding: EdgeInsets.all(10), child: Column( crossAxisAlignment: isMe ? CrossAxisAlignment.end : CrossAxisAlignment.start, - children: [ + children: [ Text( sender, - style: TextStyle( - fontSize: 12.0, - color: Colors.black54, - ), + style: TextStyle(fontSize: 12, color: Colors.black54), ), Material( - borderRadius: isMe - ? BorderRadius.only( - topLeft: Radius.circular(30.0), - bottomLeft: Radius.circular(30.0), - bottomRight: Radius.circular(30.0)) - : BorderRadius.only( - bottomLeft: Radius.circular(30.0), - bottomRight: Radius.circular(30.0), - topRight: Radius.circular(30.0), - ), - elevation: 5.0, - color: isMe ? Colors.lightBlueAccent : Colors.white, + borderRadius: BorderRadius.only( + topLeft: isMe ? Radius.circular(30) : Radius.circular(0), + bottomLeft: Radius.circular(30), + bottomRight: Radius.circular(30), + topRight: isMe ? Radius.circular(0) : Radius.circular(30), + ), + color: isMe ? Colors.blueAccent : Colors.green, child: Padding( - padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0), + padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10), child: Text( - text, + '$text', style: TextStyle( - color: isMe ? Colors.white : Colors.black54, - fontSize: 15.0, - ), + fontSize: 15, color: isMe ? Colors.white : Colors.black), ), ), ), diff --git a/lib/screens/login_screen.dart b/lib/screens/login_screen.dart index 2050a3d..d6ac298 100644 --- a/lib/screens/login_screen.dart +++ b/lib/screens/login_screen.dart @@ -2,8 +2,8 @@ import 'package:flutter/material.dart'; import 'package:flash_chat/components/rounded_button.dart'; import 'package:flash_chat/constants.dart'; import 'package:firebase_auth/firebase_auth.dart'; -import 'chat_screen.dart'; import 'package:modal_progress_hud/modal_progress_hud.dart'; +import 'chat_screen.dart'; class LoginScreen extends StatefulWidget { static const String id = 'login_screen'; @@ -12,82 +12,83 @@ class LoginScreen extends StatefulWidget { } class _LoginScreenState extends State { - bool showSpinner = false; final _auth = FirebaseAuth.instance; + bool showModalProgress = false; String email; String password; + void logInUser() async { + setState(() { + showModalProgress = true; + }); + try { + final user = await _auth.signInWithEmailAndPassword( + email: email, password: password); + if (user != null) { + await Navigator.pushNamed(context, ChatScreen.id); + } + showModalProgress = false; + } catch (e) { + print(e); + } + } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, body: ModalProgressHUD( - inAsyncCall: showSpinner, - child: Padding( - padding: EdgeInsets.symmetric(horizontal: 24.0), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Flexible( - child: Hero( - tag: 'logo', - child: Container( - height: 200.0, - child: Image.asset('images/logo.png'), + inAsyncCall: showModalProgress, + child: SafeArea( + child: Padding( + padding: EdgeInsets.symmetric(horizontal: 24.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Flexible( + child: Hero( + tag: 'logo', + child: Container( + height: 200.0, + child: Image.asset('images/logo.png'), + ), ), ), - ), - SizedBox( - height: 48.0, - ), - TextField( - keyboardType: TextInputType.emailAddress, - textAlign: TextAlign.center, - onChanged: (value) { - email = value; - }, - decoration: - kTextFieldDecoration.copyWith(hintText: 'Enter your email'), - ), - SizedBox( - height: 8.0, - ), - TextField( - obscureText: true, - textAlign: TextAlign.center, - onChanged: (value) { - password = value; - }, - decoration: kTextFieldDecoration.copyWith( - hintText: 'Enter your password'), - ), - SizedBox( - height: 24.0, - ), - RoundedButton( - title: 'Log In', - colour: Colors.lightBlueAccent, - onPressed: () async { - setState(() { - showSpinner = true; - }); - try { - final user = await _auth.signInWithEmailAndPassword( - email: email, password: password); - if (user != null) { - Navigator.pushNamed(context, ChatScreen.id); - } - - setState(() { - showSpinner = false; - }); - } catch (e) { - print(e); - } - }, - ), - ], + SizedBox( + height: 48.0, + ), + TextField( + textAlign: TextAlign.center, + keyboardType: TextInputType.emailAddress, + onChanged: (value) { + email = value; + }, + decoration: kInputTextDecoration.copyWith( + hintText: 'Enter your Email')), + SizedBox( + height: 8.0, + ), + TextField( + textAlign: TextAlign.center, + obscureText: true, + onChanged: (value) { + password = value; + }, + decoration: kInputTextDecoration.copyWith( + hintText: 'Enter your password'), + ), + SizedBox( + height: 24.0, + ), + RoundedButton( + onPress: () { + logInUser(); + }, + colour: Colors.blueAccent, + textToShow: 'Log In', + ), + ], + ), ), ), ), diff --git a/lib/screens/registration_screen.dart b/lib/screens/registration_screen.dart index 1371ea7..bcf6286 100644 --- a/lib/screens/registration_screen.dart +++ b/lib/screens/registration_screen.dart @@ -13,81 +13,84 @@ class RegistrationScreen extends StatefulWidget { class _RegistrationScreenState extends State { final _auth = FirebaseAuth.instance; - bool showSpinner = false; + bool showModalprogress = false; String email; String password; - @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, body: ModalProgressHUD( - inAsyncCall: showSpinner, - child: Padding( - padding: EdgeInsets.symmetric(horizontal: 24.0), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Flexible( - child: Hero( - tag: 'logo', - child: Container( - height: 200.0, - child: Image.asset('images/logo.png'), + inAsyncCall: showModalprogress, + child: SafeArea( + child: Padding( + padding: EdgeInsets.symmetric(horizontal: 24.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Flexible( + child: Hero( + tag: 'logo', + child: Container( + height: 200.0, + child: Image.asset('images/logo.png'), + ), ), ), - ), - SizedBox( - height: 48.0, - ), - TextField( - keyboardType: TextInputType.emailAddress, - textAlign: TextAlign.center, - onChanged: (value) { - email = value; - }, - decoration: - kTextFieldDecoration.copyWith(hintText: 'Enter your email'), - ), - SizedBox( - height: 8.0, - ), - TextField( - obscureText: true, - textAlign: TextAlign.center, - onChanged: (value) { - password = value; - }, - decoration: kTextFieldDecoration.copyWith( - hintText: 'Enter your password'), - ), - SizedBox( - height: 24.0, - ), - RoundedButton( - title: 'Register', - colour: Colors.blueAccent, - onPressed: () async { - setState(() { - showSpinner = true; - }); - try { - final newUser = await _auth.createUserWithEmailAndPassword( - email: email, password: password); - if (newUser != null) { - Navigator.pushNamed(context, ChatScreen.id); - } - + SizedBox( + height: 48.0, + ), + TextField( + textAlign: TextAlign.center, + keyboardType: TextInputType.emailAddress, + onChanged: (value) { + email = value; + }, + decoration: kInputTextDecoration.copyWith( + hintText: 'Enter your email'), + ), + SizedBox( + height: 8.0, + ), + TextField( + textAlign: TextAlign.center, + obscureText: true, + onChanged: (value) { + password = value; + }, + decoration: kInputTextDecoration.copyWith( + hintText: 'Enter your password'), + ), + SizedBox( + height: 24.0, + ), + RoundedButton( + onPress: () async { setState(() { - showSpinner = false; + showModalprogress = true; }); - } catch (e) { - print(e); - } - }, - ), - ], + try { + final newUser = + await _auth.createUserWithEmailAndPassword( + email: email, password: password); + if (newUser != null) { + print('registeration success'); + print(newUser); + Navigator.pushNamed(context, ChatScreen.id); + } + setState(() { + showModalprogress = false; + }); + } catch (e) { + print(e); + } + }, + textToShow: 'Register', + colour: Colors.blueAccent, + ), + ], + ), ), ), ), diff --git a/lib/screens/welcome_screen.dart b/lib/screens/welcome_screen.dart index 1b0984a..f8f0e14 100644 --- a/lib/screens/welcome_screen.dart +++ b/lib/screens/welcome_screen.dart @@ -1,12 +1,11 @@ import 'package:flutter/material.dart'; -import 'login_screen.dart'; import 'registration_screen.dart'; +import 'login_screen.dart'; import 'package:animated_text_kit/animated_text_kit.dart'; import 'package:flash_chat/components/rounded_button.dart'; class WelcomeScreen extends StatefulWidget { static const String id = 'welcome_screen'; - @override _WelcomeScreenState createState() => _WelcomeScreenState(); } @@ -15,19 +14,23 @@ class _WelcomeScreenState extends State with SingleTickerProviderStateMixin { AnimationController controller; Animation animation; - @override void initState() { super.initState(); - - controller = - AnimationController(duration: Duration(seconds: 1), vsync: this); + controller = AnimationController( + duration: Duration(seconds: 1), + vsync: this, + ); animation = ColorTween(begin: Colors.blueGrey, end: Colors.white) .animate(controller); controller.forward(); - controller.addListener(() { - setState(() {}); - }); + controller.addListener( + () { + setState( + () {}, + ); + }, + ); } @override @@ -52,13 +55,15 @@ class _WelcomeScreenState extends State tag: 'logo', child: Container( child: Image.asset('images/logo.png'), - height: 60.0, + height: 60, ), ), TypewriterAnimatedTextKit( text: ['Flash Chat'], + speed: Duration(seconds: 1), textStyle: TextStyle( fontSize: 45.0, + color: Colors.black, fontWeight: FontWeight.w900, ), ), @@ -68,18 +73,18 @@ class _WelcomeScreenState extends State height: 48.0, ), RoundedButton( - title: 'Log In', - colour: Colors.lightBlueAccent, - onPressed: () { + onPress: () { Navigator.pushNamed(context, LoginScreen.id); }, + colour: Colors.lightBlueAccent, + textToShow: 'Log In', ), RoundedButton( - title: 'Register', - colour: Colors.blueAccent, - onPressed: () { + onPress: () { Navigator.pushNamed(context, RegistrationScreen.id); }, + textToShow: 'Register', + colour: Colors.blueAccent, ), ], ), diff --git a/pubspec.lock b/pubspec.lock index 092295e..fb00415 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,126 +7,126 @@ packages: name: animated_text_kit url: "https://pub.dartlang.org" source: hosted - version: "1.3.1" - archive: + version: "3.1.0" + async: dependency: transitive description: - name: archive + name: async url: "https://pub.dartlang.org" source: hosted - version: "2.0.11" - args: + version: "2.5.0-nullsafety.1" + boolean_selector: dependency: transitive description: - name: args + name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.5.2" - async: + version: "2.1.0-nullsafety.1" + characters: dependency: transitive description: - name: async + name: characters url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" - boolean_selector: + version: "1.1.0-nullsafety.3" + charcode: dependency: transitive description: - name: boolean_selector + name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" - charcode: + version: "1.2.0-nullsafety.1" + clock: dependency: transitive description: - name: charcode + name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.1.0-nullsafety.1" cloud_firestore: dependency: "direct main" description: name: cloud_firestore url: "https://pub.dartlang.org" source: hosted - version: "0.13.0+1" - collection: + version: "0.14.4" + cloud_firestore_platform_interface: dependency: transitive description: - name: collection + name: cloud_firestore_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" - convert: + version: "2.2.1" + cloud_firestore_web: dependency: transitive description: - name: convert + name: cloud_firestore_web url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" - crypto: + version: "0.2.1+2" + collection: dependency: transitive description: - name: crypto + name: collection url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "1.15.0-nullsafety.3" cupertino_icons: dependency: "direct main" description: name: cupertino_icons url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" - firebase: + version: "0.1.2" + fake_async: dependency: transitive description: - name: firebase + name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "7.2.0" + version: "1.2.0-nullsafety.1" firebase_auth: dependency: "direct main" description: name: firebase_auth url: "https://pub.dartlang.org" source: hosted - version: "0.15.3+1" + version: "0.18.4+1" firebase_auth_platform_interface: dependency: transitive description: name: firebase_auth_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.1.5" + version: "2.1.4" firebase_auth_web: dependency: transitive description: name: firebase_auth_web url: "https://pub.dartlang.org" source: hosted - version: "0.1.1+4" + version: "0.3.2+3" firebase_core: dependency: "direct main" description: name: firebase_core url: "https://pub.dartlang.org" source: hosted - version: "0.4.3+2" + version: "0.5.3" firebase_core_platform_interface: dependency: transitive description: name: firebase_core_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "2.1.0" firebase_core_web: dependency: transitive description: name: firebase_core_web url: "https://pub.dartlang.org" source: hosted - version: "0.1.1+2" + version: "0.2.1+1" flutter: dependency: "direct main" description: flutter @@ -142,48 +142,41 @@ packages: description: flutter source: sdk version: "0.0.0" - http: - dependency: transitive - description: - name: http - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.0+4" http_parser: dependency: transitive description: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "3.1.3" - image: + version: "3.1.4" + intl: dependency: transitive description: - name: image + name: intl url: "https://pub.dartlang.org" source: hosted - version: "2.1.4" + version: "0.16.1" js: dependency: transitive description: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.1+1" + version: "0.6.2" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.12.10-nullsafety.1" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0-nullsafety.3" modal_progress_hud: dependency: "direct main" description: @@ -197,28 +190,21 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" - pedantic: + version: "1.8.0-nullsafety.1" + plugin_platform_interface: dependency: transitive description: - name: pedantic + name: plugin_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.8.0+1" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.0" + version: "1.0.3" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.1.5" sky_engine: dependency: transitive description: flutter @@ -230,63 +216,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.0-nullsafety.2" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0-nullsafety.1" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0-nullsafety.1" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0-nullsafety.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0-nullsafety.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.11" + version: "0.2.19-nullsafety.2" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0-nullsafety.3" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.dartlang.org" - source: hosted - version: "3.5.0" + version: "2.1.0-nullsafety.3" sdks: - dart: ">=2.7.0-dev <3.0.0" - flutter: ">=1.12.13+hotfix.4 <2.0.0" + dart: ">=2.10.0 <2.11.0" + flutter: ">=1.22.0 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 31e91cc..a8239dd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,18 +4,17 @@ description: A new Flutter application. version: 1.0.0+1 environment: - sdk: ">=2.0.0 <3.0.0" + sdk: '>=2.1.0<3.0.0' dependencies: flutter: sdk: flutter - + animated_text_kit: ^3.1.0 cupertino_icons: ^0.1.2 - animated_text_kit: ^1.3.0 - firebase_core: ^0.3.4 - firebase_auth: ^0.8.4+4 - cloud_firestore: ^0.9.13+1 + firebase_core: ^0.5.3 + firebase_auth: ^0.18.4+1 modal_progress_hud: ^0.1.3 + cloud_firestore: ^0.14.4 dev_dependencies: flutter_test: @@ -25,4 +24,4 @@ flutter: uses-material-design: true assets: - - images/ + - images/