171 lines
7.6 KiB
Dart
171 lines
7.6 KiB
Dart
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:gap/gap.dart';
|
|
import 'package:tanami_app/core/styles/app_text.dart';
|
|
import 'package:tanami_app/features/countrySelection/bloc/GetCountry/getcountryevent_bloc.dart';
|
|
|
|
import '../../../../Globalconst.dart';
|
|
import '../../../../core/utils/language/localizations_delegate.dart';
|
|
import '../../../../shared/api/api_endpoints.dart';
|
|
import '../../../../shared/components/form_label_textfield.dart';
|
|
import '../../../countrySelection/bloc/GetCountry/getcountry_bloc.dart';
|
|
import '../../../countrySelection/bloc/choose_country_bloc.dart';
|
|
import '../../../countrySelection/bloc/choose_country_state.dart';
|
|
import '../bloc/register_bloc.dart';
|
|
|
|
class RegisterForm extends StatelessWidget {
|
|
const RegisterForm({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var localizations = AppLocalizations.of(context);
|
|
final loginBloc = context.read<RegisterBloc>();
|
|
final countrydata = context.read<GetCountryBlock>();
|
|
int selectedCountry = -1;
|
|
String flag = "";
|
|
return BlocConsumer<RadioBloc, RadioState>(listener: (context, state) {
|
|
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.isdcode="${countryState.countryModel.data![selectedCountry].isdCode}";
|
|
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) {
|
|
if (state is RadioSelectionChanged) {
|
|
selectedCountry = state.selectedIndex;
|
|
} else {
|
|
selectedCountry = -1;
|
|
}
|
|
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
|
|
: Padding(
|
|
padding: EdgeInsets.only(left: 12.w),
|
|
child: SizedBox(
|
|
height: 50.h,
|
|
width: 30.w,
|
|
child: Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: SizedBox(
|
|
height: 30.h,
|
|
width: 30.w,
|
|
child: ClipRRect(
|
|
borderRadius:
|
|
BorderRadius.all(Radius.circular(100)),
|
|
child: CachedNetworkImage(
|
|
maxHeightDiskCache: 200,
|
|
maxWidthDiskCache: 200,
|
|
cacheKey: loginBloc
|
|
.countrySelectionTextField.text,
|
|
key: UniqueKey(),
|
|
imageUrl: flag,
|
|
height: 30.h,
|
|
width: 30.w,
|
|
placeholder: (context, url) => Container(
|
|
height: 30.h,
|
|
width: 30.w,
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
errorWidget: (context, url, error) =>
|
|
Icon(Icons.error),
|
|
fit: BoxFit.cover),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
/* 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 ||flag.isEmpty
|
|
? null
|
|
: Padding(
|
|
padding: EdgeInsets.only(left: 12.w),
|
|
child: SizedBox(
|
|
height: 50.h,
|
|
width: 30.w,
|
|
child: Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: SizedBox(
|
|
height: 30.h,
|
|
width: 30.w,
|
|
child: ClipRRect(
|
|
borderRadius:
|
|
BorderRadius.all(Radius.circular(100)),
|
|
child: CachedNetworkImage(
|
|
maxHeightDiskCache: 200,
|
|
maxWidthDiskCache: 200,
|
|
cacheKey: loginBloc
|
|
.countrySelectionTextField.text,
|
|
key: UniqueKey(),
|
|
imageUrl: flag,
|
|
height: 30.h,
|
|
width: 30.w,
|
|
placeholder: (context, url) => Container(
|
|
height: 30.h,
|
|
width: 30.w,
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
errorWidget: (context, url, error) =>
|
|
Icon(Icons.error),
|
|
fit: BoxFit.cover),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),/* 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,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
}
|