Untitled
unknown
plain_text
2 years ago
4.1 kB
3
Indexable
import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:sanad_flutter/core/config/sanad_colors.dart'; import 'package:sanad_flutter/core/widgets/custom_button.dart'; import 'package:sanad_flutter/core/widgets/custom_text.dart'; import '../../../../../core/config/app_localization.dart'; import '../bloc/investment_new_registration_bloc.dart'; class RequiredModifications extends StatefulWidget { const RequiredModifications({super.key}); @override State<RequiredModifications> createState() => _RequiredModificationsState(); } class _RequiredModificationsState extends State<RequiredModifications> { String selectedValue = '0'; Map<String, dynamic> answers = {"answers": ""}; List<Map<String, dynamic>> answersList = []; @override Widget build(BuildContext context) { var locale = AppLocalization.of(context); return BlocBuilder<InvestmentNewRegistrationBloc, InvestmentNewRegistrationState>( builder: (context, state) { return Padding( padding: const EdgeInsets.only(top: 15), child: SizedBox( width: MediaQuery.of(context).size.width * double.infinity, child: Column( children: [ ListView.builder( itemBuilder: (context, indexValue) { return checkBoxWidget( indexValue, context .read<InvestmentNewRegistrationBloc>() .investmentNewRegistrationGet! .activities[indexValue], context); }, shrinkWrap: true, physics: const NeverScrollableScrollPhysics(), itemCount: context .read<InvestmentNewRegistrationBloc>() .investmentNewRegistrationGet! .activities .length, ), const SizedBox( height: 10, ), SizedBox( width: MediaQuery.of(context).size.width * 0.85, child: CustomButton( onPressed: () { InvestmentNewRegistrationBloc.get(context) .add(const StartAttachmentEvent()); InvestmentNewRegistrationBloc.get(context) .add(AddStep()); }, backgroundColor: primaryColor, child: CustomText(AppLocalization.of(context) .getTranslatedValues('next')), ), ), const SizedBox( height: 20, ), ], ), ), ); }, ); } Widget checkBoxWidget( int index, String optionsOfAnswer, BuildContext context, ) { return StatefulBuilder(builder: (context, setSt) { bool valueBool = answersList.indexWhere((element) => element['value'] == optionsOfAnswer) > -1; return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ CheckboxListTile( value: valueBool, title: Text(optionsOfAnswer), onChanged: (newValue) { log('message $newValue'); if (newValue!) { setSt(() { answersList.add({"is_checked": true, "value": optionsOfAnswer}); }); } else { setSt(() { int indexId = answersList .indexWhere((element) => element["value"] == optionsOfAnswer); if (indexId > -1) { answersList.removeAt(indexId); } }); } log('message $answersList'); }, ), ], ); }); } }
Editor is loading...