'How can I generate new item list inside my current list when I tap on icon?
can you help me with this? I want to create a widget that can generate a new item list when I click an icon/button.
The widget will be like an uploaded document (many types of documents) section. When the user clicks the current section, it will automatically generate a new section for another type of document for users to upload.
Now, my current problem is when I tap the section, it comes out nothing. Here is my coding. Please refer to it.
class UploadDoc extends StatefulWidget {
const UploadDoc({ Key? key }) : super(key: key);
@override
State<UploadDoc> createState() => new _UploadDocState();
}
class _UploadDocState extends State<UploadDoc> {
final List<dynamic> listSelection = [
{
'id': 0,
'header':'test',
'icon': Icon(Icons.abc_outlined),
'title': 'test',
},
{
'id': 1,
'header':'test',
'icon': Icon(Icons.abc_outlined),
'title': 'test',
},
{
'id': 2,
'header':'test',
'icon': Icon(Icons.abc_outlined),
'title': 'test',
},
];
dynamic _selected = 0;
int index = 0;
int _count =1;
@override
Widget build(BuildContext context) {
return Column(
children: [
Container(
width: double.infinity,
height: 30,
color: Colors.grey,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(width: 10),
Text(listSelection[index]['header'], style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
],
)),
ListTile(
leading: listSelection[index]['icon'],
title: Text(listSelection[index]['header']),
onTap: addNewList,
),
const Divider(thickness: 1)
],
);
}
void _addNewUploadDoc() {
if(listSelection.length != _selected.length){
for (int i = 0; i < listSelection.length-1; i++) {
_selected.add(listSelection[i]);
}
setState(() {});
}
}
}
this is my addNewlist()
void _addNewUploadDoc() {
if(listSelection.length != _selected.length){
for (int i = 0; i < listSelection.length-1; i++) {
_selected.add(listSelection[i]);
}
setState(() {});
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


