117 lines
4.6 KiB
Dart
117 lines
4.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:gap/gap.dart';
|
|
import 'package:tanami_app/core/styles/app_text.dart';
|
|
import 'package:tanami_app/core/utils/constant/country_flag_data.dart';
|
|
|
|
import '../../../../Globalconst.dart';
|
|
import '../../../../core/utils/language/localizations_delegate.dart';
|
|
import '../../../../shared/api/api_endpoints.dart';
|
|
import '../../../../shared/components/bloc/password_field/password_visibility_bloc.dart';
|
|
import '../../../../shared/components/form_label_textfield.dart';
|
|
import '../../../countrySelection/bloc/GetCountry/get_country_bloc.dart';
|
|
import '../../../countrySelection/bloc/GetCountry/get_country_state.dart';
|
|
import '../../../countrySelection/bloc/choose_country_bloc.dart';
|
|
import '../../../countrySelection/bloc/choose_country_state.dart';
|
|
import '../bloc/login_bloc.dart';
|
|
|
|
class LoginForm extends StatelessWidget {
|
|
const LoginForm({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var localizations = AppLocalizations.of(context);
|
|
final loginBloc = context.read<LoginBloc>();
|
|
final countrydata = context.read<GetCountryBlock>();
|
|
|
|
String flag = "";
|
|
|
|
// Reset fields when the screen is built
|
|
loginBloc.resetFields();
|
|
|
|
return BlocConsumer<RadioBloc, RadioState>(listener: (context, state) {
|
|
int selectedCountry = -1;
|
|
if (state is RadioSelectionChanged) {
|
|
selectedCountry = state.selectedIndex;
|
|
final countryState = countrydata.state;
|
|
if (countryState is CountryLoaded) {
|
|
loginBloc.countrySelectionTextField.text = countryState
|
|
.countryModel.data![selectedCountry].countryName
|
|
.toString();
|
|
loginBloc.phoneNumberTextField.text =
|
|
"${countryState.countryModel.data![selectedCountry].isdCode}";
|
|
loginBloc.countryId="${countryState.countryModel.data![selectedCountry].id}";
|
|
flag =
|
|
"${ApiEndpoints.base}${countryState.countryModel.data![selectedCountry].flagIcon}";
|
|
Globalconst.phonenumber = loginBloc.phoneNumberTextField.text;
|
|
|
|
Globalconst.name = countryState
|
|
.countryModel.data![selectedCountry].countryName
|
|
.toString();
|
|
Globalconst.isdcode =
|
|
"${countryState.countryModel.data![selectedCountry].isdCode}";
|
|
}
|
|
}
|
|
}, builder: (context, state) {
|
|
int selectedCountry = -1;
|
|
if (state is RadioSelectionChanged) {
|
|
selectedCountry = state.selectedIndex;
|
|
}
|
|
return Form(
|
|
key: loginBloc.formKey,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 14,
|
|
),
|
|
child: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Gap(50),
|
|
FormLabelTextField(
|
|
prefixWidget: selectedCountry == -1
|
|
? null
|
|
: Image.asset(
|
|
countryFlag[selectedCountry],
|
|
width: 20,
|
|
height: 20,
|
|
),
|
|
hintText: localizations.translate(AppText.chooseCountry),
|
|
title: localizations.translate(AppText.countryOfResidence),
|
|
type: "country selection",
|
|
textEditingController: loginBloc.countrySelectionTextField,
|
|
),
|
|
const Gap(20),
|
|
FormLabelTextField(
|
|
prefixWidget: selectedCountry == -1
|
|
? null
|
|
: Image.asset(
|
|
countryFlag[selectedCountry],
|
|
width: 20,
|
|
height: 20,
|
|
),
|
|
hintText: "+0 (000) 000 00 00",
|
|
title: localizations.translate(AppText.phoneNumber),
|
|
type: "phone number",
|
|
textEditingController: loginBloc.phoneNumberTextField,
|
|
),
|
|
const Gap(20),
|
|
BlocProvider(
|
|
create: (_) => PasswordVisibilityBloc(),
|
|
child: FormLabelTextField(
|
|
hintText: localizations.translate(AppText.enterPassword),
|
|
title: localizations.translate(AppText.password),
|
|
type: "password",
|
|
textEditingController: loginBloc.passwordTextField,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
}
|