Merge remote-tracking branch 'origin/master'

This commit is contained in:
Roland Geider
2020-12-01 18:29:29 +01:00
4 changed files with 59 additions and 48 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@@ -79,7 +79,7 @@ class Auth with ChangeNotifier {
});
prefs.setString('userData', userData);
} catch (error) {
throw HttpException(error.errors);
throw error;
}
}

View File

@@ -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: <Widget>[
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: <Widget>[
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<AuthCard> {
'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<AuthCard> {
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<AuthCard> {
),
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<AuthCard> {
children: <Widget>[
TextFormField(
decoration: InputDecoration(labelText: 'Username'),
controller: _usernameController,
textInputAction: TextInputAction.next,
keyboardType: TextInputType.emailAddress,
validator: (value) {
@@ -203,6 +212,7 @@ class _AuthCardState extends State<AuthCard> {
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<AuthCard> {
_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<AuthCard> {
}
: 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,
),

View File

@@ -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