You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
6.2 KiB
Dart
169 lines
6.2 KiB
Dart
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:hmg_nurses/classes/colors.dart';
|
|
import 'package:hmg_nurses/classes/enums.dart';
|
|
import 'package:hmg_nurses/classes/utils.dart';
|
|
import 'package:hmg_nurses/config/routes.dart';
|
|
import 'package:hmg_nurses/extensions/int_extensions.dart';
|
|
import 'package:hmg_nurses/generated/locale_keys.g.dart';
|
|
import 'package:hmg_nurses/model/login/imei_details_model.dart';
|
|
import 'package:hmg_nurses/model/login/project_info_model.dart';
|
|
import 'package:hmg_nurses/provider/login_provider_model.dart';
|
|
import 'package:hmg_nurses/widgets/button/default_button.dart';
|
|
import 'package:hmg_nurses/widgets/cupertino_picker.dart';
|
|
import 'package:hmg_nurses/widgets/input_widget.dart';
|
|
import 'package:injector/injector.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:sizer/sizer.dart';
|
|
|
|
import '../../services/api_repo/login_api_repo.dart';
|
|
|
|
class LoginPage extends StatefulWidget {
|
|
const LoginPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<LoginPage> createState() => _LoginPageState();
|
|
}
|
|
|
|
class _LoginPageState extends State<LoginPage> {
|
|
final ILoginApiRepo _loginApiRepo = Injector.appInstance.get<ILoginApiRepo>();
|
|
|
|
int branchID=0;
|
|
|
|
final loginFormKey = GlobalKey<FormState>();
|
|
var projectIdController = TextEditingController();
|
|
var userIdController = TextEditingController();
|
|
var passwordController = TextEditingController();
|
|
|
|
SizedBox buildSpacer20h() => SizedBox(height: 3.h);
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
checkLastSession();
|
|
}
|
|
|
|
checkLastSession() async {
|
|
try {
|
|
Utils.showLoading();
|
|
List<GetIMEIDetailsModel> deviceInfo = await _loginApiRepo.getDeviceInfoByIMEI();
|
|
Utils.showToast(deviceInfo.length.toString());
|
|
Utils.showLoading();
|
|
} catch (e) {}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final provider = Provider.of<LoginProviderModel>(context);
|
|
return Scaffold(
|
|
body: SingleChildScrollView(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
SizedBox(height: 10.h),
|
|
Padding(
|
|
padding: EdgeInsets.only(left: 8.w),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
LocaleKeys.welcomeTo.tr(),
|
|
style: TextStyle(fontSize: 16.sp, fontWeight: FontWeight.w600, fontFamily: 'Poppins'),
|
|
),
|
|
Text(
|
|
LocaleKeys.drSulaiman.tr(),
|
|
style: TextStyle(color: MyColors.blackColor, fontWeight: FontWeight.bold, fontSize: 24.sp, fontFamily: 'Poppins'),
|
|
),
|
|
Text(
|
|
"Nurses App",
|
|
style: TextStyle(fontSize: 16.sp, fontWeight: FontWeight.w600, color: MyColors.redColor),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(height: 4.h),
|
|
Form(
|
|
key: loginFormKey,
|
|
child: Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 8.w),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
buildSpacer20h(),
|
|
CustomTextField(
|
|
LocaleKeys.userID.tr(),
|
|
userIdController,
|
|
isEnableBorder: true,
|
|
),
|
|
buildSpacer20h(),
|
|
CustomTextField(
|
|
LocaleKeys.password.tr(),
|
|
passwordController,
|
|
isTextIsPassword: true,
|
|
onChange: (v) {
|
|
if (v.length > 0) {
|
|
provider.getAssignedBranches(userIdController.text);
|
|
}
|
|
},
|
|
),
|
|
buildSpacer20h(),
|
|
Consumer<LoginProviderModel>(
|
|
builder: (_, data, w) {
|
|
return data.state == ViewState.hide
|
|
? Container()
|
|
: data.state == ViewState.busy
|
|
? const Center(child: CircularProgressIndicator())
|
|
: CustomTextField(
|
|
LocaleKeys.branch.tr(),
|
|
projectIdController,
|
|
hasSelection: true,
|
|
isEnable: false,
|
|
onClick: () => CustomCupertinoPicker.showCupertinoPicker(
|
|
context,
|
|
provider.assignedBranches,
|
|
(index) {
|
|
projectIdController.text=provider.assignedBranches[index].facilityName!;
|
|
branchID=provider.assignedBranches[index].facilityId as int;
|
|
print(branchID);
|
|
provider.notifyListeners();
|
|
},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
buildSpacer20h(),
|
|
SizedBox(
|
|
height: 12.h,
|
|
),
|
|
]),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
bottomSheet: Container(
|
|
height: 12.h,
|
|
color: MyColors.backgroundColor,
|
|
width: double.infinity,
|
|
child: Center(
|
|
child: FractionallySizedBox(
|
|
widthFactor: 0.9,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 4.w),
|
|
child: DefaultButton(LocaleKeys.login.tr(), () {
|
|
Navigator.pushNamed(context, AppRoutes.loginMethodsPage);
|
|
}, colors: const [MyColors.redColor, MyColors.redColor]),
|
|
),
|
|
SizedBox(
|
|
height: 3.h,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|