533 lines
24 KiB
Dart
533 lines
24 KiB
Dart
import 'package:discover_module/constants.dart';
|
|
import 'package:discover_module/ui_screen/interactionform/interactionprovider.dart';
|
|
import 'package:discover_module/ui_screen/interactionform/model/interaction_data.dart';
|
|
import 'package:discover_module/ui_screen/interactionform/model/save_interaction.dart';
|
|
import 'package:discover_module/ui_screen/interactionform/util.dart';
|
|
import 'package:discover_module/ui_screen/interactionform/widget/custombutton.dart';
|
|
import 'package:discover_module/ui_screen/interactionform/widget/responsive_ext.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
// ignore: must_be_immutable
|
|
class ViewInteractionScreen1 extends StatefulWidget {
|
|
SaveInteraction saveInteraction;
|
|
ViewInteractionScreen1({super.key, required this.saveInteraction});
|
|
|
|
@override
|
|
State<ViewInteractionScreen1> createState() => _ViewInteractionScreenState();
|
|
}
|
|
|
|
class _ViewInteractionScreenState extends State<ViewInteractionScreen1> {
|
|
List<dynamic> interactionReponseList = [];
|
|
List<SectionList> sectionList = [];
|
|
List<TextEditingController> textEditingControllerList = [];
|
|
int textfieldIndex = 0;
|
|
String dropdownvalue = 'Select value';
|
|
String? fileName;
|
|
final TextEditingController textEditingController = TextEditingController();
|
|
@override
|
|
void initState() {
|
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
|
init();
|
|
});
|
|
|
|
super.initState();
|
|
}
|
|
|
|
init() async {
|
|
await Provider.of<InteractionProvider>(context, listen: false)
|
|
.initSavedForm(widget.saveInteraction);
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Consumer<InteractionProvider>(
|
|
builder: (BuildContext context, provider, Widget? child) {
|
|
print("build context");
|
|
print("${provider.interactionReponseList}");
|
|
return GestureDetector(
|
|
onTap: () {
|
|
FocusScope.of(context).requestFocus(FocusNode());
|
|
},
|
|
child: OrientationBuilder(builder: (context, orientation) {
|
|
return SafeArea(
|
|
child: Scaffold(
|
|
backgroundColor: Colors.white,
|
|
//resizeToAvoidBottomInset: false,
|
|
appBar: AppBar(
|
|
title: Text(
|
|
widget.saveInteraction.id,
|
|
style: TextStyle(
|
|
fontSize: isTablet ? 22 : 14, color: Colors.white),
|
|
),
|
|
// backgroundColor: const Color(0xFF2b9af3),
|
|
automaticallyImplyLeading: false,
|
|
leading: InkWell(
|
|
onTap: () {
|
|
Navigator.pop(context);
|
|
},
|
|
child: const Icon(
|
|
Icons.arrow_back_ios,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
),
|
|
body: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Expanded(
|
|
child: ListView.builder(
|
|
itemCount: provider.interactionReponseList.length,
|
|
cacheExtent: double.parse(
|
|
provider.interactionReponseList.length.toString()),
|
|
itemBuilder: (context, index) {
|
|
var item = provider.interactionReponseList[index];
|
|
sectionList = item.sectionList;
|
|
return Card(
|
|
elevation: 4,
|
|
// color: Constants.k2color,
|
|
child: Container(
|
|
color: Color.fromARGB(255, 246, 248, 252),
|
|
child: ExpansionTile(
|
|
dense: true,
|
|
initiallyExpanded: true,
|
|
title: Stack(
|
|
alignment: AlignmentDirectional.center,
|
|
children: [
|
|
Container(
|
|
// height: double.infinity,
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(0.0),
|
|
decoration: BoxDecoration(
|
|
// color: Color(0xFF2b9af3),
|
|
// color: Constants.k2color,
|
|
),
|
|
child: Text(
|
|
item.sectionName,
|
|
style: const TextStyle(
|
|
color: Colors.black,
|
|
fontWeight: FontWeight.normal,
|
|
fontSize: 18.0),
|
|
)),
|
|
]),
|
|
children: [
|
|
Container(
|
|
color: Colors.white,
|
|
child: Padding(
|
|
padding:
|
|
const EdgeInsets.only(top: 0.0),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment:
|
|
CrossAxisAlignment.center,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(
|
|
left: 18.0),
|
|
child: GridView.count(
|
|
physics:
|
|
const NeverScrollableScrollPhysics(),
|
|
crossAxisCount:
|
|
context.responsive<int>(
|
|
1,
|
|
sm: 1, // small
|
|
md: 2, // medium
|
|
lg: sectionList.length == 1
|
|
? 1
|
|
: 3, // large
|
|
xl: 3, // extra large screen
|
|
),
|
|
mainAxisSpacing:
|
|
sectionList.length == 1 ||
|
|
!isTablet
|
|
? 1
|
|
: 3.5,
|
|
childAspectRatio:
|
|
sectionList.length == 1
|
|
? orientation ==
|
|
Orientation
|
|
.landscape
|
|
? 10
|
|
: 4.8
|
|
: isTablet
|
|
? 2.8
|
|
: 5.5,
|
|
shrinkWrap: true,
|
|
padding: EdgeInsets.zero,
|
|
children: List.generate(
|
|
sectionList.length,
|
|
(i) {
|
|
print(sectionList);
|
|
SectionList sectionItem =
|
|
sectionList[i];
|
|
dropdownvalue = sectionItem
|
|
.widget ==
|
|
InteractionWidget
|
|
.DROPDOWN
|
|
? sectionItem.value ??
|
|
"Select"
|
|
: ' ';
|
|
List<
|
|
InputClass> list = sectionItem
|
|
.widget ==
|
|
InteractionWidget
|
|
.DROPDOWN ||
|
|
sectionItem
|
|
.widget ==
|
|
InteractionWidget
|
|
.AUTOCOMPLETE ||
|
|
sectionItem
|
|
.widget ==
|
|
InteractionWidget
|
|
.MULTISELECT
|
|
? provider.getData2(
|
|
sectionItem)
|
|
: [];
|
|
provider.checkboxlist =
|
|
sectionItem.widget ==
|
|
InteractionWidget
|
|
.CHECKBOX
|
|
? provider.getData2(
|
|
sectionItem)
|
|
: [];
|
|
|
|
return Column(
|
|
crossAxisAlignment:
|
|
CrossAxisAlignment
|
|
.start,
|
|
children: [
|
|
sectionItem.widget ==
|
|
InteractionWidget
|
|
.BUTTON &&
|
|
sectionItem
|
|
.param ==
|
|
'add'
|
|
? const SizedBox
|
|
.shrink()
|
|
: Text(
|
|
'${sectionItem.name}:*',
|
|
style: TextStyle(
|
|
color: Constants
|
|
.k2color,
|
|
fontSize:
|
|
isTablet
|
|
? 18
|
|
: 12,
|
|
fontWeight:
|
|
FontWeight
|
|
.normal),
|
|
),
|
|
returnWidget(
|
|
sectionItem:
|
|
sectionItem,
|
|
item: item,
|
|
provider: provider,
|
|
list: list,
|
|
gridIndex: i,
|
|
listIndex: index,
|
|
widgetData:
|
|
sectionItem
|
|
.widget!),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
|
|
item.multiple
|
|
? gridViewWidget(
|
|
provider,
|
|
item.sectionName,
|
|
item.multipleList ?? [],
|
|
orientation,
|
|
item,
|
|
index)
|
|
: const SizedBox.shrink(),
|
|
provider.interactionReponseList
|
|
.length ==
|
|
index - 1
|
|
? saveActions(provider)
|
|
: const SizedBox.shrink()
|
|
//const Spacer(),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
]),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
// const Spacer(),
|
|
// saveActions(provider),
|
|
],
|
|
)),
|
|
);
|
|
}),
|
|
);
|
|
});
|
|
}
|
|
|
|
Widget returnWidget({
|
|
required SectionList sectionItem,
|
|
required FormFieldData item,
|
|
required InteractionProvider provider,
|
|
required List<InputClass> list,
|
|
required int gridIndex,
|
|
required int listIndex,
|
|
required InteractionWidget widgetData,
|
|
}) {
|
|
switch (widgetData) {
|
|
case InteractionWidget.CHECKBOX:
|
|
return (sectionItem.inputList!.length >= 5)
|
|
? Text(sectionItem.selectedValue.toString())
|
|
: Text(provider.getDataValue(
|
|
sectionItem.id, sectionItem.selectedValue!.last));
|
|
|
|
case InteractionWidget.AUTOCOMPLETE:
|
|
return Text(provider.getDataValue(
|
|
sectionItem.id, sectionItem.selectedValue!.last));
|
|
|
|
case InteractionWidget.MULTISELECT:
|
|
return Text(sectionItem.selectedValue.toString());
|
|
|
|
case InteractionWidget.RADIO:
|
|
return (sectionItem.inputList!.length >= 5)
|
|
? Text(
|
|
sectionItem.selectedValue!.isNotEmpty
|
|
? provider.getDataValue(
|
|
sectionItem.id, sectionItem.selectedValue!.last)
|
|
: " ",
|
|
style: TextStyle(fontSize: 18.0),
|
|
)
|
|
: Text(
|
|
provider.getDataValue(
|
|
sectionItem.id,
|
|
sectionItem.selectedValue!.last,
|
|
),
|
|
style: TextStyle(fontSize: 18.0),
|
|
);
|
|
|
|
case InteractionWidget.LABEL:
|
|
return Text(
|
|
sectionItem.input!,
|
|
style: TextStyle(fontSize: 18.0),
|
|
);
|
|
|
|
case InteractionWidget.RANGESLIDER:
|
|
return Text(sectionItem.selectedValue!.isNotEmpty
|
|
? sectionItem.selectedValue!.last.toString()
|
|
: " ");
|
|
|
|
case InteractionWidget.TEXT:
|
|
return Text(
|
|
sectionItem.selectedValue!.isNotEmpty
|
|
? sectionItem.selectedValue!.last.toString()
|
|
: " ",
|
|
style: TextStyle(fontSize: 18.0),
|
|
);
|
|
|
|
case InteractionWidget.BUTTON:
|
|
return sectionItem.input == "chooseFile"
|
|
? sectionItem.selectedValue!.isNotEmpty
|
|
? const Text("File Uploaded")
|
|
: const Text(" ")
|
|
: const Text(" ");
|
|
default:
|
|
return Text(sectionItem.selectedValue!.isNotEmpty
|
|
? provider.getDataValue(
|
|
sectionItem.id, sectionItem.selectedValue!.last)
|
|
: " ");
|
|
}
|
|
}
|
|
|
|
Widget saveActions(InteractionProvider provider) {
|
|
return Align(
|
|
alignment: Alignment.centerRight,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
CustomButton(
|
|
backgroundColor: Colors.red.shade800,
|
|
onPressed: () {
|
|
//showDeleteProfileAlertDialog(context);
|
|
for (var textcontrollers in provider.textEditingControllerList) {
|
|
textcontrollers.text = '';
|
|
}
|
|
},
|
|
textColor: Colors.white,
|
|
title: "Reset",
|
|
height: 40,
|
|
width: isTablet ? 100 : 60,
|
|
fontsize: isTablet ? 15 : 10.2,
|
|
),
|
|
SizedBox(
|
|
width: isTablet ? 20 : 4,
|
|
),
|
|
CustomButton(
|
|
backgroundColor: Colors.green.shade900,
|
|
onPressed: () async {
|
|
if (textFieldsValidation(provider).isEmpty) {
|
|
// await provider.saveJsonObject(context, widget.form);
|
|
_displaySnackBar('Form Saved Sucessfully!');
|
|
} else {
|
|
_displaySnackBar(textFieldsValidation(provider));
|
|
}
|
|
},
|
|
textColor: Colors.white,
|
|
title: "Save",
|
|
height: 40,
|
|
width: isTablet ? 100 : 60,
|
|
fontsize: isTablet ? 16 : 12,
|
|
),
|
|
SizedBox(
|
|
width: isTablet ? 20 : 2,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget gridViewWidget(
|
|
InteractionProvider provider,
|
|
String sectionName,
|
|
List<SectionList> sectionList,
|
|
Orientation orientation,
|
|
FormFieldData item,
|
|
int listIndex) {
|
|
List<SectionList> pooja = sectionList;
|
|
|
|
print("Pooja: $pooja");
|
|
|
|
List<List<SectionList>> convertedArray = [];
|
|
print("Provider Length: ${item.sectionList.length}");
|
|
|
|
for (int i = 0; i < sectionList.length; i += item.sectionList.length + 1) {
|
|
print("Section List11111: $sectionList");
|
|
print("item.sectionList.length List11111: ${item.sectionList.length}");
|
|
|
|
convertedArray
|
|
.add(sectionList.sublist(i, i + item.sectionList.length + 1));
|
|
}
|
|
print("ConvertedArrayEdit.leangth: $convertedArray");
|
|
print("ConvertedArray.leangth2323: ${convertedArray.length}");
|
|
|
|
return Column(
|
|
children: [
|
|
for (var i = 0; i < convertedArray.length; i++)
|
|
DecoratedBox(
|
|
decoration: BoxDecoration(
|
|
// borderRadius: BorderRadius.circular(10.0),
|
|
color: i % 2 == 0
|
|
? Color.fromARGB(133, 213, 241, 254)
|
|
: Colors.white,
|
|
),
|
|
child: GridView.builder(
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: context.responsive<int>(
|
|
1, // default
|
|
sm: 1, // small
|
|
md: 2, // medium
|
|
lg: sectionList.length == 1
|
|
? 1
|
|
: (sectionList.length >= 1 ? 3 : 3),
|
|
// lg: sectionList.length == 1 ? 1 : 3, // large
|
|
xl: 3, // extra large screen
|
|
),
|
|
childAspectRatio: sectionList.length == 1
|
|
? orientation == Orientation.landscape
|
|
? 10
|
|
: 4.8
|
|
: isTablet
|
|
? 2.8
|
|
: 5.5,
|
|
|
|
mainAxisSpacing: sectionList.length == 1 || !isTablet ? 1 : 3.5,
|
|
// mainAxisSpacing: sectionList.length == 1 || !isTablet ? 1 : 2,
|
|
),
|
|
shrinkWrap: true,
|
|
padding: EdgeInsets.zero,
|
|
itemCount: convertedArray[i].length,
|
|
itemBuilder: (context, index) {
|
|
SectionList sectionItem = convertedArray[i][index];
|
|
dropdownvalue = sectionItem.widget == InteractionWidget.DROPDOWN
|
|
? sectionItem.value ?? "Select"
|
|
: ' ';
|
|
List<InputClass> list = sectionItem.widget ==
|
|
InteractionWidget.DROPDOWN ||
|
|
sectionItem.widget == InteractionWidget.AUTOCOMPLETE ||
|
|
sectionItem.widget == InteractionWidget.MULTISELECT
|
|
? provider.getData2(sectionItem)
|
|
: [];
|
|
provider.checkboxlist =
|
|
sectionItem.widget == InteractionWidget.CHECKBOX
|
|
? provider.getData2(sectionItem)
|
|
: [];
|
|
|
|
return SizedBox(
|
|
height: MediaQuery.of(context).size.height,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 18.0, top: 10.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
sectionItem.widget == InteractionWidget.BUTTON &&
|
|
sectionItem.param == 'add' ||
|
|
sectionItem.param == 'deletebtn'
|
|
? const SizedBox.shrink()
|
|
|
|
// ? const SizedBox.shrink()
|
|
: Text(
|
|
'${sectionItem.name}:*',
|
|
style: TextStyle(
|
|
color: Constants.k2color,
|
|
fontSize: isTablet ? 18 : 12,
|
|
),
|
|
),
|
|
// const SizedBox(
|
|
// height: 15,
|
|
// ),
|
|
returnWidget(
|
|
sectionItem: sectionItem,
|
|
item: item,
|
|
provider: provider,
|
|
list: list,
|
|
gridIndex: i,
|
|
listIndex: listIndex,
|
|
widgetData: sectionItem.widget!),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
//),
|
|
],
|
|
);
|
|
}
|
|
|
|
String textFieldsValidation(InteractionProvider provider) {
|
|
if (provider.sectionList
|
|
.any((element) => element.controller!.text.isEmpty)) {
|
|
return 'Fields cannot be empty';
|
|
}
|
|
|
|
return '';
|
|
}
|
|
|
|
_displaySnackBar(String msg) {
|
|
final snackBar = SnackBar(
|
|
content: Text(
|
|
msg,
|
|
style: const TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold),
|
|
));
|
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
|
//scaffoldKeyLogin.currentState!.showSnackBar(snackBar);
|
|
}
|
|
}
|