Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Android embedding v2 #49

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
de70c8f
Migrate to Android embedding v2
nyanibaquartey Jan 15, 2022
5f92428
Upgrade cupertino icons dependency from 0.1.2 to 1.0.4
nyanibaquartey Jan 15, 2022
462f6ba
Set bodyText1 TextStyle as TextTheme
nyanibaquartey Jan 15, 2022
224450c
distributionUrl gradle from 5.4.1 to 6.7
nyanibaquartey Jan 15, 2022
9a858f9
Change deprecated jcenter to mavenCentral
nyanibaquartey Jan 15, 2022
973908d
Update gradle dependency to 4.1.0
nyanibaquartey Jan 15, 2022
1f9cd26
Create id variable to use in named routes
nyanibaquartey Jan 15, 2022
b855fd4
Add named routes
nyanibaquartey Jan 15, 2022
13a6398
Fix typo
nyanibaquartey Jan 15, 2022
8bdc9e7
Make id variable constant - add const keyword
nyanibaquartey Jan 15, 2022
43074c1
Add text color
nyanibaquartey Jan 15, 2022
40b56a1
Add hero widget to animate the logo
nyanibaquartey Jan 15, 2022
072d748
Set the color of the hint text
nyanibaquartey Jan 15, 2022
25702cd
Animate the app's background color
nyanibaquartey Jan 17, 2022
267683e
Add animated_text_kit package dependency
nyanibaquartey Jan 17, 2022
e3a9144
Implement the animated text kit pacckage
nyanibaquartey Jan 17, 2022
bd51b8a
Extract Padding widget into a custom widget
nyanibaquartey Jan 17, 2022
034d085
New file for custom button
nyanibaquartey Jan 17, 2022
669c346
Move custom RoundedButton class into a new file
nyanibaquartey Jan 17, 2022
3125fe5
Create a variable for InputDecoration
nyanibaquartey Jan 18, 2022
ebb17d4
Refactor - Replace InputDecoration with a variable
nyanibaquartey Jan 18, 2022
03f3b23
Edit applicationId
nyanibaquartey Jan 18, 2022
cac1922
Edit
nyanibaquartey Jan 18, 2022
197581b
Edit to inteegrate Firebase
nyanibaquartey Jan 18, 2022
6503321
Add Firebase dependencies - core, auth, firestore
nyanibaquartey Jan 18, 2022
8bf3bdf
Assign user email and password to variables
nyanibaquartey Jan 18, 2022
b3a322e
Set minSdkVersion to 19
nyanibaquartey Jan 18, 2022
a09b676
Set text alignment, text obscurity & keyboard type
nyanibaquartey Jan 18, 2022
e54cbbc
Create new user with FirebaseAuth
nyanibaquartey Jan 18, 2022
130183f
Create email and password variables & Log in user
nyanibaquartey Jan 18, 2022
0a7a623
Get logged in user
nyanibaquartey Jan 18, 2022
1d16a94
Implement log out functionality
nyanibaquartey Jan 18, 2022
891eecd
Initialize app to use Firebase
nyanibaquartey Jan 18, 2022
68f1d57
Set navigation to welcome screen when user signs out
nyanibaquartey Jan 18, 2022
039303a
Set input text color to black
nyanibaquartey Jan 18, 2022
f22c5bf
Set input text color to black
nyanibaquartey Jan 18, 2022
173bea9
Add spinner package - modal progress hud
nyanibaquartey Jan 19, 2022
95d25b5
Implement modal progress hud package
nyanibaquartey Jan 19, 2022
e939dad
Navigate to Log In screen after sign out
nyanibaquartey Jan 19, 2022
ccb2523
Assign user input to a variable
nyanibaquartey Jan 19, 2022
2944d49
Change deprecated FlatButton to TextButton
nyanibaquartey Jan 19, 2022
9bc1952
Implement send functionality - save message to DB
nyanibaquartey Jan 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
.buildlog/
.history
.svn/
*.lock


# IntelliJ related
*.iml
Expand Down Expand Up @@ -61,6 +63,10 @@
**/ios/Flutter/flutter_assets/
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*
*.sh

# Firebase
*.json

# Exceptions to above rules.
!**/ios/**/default.mode1v3
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ We’re going to build a modern messaging app where users can sign up and log in
- How to incorporate Firebase into your Flutter projects.
- How to use Firebase authentication to register and sign in users.
- How to create beautiful animations using the Flutter Hero widget.
- How to create custom aniamtions using Flutter's animation controller.
- How to create custom animations using Flutter's animation controller.
- Learn all about mixins and how they differ from superclasses.
- Learn about Streams and how they work.
- Learn to use ListViews to build scrolling views.
Expand Down
6 changes: 4 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if (flutterVersionName == null) {

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion 29
Expand All @@ -34,8 +35,8 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "co.appbrewery.flash_chat"
minSdkVersion 16
applicationId "com.nnq.flash_chat"
minSdkVersion 19
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand All @@ -57,4 +58,5 @@ flutter {

dependencies {
implementation 'androidx.multidex:multidex:2.0.0'
implementation platform('com.google.firebase:firebase-bom:29.0.3')
}
17 changes: 10 additions & 7 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="flash_chat"
android:icon="@mipmap/ic_launcher">
<activity
Expand All @@ -17,17 +17,20 @@
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->

<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background" />


<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package co.appbrewery.flash_chat;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;

import io.flutter.embedding.android.FlutterActivity;


public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}

}
7 changes: 4 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.google.gms:google-services:4.3.10'
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
27 changes: 27 additions & 0 deletions lib/components/rounded_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';

class RoundedButton extends StatelessWidget {
const RoundedButton({this.colour, this.title, @required this.onPressed});

final Color colour;
final String title;
final Function onPressed;

@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child: Material(
elevation: 5.0,
color: colour,
borderRadius: BorderRadius.circular(30.0),
child: MaterialButton(
onPressed: onPressed,
minWidth: 200.0,
height: 42.0,
child: Text(title),
),
),
);
}
}
17 changes: 17 additions & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,20 @@ const kMessageContainerDecoration = BoxDecoration(
top: BorderSide(color: Colors.lightBlueAccent, width: 2.0),
),
);

const kTextFieldDecoration = InputDecoration(
hintText: '',
hintStyle: TextStyle(color: Colors.black45),
contentPadding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.lightBlueAccent, width: 1.0),
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.lightBlueAccent, width: 2.0),
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
);
17 changes: 14 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,30 @@ 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';

void main() => runApp(FlashChat());
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(FlashChat());
}

class FlashChat extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
textTheme: TextTheme(
body1: TextStyle(color: Colors.black54),
bodyText1: TextStyle(color: Colors.black54),
),
),
home: WelcomeScreen(),
initialRoute: WelcomeScreen.id,
routes: {
WelcomeScreen.id: (context) => WelcomeScreen(),
LoginScreen.id: (context) => LoginScreen(),
RegistrationScreen.id: (context) => RegistrationScreen(),
ChatScreen.id: (context) => ChatScreen(),
},
);
}
}
46 changes: 39 additions & 7 deletions lib/screens/chat_screen.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,52 @@
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';

class ChatScreen extends StatefulWidget {
static const String id = 'chat_screen';

@override
_ChatScreenState createState() => _ChatScreenState();
}

class _ChatScreenState extends State<ChatScreen> {
final _auth = FirebaseAuth.instance;
final _firestore = FirebaseFirestore.instance;
User loggedInUser;
String messageText;

@override
void initState() {
super.initState();
getCurrentUser();
}

void getCurrentUser() {
try {
final user = _auth.currentUser;
if (user != null) {
loggedInUser = user;
}
} catch (e) {
print(e);
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: null,
actions: <Widget>[
IconButton(
icon: Icon(Icons.close),
onPressed: () {
//Implement logout functionality
}),
icon: Icon(Icons.close),
onPressed: () {
//Implement logout functionality
_auth.signOut();
Navigator.pop(context);
},
),
],
title: Text('⚡️Chat'),
backgroundColor: Colors.lightBlueAccent,
Expand All @@ -35,14 +64,17 @@ class _ChatScreenState extends State<ChatScreen> {
Expanded(
child: TextField(
onChanged: (value) {
//Do something with the user input.
//save user input to a variable.
messageText = value;
},
decoration: kMessageTextFieldDecoration,
),
),
FlatButton(
TextButton(
onPressed: () {
//Implement send functionality.
//save message to database.
_firestore.collection('messages').add(
{'sender': loggedInUser.email, 'text': messageText});
},
child: Text(
'Send',
Expand Down
Loading