From 917deb2fd32f8314ed16c03373620d74d85228fb Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 1 Dec 2020 10:46:53 +0100 Subject: [PATCH 1/7] Small reworking of the auth page --- assets/images/logo-white.png | Bin 0 -> 2700 bytes lib/screens/auth_screen.dart | 70 ++++++++++++++++++++--------------- pubspec.yaml | 1 + 3 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 assets/images/logo-white.png diff --git a/assets/images/logo-white.png b/assets/images/logo-white.png new file mode 100644 index 0000000000000000000000000000000000000000..4890d2848d805437219bb0566d224b853e6917ad GIT binary patch literal 2700 zcmaJ@dpy(o8{cfqEh@JnGtB)Gxt2s7j(us;&+~qs=kt1f&iQzIY?0TL2Z2Ca z0F)bMGtz&UtjwmL`So4%W{@MHf)YU>nWH}pJm)zZy$S9ly9bhe%B=7Rs9R$@rH^m)Q8kU-MKE}9Q z;x+7W_v-2sC(1}->)X-23xYP@y%#f`?E(QWF(YEErR{UUM58W2o+Ml6g236;2?h2B z7J`Ax>~v(X@!V11m*LkGMux@Q)T@S8%_1_LU24$YuV*{YxkzTQwK0PW+l%;}?6(HQ zzqXb2T`4BF!U$BeS1Z-J2;!fYGgx-CRhPe)U_` z-l120ItJzRROgnXNHl|gY_)fq{e{lH;al58Ga@7b8o=?Z_R3+)9qfC^bjOv{U5@fI z3GY#<1_bE&yY9k5WV-Q6>O6&U+E2EZ#m-z#i1B}u`POJ9wfBZmuP=%PO4DwJzHuPh z-J~c4Dq#uukG>lHKn(;*FcK-^tgQ@)cEu-@%^_SHo&!ds-`fIWE4sgvs7=~Jy1{HO zZ7u1GQmeQnGMAEgoj}iXWG;bRtax8HIecX{w`YOK&3Ap6Y`R#|nekOS%<;xo~A7dn~4d*TA^YOUxmsaLXz_2-sJ!sDB{j z^&YIpZpdYDQ|S;T+`M8D1h8bV^2tZq){?VHvGW-=zC|{c=B^Bhk$AF9I=ON=bI;@BYRmwXSq`oP%pnqFw1rEIO~YXNCTa+EOkl9F{S@_noAm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dEW5eD$xNk{6)V1E_j+bE1OEE%r74yv|O!jC%C~VG6m|6zvfOy_Z8-=JmEVtR8~DhlXysFX>TIm713T?Qs8fUDR>g7M1jC7!o&Bib^{RMOMi#TZsI}yDlvYKy*lkKr zv`c2vZAx9_k2}XS(55xiqW1X+iHtGdOic#47TK8*XbAN4)JBiMF^*J{UlF;Doujfb z5$0?-=X-l_+VujN!8THX>DKx&@MdL2Nw)z_Bf>5A4CC>2UIXL37mJ=+-lC42XD?n| zj}n%|L|4OBl|u_uo~f3nY2%b6nX+ zlBV->x;vh%$#?S(39WBu^2}&#fN`m+%tGi1Tm{y(f~8d(QHjVJ6NKY#GjTJ;;o?Dk zf&-9f&~BS8iaGY?=(xqo0_hyULd[ - Container( - decoration: BoxDecoration( - color: const Color(0xff222000), - image: new DecorationImage( - fit: BoxFit.cover, - colorFilter: ColorFilter.mode(Colors.black.withOpacity(0.2), BlendMode.dstATop), - image: new AssetImage( - 'assets/images/main.jpg', + if (false) + Container( + decoration: BoxDecoration( + color: const Color(0xff222000), + image: new DecorationImage( + fit: BoxFit.cover, + colorFilter: ColorFilter.mode( + Colors.black.withOpacity(0.2), BlendMode.dstATop), + image: new AssetImage( + 'assets/images/main.jpg', + ), ), ), ), - ), SingleChildScrollView( child: Container( height: deviceSize.height, @@ -40,22 +45,21 @@ class AuthScreen extends StatelessWidget { children: [ Padding(padding: EdgeInsets.symmetric(vertical: 20)), Image( - image: AssetImage('assets/images/logo.png'), + image: AssetImage('assets/images/logo-white.png'), width: 120, ), - Flexible( - child: Container( - margin: EdgeInsets.only(bottom: 20.0), - padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 94.0), - // ..translate(-10.0), - child: Text( - 'WGER', - style: TextStyle( - color: Theme.of(context).accentColor, - fontSize: 50, - fontFamily: 'OpenSansBold', - fontWeight: FontWeight.bold, - ), + Container( + margin: EdgeInsets.only(bottom: 20.0), + padding: + EdgeInsets.symmetric(vertical: 8.0, horizontal: 94.0), + // ..translate(-10.0), + child: Text( + 'WGER', + style: TextStyle( + color: Colors.white, + fontSize: 50, + fontFamily: 'OpenSansBold', + fontWeight: FontWeight.bold, ), ), ), @@ -149,6 +153,10 @@ class _AuthCardState extends State { //} finally { // var errorMessage = 'Could not authenticate you. Please try again later'; // _showErrorDialog(errorMessage); + + } catch (error) { + String errorMessage = error.toString(); + _showErrorDialog(errorMessage); } setState(() { @@ -177,8 +185,10 @@ class _AuthCardState extends State { ), elevation: 8.0, child: Container( - height: _authMode == AuthMode.Signup ? 520 : 320, - constraints: BoxConstraints(minHeight: _authMode == AuthMode.Signup ? 520 : 320), + //decoration: BoxDecoration(color: Colors.black12), + //height: _authMode == AuthMode.Signup ? 450 : 320, + //constraints: + // BoxConstraints(minHeight: _authMode == AuthMode.Signup ? 450 : 320), width: deviceSize.width * 0.75, padding: EdgeInsets.all(16.0), child: Form( @@ -266,11 +276,13 @@ class _AuthCardState extends State { CircularProgressIndicator() else ElevatedButton( - child: Text(_authMode == AuthMode.Login ? 'LOGIN' : 'SIGN UP'), + child: + Text(_authMode == AuthMode.Login ? 'LOGIN' : 'SIGN UP'), onPressed: _submit, ), TextButton( - child: Text('${_authMode == AuthMode.Login ? 'SIGNUP' : 'LOGIN'} INSTEAD'), + child: Text( + '${_authMode == AuthMode.Login ? 'SIGNUP' : 'LOGIN'} INSTEAD'), onPressed: _switchAuthMode, ), ], diff --git a/pubspec.yaml b/pubspec.yaml index d9753bdf2..d2901b3bc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -70,6 +70,7 @@ flutter: assets: - assets/images/main.jpg - assets/images/logo.png + - assets/images/logo-white.png - assets/images/placeholder.png # An image asset can refer to one or more resolution-specific "variants", see From 704333f5afeb1dfebad8e7dd626f2d535555c45c Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 1 Dec 2020 11:46:44 +0100 Subject: [PATCH 2/7] Add controllers to text fields Otherwise, the filled in content would jump around when switching modes --- lib/screens/auth_screen.dart | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/screens/auth_screen.dart b/lib/screens/auth_screen.dart index 1d7ccbf15..f81ef3ca4 100644 --- a/lib/screens/auth_screen.dart +++ b/lib/screens/auth_screen.dart @@ -96,7 +96,13 @@ class _AuthCardState extends State { 'serverUrl': '', }; var _isLoading = false; - final _passwordController = TextEditingController(); + final _usernameController = TextEditingController(text: 'admin'); + final _passwordController = TextEditingController(text: 'admin'); + final _password2Controller = TextEditingController(); + final _emailController = TextEditingController(); + final _serverUrlController = TextEditingController( + text: 'http://10.0.2.2::8000', + ); void _showErrorDialog(String message) { showDialog( @@ -198,6 +204,7 @@ class _AuthCardState extends State { children: [ TextFormField( decoration: InputDecoration(labelText: 'Username'), + controller: _usernameController, textInputAction: TextInputAction.next, keyboardType: TextInputType.emailAddress, validator: (value) { @@ -213,6 +220,7 @@ class _AuthCardState extends State { if (_authMode == AuthMode.Signup) TextFormField( decoration: InputDecoration(labelText: 'E-Mail'), + controller: _emailController, keyboardType: TextInputType.emailAddress, textInputAction: TextInputAction.next, validator: (value) { @@ -243,8 +251,8 @@ class _AuthCardState extends State { }, ), TextFormField( - decoration: InputDecoration(labelText: 'Server Url'), - initialValue: 'http://10.0.2.2:8000', + decoration: InputDecoration(labelText: 'Server URL'), + controller: _serverUrlController, validator: (value) { if (value.isEmpty || !value.contains('http')) { return 'Invalid URL!'; @@ -258,6 +266,7 @@ class _AuthCardState extends State { if (_authMode == AuthMode.Signup) TextFormField( decoration: InputDecoration(labelText: 'Confirm Password'), + controller: _password2Controller, enabled: _authMode == AuthMode.Signup, obscureText: true, validator: _authMode == AuthMode.Signup From 4f10bf6160460d3cd2a937f3c952d64a2c156a6f Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 1 Dec 2020 11:48:25 +0100 Subject: [PATCH 3/7] Correctly show error messages from the server This still looks kinda awful... --- lib/screens/auth_screen.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/screens/auth_screen.dart b/lib/screens/auth_screen.dart index f81ef3ca4..095258d19 100644 --- a/lib/screens/auth_screen.dart +++ b/lib/screens/auth_screen.dart @@ -149,11 +149,11 @@ class _AuthCardState extends State { var errorMessage = 'Authentication Failed'; if (error.errors.containsKey('username')) { - errorMessage = error.errors['username']; + errorMessage = "Username: " + error.errors['username'][0]; } else if (error.errors.containsKey('password')) { - errorMessage = error.errors['password']; + errorMessage = "Password: " + error.errors['password'][0]; } else if (error.errors.containsKey('detail')) { - errorMessage = error.errors['detail']; + errorMessage = error.errors['detail'][0]; } _showErrorDialog(errorMessage); //} finally { From 1f65bb82951022666b6b13e351e06162d682abf9 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 1 Dec 2020 11:53:37 +0100 Subject: [PATCH 4/7] Put password fields next to each other --- lib/screens/auth_screen.dart | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/screens/auth_screen.dart b/lib/screens/auth_screen.dart index 095258d19..d93c45569 100644 --- a/lib/screens/auth_screen.dart +++ b/lib/screens/auth_screen.dart @@ -250,19 +250,6 @@ class _AuthCardState extends State { _authData['password'] = value; }, ), - TextFormField( - decoration: InputDecoration(labelText: 'Server URL'), - controller: _serverUrlController, - validator: (value) { - if (value.isEmpty || !value.contains('http')) { - return 'Invalid URL!'; - } - return null; - }, - onSaved: (value) { - _authData['serverUrl'] = value; - }, - ), if (_authMode == AuthMode.Signup) TextFormField( decoration: InputDecoration(labelText: 'Confirm Password'), @@ -278,6 +265,19 @@ class _AuthCardState extends State { } : null, ), + TextFormField( + decoration: InputDecoration(labelText: 'Server URL'), + controller: _serverUrlController, + validator: (value) { + if (value.isEmpty || !value.contains('http')) { + return 'Invalid URL!'; + } + return null; + }, + onSaved: (value) { + _authData['serverUrl'] = value; + }, + ), SizedBox( height: 20, ), From 43f6c640818ed16ae83c007853e1ad3efb26d831 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 1 Dec 2020 13:20:58 +0100 Subject: [PATCH 5/7] Some improvements to exception handling --- lib/providers/auth.dart | 2 +- lib/screens/auth_screen.dart | 22 +++++++--------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/providers/auth.dart b/lib/providers/auth.dart index ea6781114..298b40e18 100644 --- a/lib/providers/auth.dart +++ b/lib/providers/auth.dart @@ -79,7 +79,7 @@ class Auth with ChangeNotifier { }); prefs.setString('userData', userData); } catch (error) { - throw HttpException(error.errors); + throw error; } } diff --git a/lib/screens/auth_screen.dart b/lib/screens/auth_screen.dart index d93c45569..3353da49c 100644 --- a/lib/screens/auth_screen.dart +++ b/lib/screens/auth_screen.dart @@ -27,8 +27,7 @@ class AuthScreen extends StatelessWidget { color: const Color(0xff222000), image: new DecorationImage( fit: BoxFit.cover, - colorFilter: ColorFilter.mode( - Colors.black.withOpacity(0.2), BlendMode.dstATop), + colorFilter: ColorFilter.mode(Colors.black.withOpacity(0.2), BlendMode.dstATop), image: new AssetImage( 'assets/images/main.jpg', ), @@ -50,8 +49,7 @@ class AuthScreen extends StatelessWidget { ), Container( margin: EdgeInsets.only(bottom: 20.0), - padding: - EdgeInsets.symmetric(vertical: 8.0, horizontal: 94.0), + padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 94.0), // ..translate(-10.0), child: Text( 'WGER', @@ -149,17 +147,13 @@ class _AuthCardState extends State { var errorMessage = 'Authentication Failed'; if (error.errors.containsKey('username')) { - errorMessage = "Username: " + error.errors['username'][0]; + errorMessage = "Username: " + error.errors['username'].join('\n\n'); } else if (error.errors.containsKey('password')) { - errorMessage = "Password: " + error.errors['password'][0]; + errorMessage = "Password: " + error.errors['password'].join('\n\n'); } else if (error.errors.containsKey('detail')) { - errorMessage = error.errors['detail'][0]; + errorMessage = error.errors['detail']; } _showErrorDialog(errorMessage); - //} finally { - // var errorMessage = 'Could not authenticate you. Please try again later'; - // _showErrorDialog(errorMessage); - } catch (error) { String errorMessage = error.toString(); _showErrorDialog(errorMessage); @@ -285,13 +279,11 @@ class _AuthCardState extends State { CircularProgressIndicator() else ElevatedButton( - child: - Text(_authMode == AuthMode.Login ? 'LOGIN' : 'SIGN UP'), + child: Text(_authMode == AuthMode.Login ? 'LOGIN' : 'SIGN UP'), onPressed: _submit, ), TextButton( - child: Text( - '${_authMode == AuthMode.Login ? 'SIGNUP' : 'LOGIN'} INSTEAD'), + child: Text('${_authMode == AuthMode.Login ? 'SIGNUP' : 'LOGIN'} INSTEAD'), onPressed: _switchAuthMode, ), ], From 741ad8ebae75ead84a457045f4ad7742919d24b9 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 1 Dec 2020 13:22:26 +0100 Subject: [PATCH 6/7] Fix port --- lib/screens/auth_screen.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/screens/auth_screen.dart b/lib/screens/auth_screen.dart index 3353da49c..de405eede 100644 --- a/lib/screens/auth_screen.dart +++ b/lib/screens/auth_screen.dart @@ -98,9 +98,7 @@ class _AuthCardState extends State { final _passwordController = TextEditingController(text: 'admin'); final _password2Controller = TextEditingController(); final _emailController = TextEditingController(); - final _serverUrlController = TextEditingController( - text: 'http://10.0.2.2::8000', - ); + final _serverUrlController = TextEditingController(text: 'http://10.0.2.2:8000'); void _showErrorDialog(String message) { showDialog( From 231288a730d61225ade4d26d6ba56c20b5a1c12a Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 1 Dec 2020 14:53:20 +0100 Subject: [PATCH 7/7] Remove duplicated dependency --- pubspec.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index d2901b3bc..73c6ab2f7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -39,7 +39,6 @@ dev_dependencies: sdk: flutter flutter_launcher_icons: ^0.8.1 intl_translation: ^0.17.10+1 - json_serializable: ^3.5.0 # Note that there are incompatibilities when using a higher version. Both build # runner and intl_translation depend on different versions of analyzer