You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
303 lines
13 KiB
303 lines
13 KiB
1 year ago
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter/services.dart';
|
||
1 year ago
|
import 'package:healthcare_user/common/dashboard.dart';
|
||
|
import 'package:healthcare_user/common/settings.dart';
|
||
|
import 'package:healthcare_user/common/signup.dart';
|
||
1 year ago
|
import 'package:path/path.dart' as Path;
|
||
|
|
||
|
class Login extends StatefulWidget {
|
||
|
const Login({super.key});
|
||
|
|
||
|
@override
|
||
|
State<Login> createState() => _LoginState();
|
||
|
}
|
||
|
|
||
|
class _LoginState extends State<Login> {
|
||
|
|
||
|
bool isObscureText=true;
|
||
|
TextEditingController mobileNumberController = TextEditingController();
|
||
|
TextEditingController passwordController = TextEditingController();
|
||
|
|
||
|
|
||
|
@override
|
||
|
void initState() {
|
||
|
isObscureText=true;
|
||
|
super.initState();
|
||
|
}
|
||
|
|
||
|
Future<bool> onWillPop() async {
|
||
|
final shouldPop = await showDialog<bool>(context: context, builder: (context) {
|
||
|
return AlertDialog(
|
||
|
title: const Text('Do you want to exit app?',
|
||
|
style: TextStyle(
|
||
|
color: primaryColor,
|
||
|
fontSize: 20,
|
||
|
)),
|
||
|
actionsAlignment: MainAxisAlignment.spaceBetween,
|
||
|
actions: [
|
||
|
TextButton(
|
||
|
onPressed: () {
|
||
|
SystemNavigator.pop();
|
||
|
},
|
||
|
child: const Text('Yes',
|
||
|
style: TextStyle(
|
||
|
color: primaryColor,
|
||
|
fontSize: 20,
|
||
|
)),
|
||
|
),
|
||
|
TextButton(
|
||
|
onPressed: () {
|
||
|
Navigator.of(context).pop(false);
|
||
|
},
|
||
|
child: const Text('No',
|
||
|
style: TextStyle(
|
||
|
color: primaryColor,
|
||
|
fontSize: 20,
|
||
|
)),
|
||
|
),
|
||
|
],
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
return shouldPop!;
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
String lastInputValue="";
|
||
|
|
||
|
return WillPopScope(
|
||
|
onWillPop: () async => onWillPop(),
|
||
|
child: Scaffold(
|
||
|
|
||
|
body: Stack(
|
||
|
children: <Widget>[
|
||
|
Container(
|
||
|
decoration: const BoxDecoration(
|
||
|
image: DecorationImage(image: AssetImage("images/background.png"), fit: BoxFit.cover,),
|
||
|
),
|
||
|
),
|
||
|
GestureDetector(
|
||
|
onTap: () {
|
||
|
FocusManager.instance.primaryFocus?.unfocus();
|
||
|
},
|
||
|
child: SafeArea(
|
||
|
child: SingleChildScrollView(
|
||
|
child: Padding(
|
||
|
padding: const EdgeInsets.all(10),
|
||
|
child: Column(
|
||
|
children: <Widget>[
|
||
|
const SizedBox(
|
||
|
height: 15,
|
||
|
),
|
||
|
Container(
|
||
|
//width: double.infinity,
|
||
|
child: Image(
|
||
|
image: const AssetImage('images/logo.png'),
|
||
|
height: MediaQuery.of(context).size.height * .25,
|
||
|
)),
|
||
|
const SizedBox(
|
||
|
height: 15,
|
||
|
),
|
||
|
Container(
|
||
|
padding: const EdgeInsets.all(10),
|
||
|
child: TextFormField(
|
||
|
cursorColor: greyColor,
|
||
|
controller: mobileNumberController,
|
||
|
keyboardType: TextInputType.number,
|
||
|
decoration: const InputDecoration(
|
||
|
prefixIcon: Icon(
|
||
|
Icons.phone,
|
||
|
color: greyColor,
|
||
|
),
|
||
|
border: OutlineInputBorder(
|
||
|
borderSide: BorderSide(color: primaryColor)),
|
||
|
focusedBorder: OutlineInputBorder(
|
||
|
borderSide: BorderSide(color:primaryColor),
|
||
|
),
|
||
|
enabledBorder: OutlineInputBorder(
|
||
|
borderSide: BorderSide(color: primaryColor),
|
||
|
),
|
||
|
labelText: 'Enter MobileNumber',
|
||
|
labelStyle: TextStyle(
|
||
|
color: greyColor, //<-- SEE HERE
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
const SizedBox(
|
||
|
height: 15,
|
||
|
),
|
||
|
|
||
|
Container(
|
||
|
padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
|
||
|
child: TextFormField(
|
||
|
cursorColor: greyColor,
|
||
|
obscureText: isObscureText,
|
||
|
controller: passwordController,
|
||
|
decoration: InputDecoration(
|
||
|
labelText: 'Password',
|
||
|
prefixIcon: const Icon(Icons.password, color: greyColor,),
|
||
|
labelStyle: const TextStyle(
|
||
|
color: greyColor, //<-- SEE HERE
|
||
|
),
|
||
|
border: const OutlineInputBorder(
|
||
|
borderSide: BorderSide(color: primaryColor)),
|
||
|
focusedBorder: const OutlineInputBorder(
|
||
|
borderSide: BorderSide(color: primaryColor),
|
||
|
),
|
||
|
enabledBorder: const OutlineInputBorder(
|
||
|
borderSide: BorderSide(color: primaryColor),
|
||
|
),
|
||
|
suffixIcon: IconButton(
|
||
|
icon: Icon(
|
||
|
Icons.visibility_off_outlined,
|
||
|
color: isObscureText==true?greyColor:primaryColor,
|
||
|
),
|
||
|
onPressed: () {
|
||
|
|
||
|
print("show password");
|
||
|
setState(() {
|
||
|
isObscureText = !isObscureText;
|
||
|
});
|
||
|
},
|
||
|
),
|
||
|
|
||
|
),
|
||
|
|
||
|
),
|
||
|
),
|
||
|
Padding(padding: const EdgeInsets.fromLTRB(220, 10, 0,10),
|
||
|
child: TextButton(
|
||
|
onPressed: () {
|
||
|
/*Navigator.push(
|
||
|
context,
|
||
|
MaterialPageRoute(builder: (context) => OtpScreen()),
|
||
|
);*/
|
||
|
},
|
||
|
child: const Text(
|
||
|
'Forgot Password?',
|
||
|
style: TextStyle(
|
||
|
color: greyColor,
|
||
|
fontSize: 15,
|
||
|
decoration: TextDecoration.underline,
|
||
|
|
||
|
),
|
||
|
),
|
||
|
),),
|
||
|
Container(
|
||
|
width: 400,
|
||
|
height: 50,
|
||
|
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
||
|
child: ElevatedButton(
|
||
|
style: ElevatedButton.styleFrom(
|
||
|
primary: primaryColor, // background
|
||
|
onPrimary: Colors.white, // foreground
|
||
|
),
|
||
|
onPressed: () async{
|
||
|
|
||
|
if (mobileNumberController.text != '' ||
|
||
|
passwordController.text != '') {
|
||
|
AppSettings.preLoaderDialog(context);
|
||
|
|
||
|
bool isOnline = await AppSettings.internetConnectivity();
|
||
|
|
||
|
if(isOnline){
|
||
|
var payload = new Map<String, dynamic>();
|
||
|
payload["phone"] = mobileNumberController.text.toString();
|
||
|
payload["password"] = passwordController.text.toString();
|
||
|
|
||
|
bool signinStatus = await AppSettings.login(payload);
|
||
|
|
||
|
try{
|
||
|
if (signinStatus) {
|
||
|
Navigator.of(context,rootNavigator: true).pop();
|
||
|
|
||
|
await Navigator.push(
|
||
|
context,
|
||
|
MaterialPageRoute(
|
||
|
builder: (context) => const Dashboard()),
|
||
|
);
|
||
1 year ago
|
AppSettings.longSuccessToast("Logged in Successfully");
|
||
1 year ago
|
mobileNumberController.text='';
|
||
|
passwordController.text='';
|
||
|
|
||
|
} else {
|
||
|
Navigator.of(context,rootNavigator: true).pop();
|
||
1 year ago
|
AppSettings.longFailedToast("Please enter valid details");
|
||
1 year ago
|
}
|
||
|
}
|
||
|
catch(exception){
|
||
|
Navigator.of(context,rootNavigator: true).pop();
|
||
|
print(exception);
|
||
|
}
|
||
|
}
|
||
|
else{
|
||
|
Navigator.of(context,rootNavigator: true).pop();
|
||
1 year ago
|
AppSettings.longFailedToast("Please Check internet");
|
||
1 year ago
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
else{
|
||
|
|
||
1 year ago
|
AppSettings.longFailedToast("Please enter valid details");
|
||
1 year ago
|
}
|
||
|
|
||
|
},
|
||
|
child: const Text('Login'),
|
||
|
)),
|
||
|
Padding(padding: const EdgeInsets.fromLTRB(10, 10,10,10),
|
||
|
child: Row(
|
||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||
|
children: <Widget>[
|
||
|
const Text(
|
||
|
'Not a Member Yet?',
|
||
|
style: TextStyle(
|
||
|
color: primaryColor,
|
||
|
),
|
||
|
),
|
||
|
TextButton(
|
||
|
child: const Text(
|
||
|
'Sign Up',
|
||
|
style: TextStyle(fontSize: 15,
|
||
|
decoration: TextDecoration.underline,color: greyColor),
|
||
|
),
|
||
|
onPressed: () {
|
||
|
Navigator.push(
|
||
|
context,
|
||
|
MaterialPageRoute(
|
||
|
builder: (context) => const SignUp()),
|
||
|
);
|
||
|
//signup screen
|
||
|
},
|
||
|
)
|
||
|
],
|
||
|
),)
|
||
|
],
|
||
|
),
|
||
|
)
|
||
|
)),
|
||
|
),
|
||
|
],
|
||
|
)
|
||
|
/*bottomNavigationBar: Container(
|
||
|
padding: EdgeInsets.only(bottom: 13),
|
||
|
height: 38,
|
||
|
child: Column(
|
||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||
|
children: [
|
||
|
Container(
|
||
|
child: Image(
|
||
|
image: AssetImage('images/logo_btm.png'),
|
||
|
width: 90,
|
||
|
)),
|
||
|
],
|
||
|
),
|
||
|
),*/
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|