4
2
Fork 0

feat: implementing login persistence

pull/55/head
Sudharshan S. 2019-05-26 14:45:17 +08:00
parent 2b3891f2fe
commit 5f3967c065
Signed by: sudharshan
GPG Key ID: C861C97AAF3D9559
4 changed files with 41 additions and 15 deletions

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'src/ui/home/home.dart';
import "src/ui/login/welcome.dart";
import "src/services/login_manager.dart";
import 'themer.dart';
class Routes {
@ -11,13 +12,30 @@ class Routes {
};
final theme = buildTheme();
final loginManager = LoginManager();
Routes() {
runApp(MaterialApp(
title: "Beep",
theme: theme,
routes: routes,
home: Welcome(),
));
checkIfLogin();
}
checkIfLogin() async {
final authToken = await loginManager.getToken();
print(authToken);
if (authToken != "") {
runApp(MaterialApp(
title: "Beep",
theme: theme,
routes: routes,
home: Home(),
));
} else {
runApp(MaterialApp(
title: "Beep",
theme: theme,
routes: routes,
home: Welcome(),
));
}
}
}

View File

@ -1,6 +1,7 @@
import "package:flutter/material.dart";
import "../../services/login_manager.dart";
import "../../services/conversation_manager.dart";
import "./widgets/welcome_page.dart";
import "./widgets/login_page.dart";
import "./widgets/otp_page.dart";
@ -50,7 +51,9 @@ class Welcome extends StatelessWidget {
case "welcome/otp":
builder = (BuildContext _) =>
OtpPage(buttonCallback: (String otp) async {
// loginManager.processOtp(otp); disabled for testing
final authToken = await loginManager.processOtp(otp);
await ConversationManager.init(authToken);
Navigator.of(context).pushReplacementNamed("/home");
});
break;

View File

@ -3,7 +3,6 @@ import "package:flutter_svg/flutter_svg.dart";
import "../../widgets/text_button.dart";
import "../../../services/login_manager.dart";
import "../../../services/conversation_manager.dart";
import "phone_input.dart";
class LoginPage extends StatefulWidget {
@ -55,13 +54,9 @@ class _LoginPageState extends State<LoginPage> {
TextButton(
text: "Continue",
onClickCallback: () async {
final authToken =
await widget.loginManager.loginTest(controller.text);
// Waiting for initialization
await ConversationManager.init(authToken);
print(authToken);
print(await widget.loginManager.getToken());
await widget.loginManager
.initAuthentication("+65${controller.text}");
Navigator.pushNamed(context, 'welcome/otp');
}),
]));

View File

@ -47,8 +47,18 @@ class _OtpPageState extends State<OtpPage> {
child: Center(
child: PinCodeTextField(
controller: controller,
maxLength: 6,
highlight: true,
autofocus: true,
highlightColor: Colors.white,
onTextChanged: (text) {},
onDone: (text) {
widget.buttonCallback(text);
},
pinBoxHeight:
(MediaQuery.of(context).size.width / 6) - 15,
pinBoxWidth:
(MediaQuery.of(context).size.width / 6) - 15,
/*hideCharacter: true,*/
pinBoxDecoration: (Color color) {
return BoxDecoration(