diff --git a/assets/images/logo-white.png b/assets/images/logo-white.png new file mode 100644 index 000000000..4890d2848 Binary files /dev/null and b/assets/images/logo-white.png differ 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 6659f55c0..de405eede 100644 --- a/lib/screens/auth_screen.dart +++ b/lib/screens/auth_screen.dart @@ -4,7 +4,10 @@ import 'package:provider/provider.dart'; import '../models/http_exception.dart'; import '../providers/auth.dart'; -enum AuthMode { Signup, Login } +enum AuthMode { + Signup, + Login, +} class AuthScreen extends StatelessWidget { static const routeName = '/auth'; @@ -15,21 +18,22 @@ class AuthScreen extends StatelessWidget { // final transformConfig = Matrix4.rotationZ(-8 * pi / 180); // transformConfig.translate(-10.0); return Scaffold( - // resizeToAvoidBottomInset: false, + backgroundColor: Theme.of(context).primaryColor, body: Stack( children: [ - 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 +44,20 @@ 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, ), ), ), @@ -92,7 +94,11 @@ 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( @@ -139,16 +145,16 @@ class _AuthCardState extends State { var errorMessage = 'Authentication Failed'; if (error.errors.containsKey('username')) { - errorMessage = error.errors['username']; + errorMessage = "Username: " + error.errors['username'].join('\n\n'); } else if (error.errors.containsKey('password')) { - errorMessage = error.errors['password']; + errorMessage = "Password: " + error.errors['password'].join('\n\n'); } else if (error.errors.containsKey('detail')) { 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); } setState(() { @@ -177,8 +183,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( @@ -188,6 +196,7 @@ class _AuthCardState extends State { children: [ TextFormField( decoration: InputDecoration(labelText: 'Username'), + controller: _usernameController, textInputAction: TextInputAction.next, keyboardType: TextInputType.emailAddress, validator: (value) { @@ -203,6 +212,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) { @@ -232,22 +242,10 @@ class _AuthCardState extends State { _authData['password'] = value; }, ), - TextFormField( - decoration: InputDecoration(labelText: 'Server Url'), - initialValue: 'http://10.0.2.2:8000', - 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'), + controller: _password2Controller, enabled: _authMode == AuthMode.Signup, obscureText: true, validator: _authMode == AuthMode.Signup @@ -259,6 +257,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, ), diff --git a/pubspec.yaml b/pubspec.yaml index ad9357295..c1f287904 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,7 +40,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 @@ -71,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