Skip to content

Commit

Permalink
v1 complete
Browse files Browse the repository at this point in the history
  • Loading branch information
ErfanRht committed Sep 9, 2021
1 parent f38fb4f commit c0fc276
Show file tree
Hide file tree
Showing 31 changed files with 699 additions and 319 deletions.
55 changes: 55 additions & 0 deletions lib/controllers/home/drawer/edit-profile-controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:todo/models/user/user-email.dart';

class EditProfileController extends GetxController {
String userName = "";
String userEmail = "";
String userAge = "";

bool validationEmail = true;

updateUserName({@required String name}) {
userName = name;
update();
}

updateUserEmail({@required String email}) {
userEmail = email;
update();
}

updateUserAge({@required String age}) {
userAge = age;
update();
}

updateValidations({
@required bool newValidationEmail,
}) {
validationEmail = newValidationEmail;
print(validationEmail);

update();
}

resetState() {
userName = "";
userEmail = "";
userAge = "";
validationEmail = true;
update();
}
}

Future<bool> editProfileChecker({@required String email}) async {
bool response = false;
await EmailValidation(email: email).then((bool value) {
if (email == "") {
response = true;
} else {
response = value;
}
});
return response;
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ import 'package:get/get.dart';
class MainController extends GetxController {
bool isFirstEnter = false;
String userName = "";
String userEmail = "";
String userAge = "";

List tasks = [];

updateMainStete(
{bool newFirstEnterStatus, String newUserName, List newTasks}) {
{bool newFirstEnterStatus,
String newUserName,
String newUserEmail,
String newUserAge,
List newTasks}) {
isFirstEnter =
newFirstEnterStatus != null ? newFirstEnterStatus : isFirstEnter;
userName = newUserName != null ? newUserName : userName;
userEmail = newUserEmail != null ? newUserEmail : userEmail;
userAge = newUserAge != null ? newUserAge : userAge;
tasks = newTasks != null ? newTasks : tasks;

update();
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:todo/constants/colors.dart';
import 'package:todo/constants/routes.dart';
import 'package:todo/controllers/controller.dart';
import 'package:todo/controllers/main-controller.dart';
import 'package:todo/screens/home/home.dart';
import 'package:todo/screens/home/new-task/new-task.dart';
import 'package:todo/screens/loading/loading.dart';
Expand All @@ -15,7 +15,7 @@ void main() {
// ignore: must_be_immutable
class App extends StatelessWidget {
MainController mainController = Get.put(MainController());
String initRoute = loading_route;
final String initRoute = loading_route;
@override
Widget build(BuildContext context) {
return MaterialApp(
Expand Down
4 changes: 2 additions & 2 deletions lib/models/tasks.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:todo/controllers/controller.dart';
import 'package:todo/controllers/newtask-controller.dart';
import 'package:todo/controllers/main-controller.dart';
import 'package:todo/controllers/new-task/newtask-controller.dart';

Future<bool> getTasks() async {
try {
Expand Down
42 changes: 0 additions & 42 deletions lib/models/user-name.dart

This file was deleted.

Empty file added lib/models/user/user-age.dart
Empty file.
43 changes: 43 additions & 0 deletions lib/models/user/user-email.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:todo/controllers/main-controller.dart';

Future<bool> checkUserEmail() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
bool userNameStatus = prefs.getString('user-email') != null ? true : false;

return userNameStatus;
}

Future<bool> setUserEmail({@required String userEmail}) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
EmailValidation(email: userEmail).then((response) {
if (response) {
prefs.setString('user-email', userEmail);
getUserEmail();
return true;
} else {
return false;
}
});
}

Future<String> getUserEmail() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String userEmail = prefs.getString('user-email');
Get.find<MainController>().updateMainStete(newUserEmail: userEmail);

return userEmail;
}

// ignore: non_constant_identifier_names
Future<bool> EmailValidation({@required String email}) async {
Pattern pattern =
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
RegExp regex = RegExp(pattern);
if (!regex.hasMatch(email))
return false;
else
return true;
}
38 changes: 38 additions & 0 deletions lib/models/user/user-name.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:todo/controllers/main-controller.dart';

Future<bool> checkUserName() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
bool userNameStatus = prefs.getString('user-name') != null ? true : false;

// return false; // just for debuging
return userNameStatus;
}

Future<bool> setUserName({@required String userName}) async {
if (userName == null ||
userName == "" ||
userName == " " ||
userName == " " ||
userName == " ") {
return false;
}
try {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('user-name', userName);
getUserName();
return true;
} catch (e) {
return false;
}
}

Future<String> getUserName() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String userName = prefs.getString('user-name');
Get.find<MainController>().updateMainStete(newUserName: userName);

return userName;
}
12 changes: 12 additions & 0 deletions lib/models/user/user.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:flutter/material.dart';
import 'package:todo/models/user/user-email.dart';
import 'package:todo/models/user/user-name.dart';

Future<bool> UpdateUserData({String name, String email, String age}) async {
if (name != null && name != "") {
setUserName(userName: name);
}
if (email != null && email != "") {
setUserEmail(userEmail: email);
}
}
Loading

0 comments on commit c0fc276

Please # to comment.