Skip to content

Commit

Permalink
feat: note editing, note creation
Browse files Browse the repository at this point in the history
  • Loading branch information
matteopolak committed Nov 22, 2022
1 parent 61f47fc commit 348c85b
Show file tree
Hide file tree
Showing 9 changed files with 403 additions and 206 deletions.
4 changes: 3 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ android {
applicationId "com.matteopolak.geonotes"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}

buildTypes {
Expand All @@ -68,4 +69,5 @@ flutter {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:multidex:1.0.3'
}
140 changes: 75 additions & 65 deletions lib/features/login/login_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ class LoginPageState extends State<LoginPage> {
if (formState == null || !formState.validate()) return;

try {
UserCredential userCredential = await FirebaseAuth.instance
.signInWithEmailAndPassword(
email: emailController.text, password: passwordController.text);
await FirebaseAuth.instance.signInWithEmailAndPassword(
email: emailController.text, password: passwordController.text);

onSuccess.call();
} on FirebaseAuthException catch (e) {
Expand All @@ -60,83 +59,94 @@ class LoginPageState extends State<LoginPage> {
return Scaffold(
backgroundColor: Theme.of(context).backgroundColor,
body: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(
children: [
Padding(
child: Form(
key: _formKey,
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 60),
child: Center(
child: Container(
width: 200,
height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
image: const DecorationImage(
image: AssetImage('assets/images/logo.png'),
child: Container(
width: 200,
height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
image: const DecorationImage(
image: AssetImage('assets/images/logo.png'),
),
),
),
))),
const SizedBox(height: 50),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25),
child: TextFormField(
controller: emailController,
validator: (email) => email == null
? null
: emailRegex.hasMatch(email)
? null
: AppLocalizations.of(context)!.invalidEmailError,
decoration: InputDecoration(
),
),
const SizedBox(height: 50),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25),
child: TextFormField(
controller: emailController,
validator: (email) => email == null
? null
: emailRegex.hasMatch(email)
? null
: AppLocalizations.of(context)!.invalidEmailError,
decoration: InputDecoration(
errorText: emailError,
labelText: AppLocalizations.of(context)!.emailLabel),
labelText: AppLocalizations.of(context)!.emailLabel,
),
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 25, right: 25, top: 10, bottom: 0),
//padding: EdgeInsets.symmetric(horizontal: 15),
child: TextFormField(
obscureText: true,
controller: passwordController,
validator: (password) => password != null && password.isNotEmpty
? null
: AppLocalizations.of(context)!.passwordEmptyError,
decoration: InputDecoration(
Padding(
padding: const EdgeInsets.only(
left: 25, right: 25, top: 10, bottom: 0),
//padding: EdgeInsets.symmetric(horizontal: 15),
child: TextFormField(
obscureText: true,
controller: passwordController,
validator: (password) =>
password != null && password.isNotEmpty
? null
: AppLocalizations.of(context)!.passwordEmptyError,
decoration: InputDecoration(
errorText: passwordError,
labelText: AppLocalizations.of(context)!.passwordLabel),
labelText: AppLocalizations.of(context)!.passwordLabel,
),
),
),
),
const SizedBox(
height: 35,
),
SizedBox(
height: 50,
width: 250,
child: ElevatedButton(
onPressed: () {
authenticate(() {
Navigator.push(context,
MaterialPageRoute(builder: (_) => const NotesPage()));
});
},
child: Text(
AppLocalizations.of(context)!.loginButtonLabel,
const SizedBox(
height: 35,
),
SizedBox(
height: 50,
width: 250,
child: ElevatedButton(
onPressed: () {
authenticate(() {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (_) => const NotesPage(),
),
);
});
},
child: Text(
AppLocalizations.of(context)!.loginButtonLabel,
),
),
),
),
const SizedBox(
height: 100,
),
TextButton(
const SizedBox(
height: 100,
),
TextButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (_) => const RegisterPage()));
},
child: Text(AppLocalizations.of(context)!.newUserCreateAccount))
],
child: Text(AppLocalizations.of(context)!.newUserCreateAccount),
)
],
),
),
)),
),
);
}
}
164 changes: 94 additions & 70 deletions lib/features/login/register_controller.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import '../notes/notes_controller.dart';
Expand Down Expand Up @@ -39,6 +40,21 @@ class RegisterPageState extends State<RegisterPage> {
.createUserWithEmailAndPassword(
email: emailController.text, password: passwordController.text);

if (userCredential.user == null) {
return setState(() {
emailError = AppLocalizations.of(context)!.unknownError;
passwordError = null;
});
}

CollectionReference users =
FirebaseFirestore.instance.collection('users');

await users.doc(userCredential.user!.uid).set({
'email': userCredential.user!.email,
'uid': userCredential.user!.uid
});

onSuccess.call();
} on FirebaseAuthException catch (e) {
if (e.code == 'weak-password') {
Expand All @@ -63,86 +79,94 @@ class RegisterPageState extends State<RegisterPage> {
),
backgroundColor: Theme.of(context).backgroundColor,
body: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 60),
child: Center(
child: Container(
width: 200,
height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
image: const DecorationImage(
image: AssetImage('assets/images/logo.png'),
child: Form(
key: _formKey,
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 60),
child: Center(
child: Container(
width: 200,
height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
image: const DecorationImage(
image: AssetImage('assets/images/logo.png'),
),
),
),
))),
const SizedBox(height: 50),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25),
child: TextFormField(
controller: emailController,
validator: (email) => email == null
? null
: emailRegex.hasMatch(email)
? null
: "Invalid email address",
decoration: InputDecoration(
errorText: emailError,
labelText: AppLocalizations.of(context)!.emailLabel),
))),
const SizedBox(height: 50),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25),
child: TextFormField(
controller: emailController,
validator: (email) => email == null
? null
: emailRegex.hasMatch(email)
? null
: 'Invalid email address',
decoration: InputDecoration(
errorText: emailError,
labelText: AppLocalizations.of(context)!.emailLabel),
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 25, right: 25, top: 10, bottom: 0),
child: TextFormField(
obscureText: true,
controller: passwordController,
validator: (password) => password != null && password.isNotEmpty
? null
: AppLocalizations.of(context)!.passwordEmptyError,
decoration: InputDecoration(
errorText: passwordError,
labelText: AppLocalizations.of(context)!.passwordLabel),
Padding(
padding: const EdgeInsets.only(
left: 25, right: 25, top: 10, bottom: 0),
child: TextFormField(
obscureText: true,
controller: passwordController,
validator: (password) =>
password != null && password.isNotEmpty
? null
: AppLocalizations.of(context)!.passwordEmptyError,
decoration: InputDecoration(
errorText: passwordError,
labelText: AppLocalizations.of(context)!.passwordLabel),
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 25, right: 25, top: 10, bottom: 0),
child: TextFormField(
obscureText: true,
controller: retypePasswordController,
validator: (password) => password == passwordController.text
? null
: AppLocalizations.of(context)!.passwordMatchError,
decoration: InputDecoration(
Padding(
padding: const EdgeInsets.only(
left: 25, right: 25, top: 10, bottom: 0),
child: TextFormField(
obscureText: true,
controller: retypePasswordController,
validator: (password) => password == passwordController.text
? null
: AppLocalizations.of(context)!.passwordMatchError,
decoration: InputDecoration(
labelText:
AppLocalizations.of(context)!.retypePasswordLabel),
AppLocalizations.of(context)!.retypePasswordLabel,
),
),
),
const SizedBox(
height: 35,
),
),
const SizedBox(
height: 35,
),
SizedBox(
height: 50,
width: 250,
child: ElevatedButton(
SizedBox(
height: 50,
width: 250,
child: ElevatedButton(
onPressed: () {
register(() {
Navigator.pushReplacement(
register(
() {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => const NotesPage()));
});
builder: (context) => const NotesPage(),
),
);
},
);
},
child: Text(AppLocalizations.of(context)!.registerLabel)),
),
],
child: Text(AppLocalizations.of(context)!.registerLabel),
),
),
],
),
),
)),
),
);
}
}
Loading

0 comments on commit 348c85b

Please sign in to comment.