2019-05-08 18:54:14 +00:00
|
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter/gestures.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:local_spend/common/apifunctions/request_login_api.dart';
|
|
|
|
import 'package:local_spend/common/functions/show_dialog_single_button.dart';
|
|
|
|
import 'package:local_spend/common/platform/platform_scaffold.dart';
|
|
|
|
import 'package:local_spend/common/widgets/basic_drawer.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
|
|
|
|
const URL = "https://flutter.io/";
|
|
|
|
|
|
|
|
class LoginPage extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return new LoginPageState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class LoginPageState extends State<LoginPage> {
|
|
|
|
final TextEditingController _emailController = TextEditingController();
|
|
|
|
final TextEditingController _passwordController = TextEditingController();
|
|
|
|
String _welcomeString = "";
|
2019-07-03 11:41:51 +00:00
|
|
|
FocusNode focusNode; // added so focus can move automatically
|
2019-05-08 18:54:14 +00:00
|
|
|
|
|
|
|
Future launchURL(String url) async {
|
|
|
|
if (await canLaunch(url)) {
|
|
|
|
await launch(url, forceSafariVC: true, forceWebView: true);
|
|
|
|
} else {
|
|
|
|
showDialogSingleButton(
|
|
|
|
context,
|
|
|
|
"Unable to reach your website.",
|
|
|
|
"Currently unable to reach the website $URL. Please try again at a later time.",
|
|
|
|
"OK");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_saveCurrentRoute("/LoginPage");
|
2019-07-03 11:41:51 +00:00
|
|
|
|
|
|
|
focusNode = FocusNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
focusNode.dispose(); //disposes focus node when form disposed
|
|
|
|
super.dispose();
|
2019-05-08 18:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_saveCurrentRoute(String lastRoute) async {
|
|
|
|
SharedPreferences preferences = await SharedPreferences.getInstance();
|
|
|
|
await preferences.setString('LastPageRoute', lastRoute);
|
|
|
|
}
|
|
|
|
|
2019-07-05 14:34:39 +00:00
|
|
|
void login(String username, String password) {
|
|
|
|
SystemChannels.textInput.invokeMethod('TextInput.hide');
|
|
|
|
requestLoginAPI(context, username,
|
|
|
|
password);
|
|
|
|
}
|
|
|
|
|
2019-05-08 18:54:14 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return WillPopScope(
|
|
|
|
onWillPop: () {
|
|
|
|
if (Navigator.canPop(context)) {
|
|
|
|
Navigator.of(context).pushNamedAndRemoveUntil(
|
|
|
|
'/HomePage', (Route<dynamic> route) => false);
|
|
|
|
} else {
|
|
|
|
Navigator.of(context).pushReplacementNamed('/HomePage');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: PlatformScaffold(
|
2019-07-05 12:39:24 +00:00
|
|
|
// drawer: BasicDrawer(),
|
2019-05-08 18:54:14 +00:00
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(
|
|
|
|
"LOGIN",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 30.0,
|
|
|
|
color: Colors.black,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
centerTitle: true,
|
|
|
|
iconTheme: IconThemeData(color: Colors.black),
|
|
|
|
),
|
|
|
|
body: Container(
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(30.0, 0.0, 30.0, 0.0),
|
|
|
|
child: ListView(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(0.0, 40.0, 0.0, 15.0),
|
|
|
|
child: Text(
|
|
|
|
"Local Loop",
|
|
|
|
style: TextStyle(fontSize: 40.0, color: Colors.black),
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 78.0),
|
|
|
|
child: RichText(
|
|
|
|
text: TextSpan(
|
|
|
|
children: [
|
|
|
|
TextSpan(
|
|
|
|
text:
|
|
|
|
'This is the logon page.',
|
|
|
|
style: new TextStyle(
|
|
|
|
fontSize: 20.0,
|
|
|
|
color: Colors.black,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
TextSpan(
|
|
|
|
text:
|
|
|
|
' It is currently in development.',
|
|
|
|
style: new TextStyle(
|
|
|
|
fontSize: 20.0,
|
|
|
|
color: Colors.black,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"Email",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 18.0,
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 0.0),
|
|
|
|
child: TextField(
|
|
|
|
controller: _emailController,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: "Use your login email",
|
|
|
|
),
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 18.0,
|
2019-05-16 16:04:08 +00:00
|
|
|
color: Colors.grey[800],
|
2019-05-08 18:54:14 +00:00
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2019-07-03 11:41:51 +00:00
|
|
|
onSubmitted: (_) {
|
|
|
|
FocusScope.of(context).requestFocus(focusNode);
|
|
|
|
},
|
2019-05-08 18:54:14 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(0.0, 35.0, 0.0, 0.0),
|
|
|
|
child: Text(
|
|
|
|
"Password",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 18.0,
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(0.0, 5.0, 0.0, 0.0),
|
|
|
|
child: TextField(
|
|
|
|
controller: _passwordController,
|
2019-07-03 11:41:51 +00:00
|
|
|
focusNode: focusNode,
|
2019-05-08 18:54:14 +00:00
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: 'Your password, keep it secret, keep it safe.',
|
|
|
|
),
|
|
|
|
obscureText: true,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 18.0,
|
2019-05-16 16:04:08 +00:00
|
|
|
color: Colors.grey[800],
|
2019-05-08 18:54:14 +00:00
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2019-07-03 10:21:53 +00:00
|
|
|
onSubmitted: (_) {
|
2019-07-05 14:34:39 +00:00
|
|
|
login( _emailController.text,
|
2019-07-03 10:21:53 +00:00
|
|
|
_passwordController.text);
|
|
|
|
},
|
2019-05-08 18:54:14 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(0.0, 70.0, 0.0, 0.0),
|
|
|
|
child: Container(
|
|
|
|
height: 65.0,
|
|
|
|
child: RaisedButton(
|
|
|
|
onPressed: () {
|
2019-07-05 14:34:39 +00:00
|
|
|
login( _emailController.text,
|
2019-05-08 18:54:14 +00:00
|
|
|
_passwordController.text);
|
2019-07-03 10:21:53 +00:00
|
|
|
// showDialog(
|
|
|
|
// barrierDismissible: false,
|
|
|
|
// );
|
|
|
|
// print("pressed");
|
2019-05-08 18:54:14 +00:00
|
|
|
},
|
|
|
|
child: Text("LOGIN",
|
|
|
|
style:
|
|
|
|
TextStyle(color: Colors.white, fontSize: 22.0)),
|
|
|
|
color: Colors.blue,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|