Documentation, Basic Login Workflow
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:fluro/fluro.dart';
|
||||
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
|
||||
import 'package:imagini/blocs/login_bloc.dart';
|
||||
import 'package:imagini/core/app_provider.dart';
|
||||
|
||||
class LoginScreen extends StatefulWidget {
|
||||
static const String PATH = '/Login';
|
||||
static const String PATH = '/';
|
||||
|
||||
LoginScreen({Key key}) : super(key: key);
|
||||
|
||||
@@ -16,7 +17,7 @@ class LoginScreen extends StatefulWidget {
|
||||
|
||||
class _LoginScreenState extends State<LoginScreen> {
|
||||
|
||||
// LoginBloc bloc;
|
||||
LoginBloc bloc;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
@@ -29,12 +30,76 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
_init();
|
||||
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: 500),
|
||||
child: Container(
|
||||
margin: EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
height: 500,
|
||||
body: StreamBuilder<bool>(
|
||||
stream: bloc.authenticatedResult,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.data == null || snapshot.data == true)
|
||||
return _appLoading();
|
||||
return _appLogin();
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
void _init(){
|
||||
if(bloc != null){
|
||||
return;
|
||||
}
|
||||
|
||||
bloc = LoginBloc(AppProvider.getApplication(context));
|
||||
bloc.authenticatedResult.listen((bool status) {
|
||||
if (status)
|
||||
AppProvider.getRouter(context).navigateTo(context, "/Home", transition: TransitionType.fadeIn);
|
||||
});
|
||||
|
||||
bloc.loginResult.listen((bool status) {
|
||||
if (status == null || status == false)
|
||||
return;
|
||||
|
||||
AppProvider.getRouter(context).navigateTo(context, "/Home", transition: TransitionType.fadeIn);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _appLoading(){
|
||||
return Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: 500),
|
||||
child: Container(
|
||||
margin: EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
height: 270,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.contain,
|
||||
child: const FlutterLogo(),
|
||||
),
|
||||
width: 175,
|
||||
margin: EdgeInsets.fromLTRB(0, 0, 0, 50),
|
||||
),
|
||||
PlatformCircularProgressIndicator()
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _appLogin(){
|
||||
TextEditingController serverController = new TextEditingController();
|
||||
TextEditingController userController = new TextEditingController();
|
||||
TextEditingController passwordController = new TextEditingController();
|
||||
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
return Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: 500),
|
||||
child: Container(
|
||||
margin: EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
height: 500,
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
@@ -46,24 +111,45 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
margin: EdgeInsets.fromLTRB(0, 0, 0, 50),
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
child: TextFormField(
|
||||
controller: serverController,
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return 'Please enter server address';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Server Address'
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
child: TextFormField(
|
||||
controller: userController,
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return 'Please enter username or email';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Username / Email'
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
child: TextFormField(
|
||||
obscureText: true,
|
||||
enableSuggestions: false,
|
||||
autocorrect: false,
|
||||
controller: passwordController,
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return 'Please enter password';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Password'
|
||||
),
|
||||
@@ -73,11 +159,31 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
width: double.infinity,
|
||||
child: PlatformButton(
|
||||
onPressed: () {
|
||||
AppProvider.getRouter(context).navigateTo(context, "/Home", transition: TransitionType.fadeIn);
|
||||
if (!_formKey.currentState.validate())
|
||||
return;
|
||||
bloc.attemptLogin(userController.text, passwordController.text, serverController.text);
|
||||
},
|
||||
child: Text('Login')
|
||||
),
|
||||
),
|
||||
|
||||
StreamBuilder<bool>(
|
||||
stream: bloc.loginResult,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.data == null || snapshot.data == true)
|
||||
return Container();
|
||||
|
||||
return Expanded(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 20, 20, 20),
|
||||
child: Text(
|
||||
"Login Failed",
|
||||
style: TextStyle(color: Colors.red),
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -85,10 +191,4 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _init(){
|
||||
// if(null == bloc){
|
||||
// bloc = LoginBloc(AppProvider.getApplication(context));
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
import 'package:fluro/fluro.dart';
|
||||
|
||||
import 'package:imagini/core/app_provider.dart';
|
||||
import 'package:imagini/blocs/splash_bloc.dart';
|
||||
import 'package:imagini/graphql/imagini_graphql.dart';
|
||||
|
||||
class SplashScreen extends StatefulWidget {
|
||||
static const String PATH = '/';
|
||||
|
||||
SplashScreen({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_SplashScreenState createState() => _SplashScreenState();
|
||||
}
|
||||
|
||||
class _SplashScreenState extends State<SplashScreen> {
|
||||
|
||||
SplashBloc bloc;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
bloc.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_init();
|
||||
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: 500),
|
||||
child: Container(
|
||||
margin: EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
height: 270,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.contain,
|
||||
child: const FlutterLogo(),
|
||||
),
|
||||
width: 175,
|
||||
margin: EdgeInsets.fromLTRB(0, 0, 0, 50),
|
||||
),
|
||||
PlatformCircularProgressIndicator()
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _init(){
|
||||
if(null == bloc){
|
||||
bloc = SplashBloc(AppProvider.getApplication(context));
|
||||
bloc.loginResult.listen((Login$Query$AuthResponse lr) {
|
||||
if (lr.result == AuthResult.success) {
|
||||
AppProvider.getRouter(context).navigateTo(context, "/Home", transition: TransitionType.fadeIn);
|
||||
} else {
|
||||
AppProvider.getRouter(context).navigateTo(context, "/Login", transition: TransitionType.fadeIn);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user