setConsentData method
Widget
setConsentData(
- ConsentFormResponse data,
- FrequencyResponse freqData,
- WidgetRef ref,
- LangResponse langResponse,
Implementation
Widget setConsentData(ConsentFormResponse data, FrequencyResponse freqData,
WidgetRef ref, LangResponse langResponse) {
errorFlags = List<bool>.filled(data.result!.data!.piiList!.length, false);
data.result!.data!.formConfiguration != null
? TITLE = data.result!.data!.formConfiguration!.formHeading!
: TITLE;
try {
// CustomTextStyle.initializeFontFamily(data.result!.data!.formConfiguration!.fontFamily!);
CustomTextStyle.initializeFontFamily("Lato");
} catch (e) {
print(e);
}
AppColor.appColor = AppColor.hexToColor(
data.result!.data!.formConfiguration!.backgroundHeaderColor!);
AppColor.apptitleandbuttontextcolor =
AppColor.hexToColor(data.result!.data!.formConfiguration!.fontColor!);
SharedPreferences.getInstance().then((prefs) {
prefs.setString('appColor', AppColor.colorToHex(AppColor.appColor!));
prefs.setString('apptitleandbuttontextcolor',
AppColor.colorToHex(AppColor.apptitleandbuttontextcolor!));
});
return Scaffold(
body: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(top: 8.0,left: 16,right: 16,bottom: 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
data.result!.data!.basicInfo!.title.toString(),
style: CustomTextStyle.heading2,
),
// const SizedBox(height: 0),
Text(
data.result!.data!.basicInfo!.description.toString(),
style: CustomTextStyle.subheading,
),
],
),
),
const SizedBox(height: 12),
// Second Section: TextFields
Padding(
padding:
const EdgeInsets.only(top: 0, left: 16, right: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
data.result!.data!.formConfiguration == null
? Text("dc")
: Text(
data.result!.data!.basicInfo!.piiInputHeading!,
style: CustomTextStyle.headinglightblack,
),
const SizedBox(height: 4),
Consumer(builder: (BuildContext context, WidgetRef ref, Widget? child) {
ref.watch(consentProvider2);
return ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: data.result!.data!.piiList?.length,
itemBuilder: (context, index) {
final TextEditingController controller =
TextEditingController();
bool isReadOnly = (data.result!.data!
.piiList![index].customerPiiLabelId ==
data.result!.data!.additionalInfo!
.subjectIdentityTypeId);
if (isReadOnly) {
controller.text = widget.sval ?? '';
data.result!.data!.piiList![index].val =
widget.sval;
} else {
controller.text =
data.result!.data!.piiList![index].val ?? '';
}
return Padding(
padding:
const EdgeInsets.symmetric(vertical: 4.0),
child: TextField(
onChanged: (val) {
data.result!.data!.piiList![index].val = val;
errorFlags[index] = val.isEmpty;
},
enabled: !isReadOnly,
controller: controller,
decoration: InputDecoration(
labelText:
'${data.result!.data!.piiList![index].customerPiiLabelName}',
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(vertical: 10, horizontal: 8),
errorText: errorFlags[index] ? 'This field is required' : null,
),
),
);
},
);
},),
],
),
),
const SizedBox(height: 12),
// Third Section: Expandable ListView
Padding(
padding: const EdgeInsets.only(top: 0, left: 16, right: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
data.result!.data!.basicInfo == null
? ""
: data.result!.data!.basicInfo!
.preferenceInputHeading!,
style: CustomTextStyle.headinglightblack,
),
const SizedBox(height: 4),
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: data.result!.data!.purposeList!.length,
itemBuilder: (context, purposeIndex) {
return Theme(
child: Card(
child: ExpansionTile(
title: Text(
data
.result!
.data!
.purposeList![purposeIndex]
.processingPurposeName!,
style: CustomTextStyle.heading2expendable,
),
children: [
ListView.builder(
shrinkWrap: true,
physics:
const NeverScrollableScrollPhysics(),
itemCount: data
.result!
.data!
.purposeList![purposeIndex]
.consentList!
.length,
itemBuilder: (context, consentIndex) {
final consent = data
.result!
.data!
.purposeList![purposeIndex]
.consentList![consentIndex];
return Padding(
padding: const EdgeInsets.only(left: 12,right: 12,bottom: 8),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start, // Center aligns the children vertically
children: [
Consumer(
builder: (BuildContext context,
WidgetRef ref,
Widget? child) {
ref.watch(consentProvider);
return IgnorePointer(
ignoring: consent
.compulsoryConsent!,
child: Padding(
padding: const EdgeInsets.only(top:3.0),
child: SizedBox(
child: Checkbox(
value:
consent.isChecked!,
onChanged: (value) {
ref
.read(
consentProvider
.notifier)
.toggleConsentStatus(
consent,
value!);
},
),
height: 24,
width: 24,
),
),
);
},
),
SizedBox(width: 4,),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 0.0),
child: Text.rich(
TextSpan(
text:
"I agree to share my ",
// Normal text
style: CustomTextStyle
.basicStyle,
// Base style
children: [
TextSpan(
text: consent
.consentPurposeName
.toString(),
// Bold text
style: const TextStyle(
fontWeight:
FontWeight
.bold),
),
TextSpan(
text: " for ",
// Normal text
style:
CustomTextStyle
.basicStyle),
TextSpan(
text: consent
.piiLabelName
.toString(),
// Bold text
style: const TextStyle(
fontWeight:
FontWeight
.bold),
),
],
),
),
),
flex: 4,
),
Flexible(
flex: 2,
child: DropdownButtonFormField<FreqData>(
value: freqData.result!.data!.firstWhere(
(e) => e.name?.toLowerCase() == consent.frequency?.toLowerCase()
,
orElse: () => freqData.result!.data!.first,
),
items: freqData.result!.data!.map((e) {
return DropdownMenuItem<FreqData>(
value: e,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 0.0),
child: Text(
e.name!,
style: TextStyle(fontSize: 12),
),
),
);
}).toList(),
onChanged: (value) {
consent.frequency = value!.key;
},
isDense: true, // Minimizes the default padding
isExpanded: true, // Ensures the dropdown expands fully in width
decoration: InputDecoration(
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(horizontal: 12), // Adjust spacing
),
icon: Padding(
padding: EdgeInsets.only(left: 0.0), // Adds spacing to the icon
child: Icon(Icons.arrow_drop_down),
),
// iconSize: 22,
),
),
],
),
);
},
),
],
),
margin: EdgeInsets.only(bottom: 4),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6.0),
),
),
data: ThemeData()
.copyWith(dividerColor: Colors.white),
);
},
),
],
),
),
],
),
),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: SafeArea(
child: ElevatedButton(
onPressed: () {
if (validateFields(data)) {
// Proceed with the API call if all fields are valid
// _callApi(data, freqData, ref);
_moveToOtpScreen(data, freqData, ref);
} else {
// Trigger UI update to show errors
ref.read(consentProvider2.notifier)
.updateTexfield();
}
// _callApi(data, freqData, ref);
},
style: ElevatedButton.styleFrom(
backgroundColor: AppColor.appColor,
// Button color
minimumSize: const Size(double.infinity, 50),
// Full width and height
padding:
const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
// Padding inside the button
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8), // Rounded corners
),
),
child: Text(
NEXT,
style: CustomTextStyle.headingAppBar, // Custom text style
),
),
),
),
],
),
appBar: // Define a dynamic list of option
AppBar(
title: Text(
TITLE,
style: CustomTextStyle.headingAppBar,
),
centerTitle: false,
titleSpacing: 0.0,
backgroundColor: AppColor.appColor,
foregroundColor: AppColor.apptitleandbuttontextcolor,
leading: InkWell(
child: Icon(Icons.close),
onTap: () {
Navigator.of(context).pop();
// SystemNavigator.pop();
},
),
actions: [
if (data.result!.data!.formConfiguration!.showLogo!)
SvgPicture.network(
data.result!.data!.formConfiguration!.logoUrl!,
width: 40,
height: 40,
),
Padding(
padding: const EdgeInsets.only(right: 16.0), // Add space for the icon and language
child: InkWell(
onTap: () async {
// Change language action (Open language menu)
_showLanguageMenu(context,langResponse);
},
child: Row(
children: [
Icon(Icons.language), // Language icon
SizedBox(width: 8), // Space between icon and language text
Text(
selectedLanguage, // Display currently selected language
style: TextStyle(fontSize: 16),
),
],
),
),
),
// PopupMenuButton<LangData>(
// onSelected: (value) {
// SharedPreferences.getInstance().then((prefs) {
// prefs.setString('lang_code', value.languageCode!);
// });
// setState(() {});
// },
// itemBuilder: (BuildContext context) {
// // Dynamically generate PopupMenuItems
// return langResponse.result!.data!.map((LangData option) {
// return PopupMenuItem<LangData>(
// value: option,
// child: Text(option.language!),
// );
// }).toList();
// },
// icon: Icon(Icons.more_vert), // Icon for the dropdown button
// ),
// SizedBox(width: 2),
],
),
);
}