Skip to content

Instantly share code, notes, and snippets.

@behzodfaiziev
Last active May 12, 2022 07:52
Show Gist options
  • Select an option

  • Save behzodfaiziev/72fbe4720193ebefb690a04bd1b3feab to your computer and use it in GitHub Desktop.

Select an option

Save behzodfaiziev/72fbe4720193ebefb690a04bd1b3feab to your computer and use it in GitHub Desktop.
How to add new list when I click on the current list
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: UploadDoc(),
),
);
}
}
class UploadDoc extends StatefulWidget {
const UploadDoc({Key? key}) : super(key: key);
@override
State<UploadDoc> createState() => _UploadDocState();
}
class _UploadDocState extends State<UploadDoc> {
final List<Map<String, dynamic>> listSelection = [
{
'id': 0,
'header': 'Muat Naik Surat Rasmi Permohonan',
'title': 'Muat Naik Surat Rasmi',
},
{
'id': 1,
'header': 'Surat Lantikan Peguam',
'title': 'test',
},
{
'id': 2,
'header': 'Surat hubungan peguam dan pemilik daftar',
'title': 'test',
},
];
final List<Map<String, dynamic>> selected = [];
// 'icon': const Icon(Icons.add_circle_outlined),
int counter = 0;
@override
Widget build(BuildContext context) {
if (selected.isEmpty) {
selected.add(listSelection[0]);
}
return Scaffold(
appBar: AppBar(),
body: ListView.builder(
itemCount: selected.length,
itemBuilder: (ctx, index) {
return Column(
children: [
Container(
width: double.infinity,
height: 30,
color: Colors.grey,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
const SizedBox(width: 10),
Text(listSelection[index]['header'],
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold)),
],
)),
ListTile(
leading: const Icon(Icons.add_circle_outlined),
title: Text(listSelection[index]['header']),
onTap: () => _addNewUploadDoc(),
),
const Divider(thickness: 1)
],
);
},
),
);
}
void _addNewUploadDoc() {
setState(() {
if (listSelection.length > selected.length) {
selected.add(listSelection[selected.length]);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment