Closed mdsrkhnafd closed 1 year ago
Please send me a screen recording video. You probably have the accordion wrapped in your state management, right?
yes when i setState in AccordionSection content AccordionSection automatically closed
please fix this ASAP
Please send me a screen recording video. You probably have the accordion wrapped in your state management, right?
https://github.com/GotJimmy/accordion/assets/72373676/c633d8d1-c511-4325-a1f5-c06c5d8cefd2
Did you wrap the whole Accordion
or just your widgets within the first AccordionSection
?
Did you wrap the whole
Accordion
or just your widgets within the firstAccordionSection
?
import 'package:accordion/accordion.dart'; import 'package:flutter/material.dart';
class PatientEmrScreen extends StatefulWidget { const PatientEmrScreen({Key? key}) : super(key: key);
@override
State
class _PatientEmrScreenState extends State
List
List
List
String _selectedItem1 = ''; String _selectedItem2 = '';
String _selectedSuggestion1 = ''; String _selectedSuggestion2 = '';
void _filterData(String query, List
void _selectItem(String item, TextEditingController controller) { setState(() { if (controller == complaintController) { _selectedItem1 = item; complaintController.text = item; _filteredData1 = []; _selectedSuggestion1 = item; } else if (controller == diagnosisController) { _selectedItem2 = item; diagnosisController.text = item; _filteredData2 = []; _selectedSuggestion2 = item; } }); }
void _saveSelectedItem1() { if (_selectedSuggestion1.isNotEmpty) { print('Selected item from List 1: $_selectedSuggestion1'); } else { print('No item selected from List 1'); } }
void _saveSelectedItem2() { if (_selectedSuggestion2.isNotEmpty) { print('Selected item from List 2: $_selectedSuggestion2'); } else { print('No item selected from List 2'); } }
final _headerStyle = const TextStyle( color: Color(0xffffffff), fontSize: 15, fontWeight: FontWeight.bold, );
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Patient EMR'), centerTitle: true, ), body: Accordion( maxOpenSections: 1, headerBackgroundColorOpened: Colors.blue, scaleWhenAnimating: true, headerPadding: const EdgeInsets.symmetric(vertical: 15, horizontal: 10), openAndCloseAnimation: true, children: [ AccordionSection( isOpen: false, header: Text('Presenting Complaint', style: _headerStyle), content: Column( children: [ Focus( onFocusChange: (hasFocus) { // This callback will be called when the focus changes }, child: TextFormField( controller: complaintController, onChanged: (value) { _filterData(value, _dataList1, complaintController); }, decoration: const InputDecoration( labelText: 'Search List 1', border: OutlineInputBorder(), ), ), ), if (_filteredData1.isNotEmpty) SizedBox( height: 500, child: ListView.builder( shrinkWrap: true, itemCount: _filteredData1.length, itemBuilder: (context, index) { final item = _filteredData1[index]; return ListTile( onTap: () { _selectItem(item, complaintController); }, title: Text(item), ); }, ), ), if (_selectedSuggestion1.isNotEmpty) ElevatedButton( onPressed: _saveSelectedItem1, child: const Text('Save 1'), ), const SizedBox( height: 15, ), ], ), ), AccordionSection( isOpen: false, header: Text( 'Diagnosis', style: _headerStyle, ), content: Column( children: [ Padding( padding: const EdgeInsets.all(16.0), child: Focus( onFocusChange: (value) {
},
child: TextFormField(
controller: diagnosisController,
onChanged: (value) {
_filterData(value, _dataList2, diagnosisController);
},
decoration: const InputDecoration(
labelText: 'Search List 2',
border: OutlineInputBorder(),
),
),
),
),
if (_filteredData2.isNotEmpty)
SizedBox(
height: 500,
child: ListView.builder(
shrinkWrap: true,
itemCount: _filteredData2.length,
itemBuilder: (context, index) {
final item = _filteredData2[index];
return GestureDetector(
onTap: () {
_selectItem(item, diagnosisController);
},
child: ListTile(
title: Text(item),
),
);
},
),
),
if (_selectedSuggestion2.isNotEmpty)
ElevatedButton(
onPressed: _saveSelectedItem2,
child: const Text('Save 2'),
),
const SizedBox(
height: 15,
),
],
),
),
],
),
);
} }
void main() { runApp(MaterialApp(home: PatientEmrScreen())); }
Did you wrap the whole
Accordion
or just your widgets within the firstAccordionSection
?
Please Solve the issue ASAP i am stuck
I cannot solve an issue that is not the problem of Accordion
!
My guess is that your StatefulWidget rebuilds the entire Accordion widget and thereby putting it in its original state (playing its opening animation). I would leave the Accordion in a StatelessWidget and extract the portion with the textfield and button into a separate widget with its own handling of the state.
In short: you're rebuilding too much of your UI (the Accordion), not only the part that needs it (the textfield inside one AccordionSection).
https://github.com/GotJimmy/accordion/assets/6039735/6961ccda-e8c2-403b-8367-ff9a0a9400c9
I cannot solve an issue that is not the problem of
Accordion
! My guess is that your StatefulWidget rebuilds the entire Accordion widget and thereby putting it in its original state (playing its opening animation). I would leave the Accordion in a StatelessWidget and extract the portion with the textfield and button into a separate widget with its own handling of the state. In short: you're rebuilding too much of your UI (the Accordion), not only the part that needs it (the textfield inside one AccordionSection).screenshot.mov
in a Textformfield i am searching data and then select the item and then press the button is not working how to handle see my code implement this type of code and Videos and Image that i have implement. You Only Impelement the simple TextFormField i Implement this type of field but when i am searching some data is not working
Again, you need to extract everything from that one AccordionSection body into a separate widget that handles its own state as I suggested before. Have you tried that by now?
it cant work for me why this is closed
Please Solve this ASAP when i seacrh item it will closed automatically