在这里,我正在创建一个应用程序,其中包含一个用户可以通过该部分创建民意调查的部分。因此,当我按下添加按钮时,选项容器被添加,但是当我试图通过按下减号按钮删除选项容器时,它不起作用。有人可以帮我解决这个问题。这是我的大学项目。
import 'package:flutter/material.dart';
import 'package:note_app_demo/scaffold.dart';
List<Container> options = [
Container(
padding: EdgeInsets.all(15),
child: TextField(
decoration: InputDecoration(
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10)),
hintText: 'Option 1',
),
),
),
];
class POLL extends StatefulWidget {
const POLL({Key? key}) : super(key: key);
@override
_POLLState createState() => _POLLState();
}
class _POLLState extends State<POLL> {
int option_var = 1;
@override
Widget build(BuildContext context) {
return SCAFFOLD(
BODY: SingleChildScrollView(
child: Column(
children: [
Container(
padding: EdgeInsets.all(15),
child: TextField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10)),
hintText: 'Write your question here',
),
),
),
Column(
children: options,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
child: GestureDetector(
onTap: () {
setState(() {
options.removeAt(option_var);
});
option_var--;
},
child: Icon(
Icons.remove_circle,
size: 60,
),
),
),
Container(
child: GestureDetector(
onTap: () {
option_var++;
if (option_var < 9) {
setState(() {
options.add(
Container(
padding: EdgeInsets.all(15),
child: TextField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10)),
hintText: 'Option $option_var',
),
),
),
);
});
}
},
child: Icon(
Icons.add_circle,
size: 60,
),
),
),
],
),
Container(
child: GestureDetector(
onTap: () {},
child: Icon(
Icons.check_circle,
size: 60,
),
),
),
],
),
),
);
}
}