diff options
author | Marvin Borner | 2018-07-21 17:59:36 +0200 |
---|---|---|
committer | Marvin Borner | 2018-07-21 17:59:36 +0200 |
commit | f03f214a47a78a52d73e28a76eec78d3f10d07e5 (patch) | |
tree | eaaf280fa5b89d32018236e06e1fc22220b8fa80 /lib/screens | |
parent | acc5d5e9e960db9525a4368b393cb97fab8658e7 (diff) |
Rewritten login activity
Diffstat (limited to 'lib/screens')
-rw-r--r-- | lib/screens/home/home_screen.dart | 14 | ||||
-rw-r--r-- | lib/screens/login/login_screen.dart | 141 | ||||
-rw-r--r-- | lib/screens/login/login_screen_presenter.dart | 19 |
3 files changed, 0 insertions, 174 deletions
diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart deleted file mode 100644 index 46acd22..0000000 --- a/lib/screens/home/home_screen.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:flutter/material.dart'; - -class HomeScreen extends StatelessWidget { - @override - Widget build(BuildContext context) { - return new Scaffold( - appBar: new AppBar(title: new Text("Home"),), - body: new Center( - child: new Text("Welcome home!"), - ), - ); - } - -}
\ No newline at end of file diff --git a/lib/screens/login/login_screen.dart b/lib/screens/login/login_screen.dart deleted file mode 100644 index 7c8845e..0000000 --- a/lib/screens/login/login_screen.dart +++ /dev/null @@ -1,141 +0,0 @@ -import 'dart:ui'; - -import 'package:flutter/material.dart'; -import 'package:beam_messenger/auth.dart'; -import 'package:beam_messenger/data/database_helper.dart'; -import 'package:beam_messenger/models/user.dart'; -import 'package:beam_messenger/screens/login/login_screen_presenter.dart'; - -class LoginScreen extends StatefulWidget { - @override - State<StatefulWidget> createState() { - return new LoginScreenState(); - } -} - -class LoginScreenState extends State<LoginScreen> - implements LoginScreenContract, AuthStateListener { - BuildContext _ctx; - - bool _isLoading = false; - final formKey = new GlobalKey<FormState>(); - final scaffoldKey = new GlobalKey<ScaffoldState>(); - String _password, _email; - - LoginScreenPresenter _presenter; - - LoginScreenState() { - _presenter = new LoginScreenPresenter(this); - var authStateProvider = new AuthStateProvider(); - authStateProvider.subscribe(this); - } - - void _submit() { - final form = formKey.currentState; - - if (form.validate()) { - setState(() => _isLoading = true); - form.save(); - _presenter.doLogin(_email, _password); - } - } - - void _showSnackBar(String text) { - scaffoldKey.currentState - .showSnackBar(new SnackBar(content: new Text(text))); - } - - @override - onAuthStateChanged(AuthState state) { - if (state == AuthState.LOGGED_IN) - Navigator.of(_ctx).pushReplacementNamed("/home"); - } - - @override - Widget build(BuildContext context) { - _ctx = context; - var loginBtn = new RaisedButton( - onPressed: _submit, - child: new Text("LOGIN"), - color: Colors.primaries[0], - ); - var loginForm = new Column( - children: <Widget>[ - new Text( - "Login", - textScaleFactor: 2.0, - ), - new Form( - key: formKey, - child: new Column( - children: <Widget>[ - new Padding( - padding: const EdgeInsets.all(8.0), - child: new TextFormField( - onSaved: (val) => _email = val, - validator: (val) { - return val.length < 10 - ? "email must have atleast 10 chars" - : null; - }, - decoration: new InputDecoration(labelText: "email"), - ), - ), - new Padding( - padding: const EdgeInsets.all(8.0), - child: new TextFormField( - onSaved: (val) => _password = val, - decoration: new InputDecoration(labelText: "Password"), - ), - ), - ], - ), - ), - _isLoading ? new CircularProgressIndicator() : loginBtn - ], - crossAxisAlignment: CrossAxisAlignment.center, - ); - - return new Scaffold( - appBar: null, - key: scaffoldKey, - body: new Container( - decoration: new BoxDecoration( - image: new DecorationImage( - image: new AssetImage("assets/login_background.jpg"), - fit: BoxFit.cover), - ), - child: new Center( - child: new ClipRect( - child: new BackdropFilter( - filter: new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0), - child: new Container( - child: loginForm, - height: 300.0, - width: 300.0, - decoration: new BoxDecoration( - color: Colors.grey.shade200.withOpacity(0.5)), - ), - ), - ), - ), - ), - ); - } - - @override - void onLoginError(String errorTxt) { - _showSnackBar(errorTxt); - setState(() => _isLoading = false); - } - - @override - void onLoginSuccess(User user) async { - _showSnackBar(user.toString()); - setState(() => _isLoading = false); - var db = new DatabaseHelper(); - await db.saveUser(user); - var authStateProvider = new AuthStateProvider(); - authStateProvider.notify(AuthState.LOGGED_IN); - } -} diff --git a/lib/screens/login/login_screen_presenter.dart b/lib/screens/login/login_screen_presenter.dart deleted file mode 100644 index fc5da4f..0000000 --- a/lib/screens/login/login_screen_presenter.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'package:beam_messenger/data/rest_ds.dart'; -import 'package:beam_messenger/models/user.dart'; - -abstract class LoginScreenContract { - void onLoginSuccess(User user); - void onLoginError(String errorTxt); -} - -class LoginScreenPresenter { - LoginScreenContract _view; - RestDatasource api = new RestDatasource(); - LoginScreenPresenter(this._view); - - doLogin(String email, String password) { - api.login(email, password).then((User user) { - _view.onLoginSuccess(user); - }).catchError((Exception error) => _view.onLoginError(error.toString())); - } -} |