Skip to content

Commit

Permalink
Merge pull request #20 from acs-upb-mobile/classes
Browse files Browse the repository at this point in the history
Add classes functionality and other minor improvements
  • Loading branch information
IoanaAlexandru authored Aug 28, 2020
2 parents c37269c + b2b7dbd commit e036e70
Show file tree
Hide file tree
Showing 35 changed files with 3,290 additions and 615 deletions.
Binary file modified assets/fonts/CustomIcons/CustomIcons.ttf
Binary file not shown.
Binary file added assets/illustrations/undraw_empty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/illustrations/undraw_login.png
Binary file not shown.
Binary file added assets/illustrations/undraw_share_link.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/illustrations/undraw_sign_in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions lib/authentication/service/auth_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ extension DatabaseUser on User {
class AuthProvider with ChangeNotifier {
FirebaseUser _firebaseUser;
StreamSubscription _userAuthSub;
User _currentUser;

AuthProvider() {
_userAuthSub = FirebaseAuth.instance.onAuthStateChanged.listen((newUser) {
print('AuthProvider - FirebaseAuth - onAuthStateChanged - $newUser');
_firebaseUser = newUser;
_fetchUser();
notifyListeners();
}, onError: (e) {
print('AuthProvider - FirebaseAuth - onAuthStateChanged - $e');
Expand Down Expand Up @@ -178,17 +180,23 @@ class AuthProvider with ChangeNotifier {
return _firebaseUser.uid;
}

Future<User> get currentUser async {
Future<User> _fetchUser() async {
if (isAnonymous) {
return null;
}
DocumentSnapshot snapshot = await Firestore.instance
.collection('users')
.document(_firebaseUser.uid)
.get();
return DatabaseUser.fromSnap(snapshot);

_currentUser = DatabaseUser.fromSnap(snapshot);
return _currentUser;
}

Future<User> get currentUser => _fetchUser();

User get currentUserFromCache => _currentUser;

Future<bool> signInAnonymously({BuildContext context}) async {
return FirebaseAuth.instance.signInAnonymously().catchError((e) {
_errorHandler(e, context);
Expand Down
208 changes: 109 additions & 99 deletions lib/authentication/view/login_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class _LoginViewState extends State<LoginView> {
hint: S.of(context).hintEmail,
suffix: emailDomain,
controller: emailController,
autocorrect: false,
check: (email, {BuildContext context}) =>
authProvider.canSignInWithPassword(
email: email + emailDomain, context: context),
Expand Down Expand Up @@ -142,117 +143,126 @@ class _LoginViewState extends State<LoginView> {
AuthProvider authProvider = Provider.of<AuthProvider>(context);
AppForm loginForm = _buildForm(context);

return Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
Align(
alignment: FractionalOffset.topRight,
child: Padding(
padding: EdgeInsets.all(10.0),
child: Container(
height: MediaQuery.of(context).size.height / 3,
child: Image.asset(
"assets/illustrations/undraw_digital_nomad.png")),
),
),
Align(
alignment: FractionalOffset.bottomCenter,
child: ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height / 4,
maxWidth: MediaQuery.of(context).size.width,
return GestureDetector(
onTap: () {
// Remove current focus on tap
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
},
child: Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
Align(
alignment: FractionalOffset.topRight,
child: Padding(
padding: EdgeInsets.all(10.0),
child: Container(
height: MediaQuery.of(context).size.height / 3,
child: Image.asset(
"assets/illustrations/undraw_digital_nomad.png")),
),
child: FittedBox(
fit:BoxFit.contain,
child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: 1,
minHeight: 1,
),
Align(
alignment: FractionalOffset.bottomCenter,
child: ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height / 4,
maxWidth: MediaQuery.of(context).size.width,
),
child: FittedBox(
fit: BoxFit.contain,
child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: 1,
minHeight: 1,
),
child: Image.asset("assets/images/city_doodle.png",
color: Theme.of(context).accentColor.withOpacity(0.4)),
),
child: Image.asset("assets/images/city_doodle.png",
color: Theme.of(context).accentColor.withOpacity(0.4)),
),
),
),
),
SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(left: 28.0, right: 28.0, bottom: 8.0),
child: IntrinsicHeight(
child: Column(
children: <Widget>[
SizedBox(
height: MediaQuery.of(context).size.height / 3,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(left: 28.0, right: 28.0, bottom: 8.0),
child: IntrinsicHeight(
child: Column(
children: <Widget>[
SizedBox(
height: MediaQuery.of(context).size.height / 3,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
UniBanner(),
],
),
),
SizedBox(height: 10),
Expanded(child: loginForm),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
UniBanner(),
Expanded(
child: AppButton(
key: ValueKey('log_in_anonymously_button'),
text: S.of(context).actionLogInAnonymously,
onTap: () async {
var result = await authProvider
.signInAnonymously(context: context);
if (result) {
Navigator.pushReplacementNamed(
context, Routes.home);
}
},
),
),
SizedBox(width: 20),
Expanded(
child: AppButton(
key: ValueKey('log_in_button'),
color: Theme.of(context).accentColor,
text: S.of(context).actionLogIn,
onTap: () => loginForm.submit(),
),
),
],
),
),
SizedBox(height: 10),
Expanded(child: loginForm),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(
child: AppButton(
key: ValueKey('log_in_anonymously_button'),
text: S.of(context).actionLogInAnonymously,
onTap: () async {
var result = await authProvider.signInAnonymously(
context: context);
if (result) {
Navigator.pushReplacementNamed(
context, Routes.home);
}
},
SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
S.of(context).messageNewUser + " ",
style: Theme.of(context)
.textTheme
.subtitle1
.copyWith(fontWeight: FontWeight.w400),
),
),
SizedBox(width: 20),
Expanded(
child: AppButton(
key: ValueKey('log_in_button'),
color: Theme.of(context).accentColor,
text: S.of(context).actionLogIn,
onTap: () => loginForm.submit(),
InkWell(
onTap: () {
Navigator.pushNamed(context, Routes.signUp);
},
child: Text(S.of(context).actionSignUp,
style: Theme.of(context)
.accentTextTheme
.subtitle1
.copyWith(fontWeight: FontWeight.w500)),
),
),
],
),
SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
S.of(context).messageNewUser + " ",
style: Theme.of(context)
.textTheme
.subtitle1
.copyWith(fontWeight: FontWeight.w400),
),
InkWell(
onTap: () {
Navigator.pushNamed(context, Routes.signUp);
},
child: Text(S.of(context).actionSignUp,
style: Theme.of(context)
.accentTextTheme
.subtitle1
.copyWith(fontWeight: FontWeight.w500)),
),
],
)
],
],
)
],
),
),
),
),
)
],
)
],
),
),
);
}
Expand Down
Loading

0 comments on commit e036e70

Please sign in to comment.