flutter下拉按钮选择问题
大家好,我刚刚开始flutter,我正在一个小项目中单击dropdownbutton,整个按钮同时更改,以及如何将下拉餐点放在右边? (检查GIF)
,我想让文本在单元格内部更可读,这是代码,并且要预先感谢。
import 'package:flutter/material.dart';
class Check_lists extends StatefulWidget {
String sug_one;
String sug_two;
Check_lists(this.sug_one, this.sug_two);
@override
State<Check_lists> createState() => _Check_listsState();
}
class _Check_listsState extends State<Check_lists> {
String dropdownValue = "Not Done";
int index = 0;
List<String> propositions = <String>[
"Single line spacing",
"Title set below the 2 top margin",
"Title not exceeding 15 words (including articles,prepositions and conjunctions)",
"Title in uppercase",
"Title arranged in an inverted pyramid",
"All parts centered, and in boldface",
"4 line skips (5 enter presses) between parts",
"First name, middle initial(s), last name format for the author’s names",
"Leader's name followed by members names",
"alphabetized by surname",
"Date of proposal stated as month, day, year",
"Start of pagination"
];
//List<String> answer = ["Done", "partially Done", "Not Done"];
List<String> selectedItemValue = <String>[];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: const Color.fromRGBO(82, 113, 255, 25),
title: Row(
children: [
Container(
padding: const EdgeInsets.all(10.0),
child: const Text('CHEKILI Table of Content'))
],
),
),
body: Column(
children: <Widget>[
Flexible(
child: ListView.builder(
itemCount: propositions.length,
itemExtent: 50.0,
itemBuilder: (BuildContext context, int index) {
for (int i = 0; i < propositions.length; i++) {
selectedItemValue.add("Not Done");
}
return ListTile(
title: Text("${propositions[index]}"),
leading: _dropdown(),
);
},
),
),
],
));
}
Widget _dropdown() {
return DropdownButton<String>(
isExpanded: false,
value: selectedItemValue[index].toString(),
items: _dropDownItem(),
onChanged: (value) {
selectedItemValue[index] = value as String;
setState(() {});
},
);
}
List<DropdownMenuItem<String>> _dropDownItem() {
List<String> ddl = ["Not Done", "Partially Done", "Done"];
return ddl
.map((value) => DropdownMenuItem(
value: value,
child: Text(value),
))
.toList();
}
}
hello guys i'm just starting flutter i'm on a little project , a checklist project to be precise i have created a checklist i loaded the text from a List to a ListTile and i've loaded the dropdownbutton with answers , but when i click on on dropdownbutton the whole button get changed on the same time and how to put the dropdownbutton on the right ?? (check the gif)
and i want to make the text loaded more readable inside the cells , here is the code , and thanks in advance.
import 'package:flutter/material.dart';
class Check_lists extends StatefulWidget {
String sug_one;
String sug_two;
Check_lists(this.sug_one, this.sug_two);
@override
State<Check_lists> createState() => _Check_listsState();
}
class _Check_listsState extends State<Check_lists> {
String dropdownValue = "Not Done";
int index = 0;
List<String> propositions = <String>[
"Single line spacing",
"Title set below the 2 top margin",
"Title not exceeding 15 words (including articles,prepositions and conjunctions)",
"Title in uppercase",
"Title arranged in an inverted pyramid",
"All parts centered, and in boldface",
"4 line skips (5 enter presses) between parts",
"First name, middle initial(s), last name format for the author’s names",
"Leader's name followed by members names",
"alphabetized by surname",
"Date of proposal stated as month, day, year",
"Start of pagination"
];
//List<String> answer = ["Done", "partially Done", "Not Done"];
List<String> selectedItemValue = <String>[];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: const Color.fromRGBO(82, 113, 255, 25),
title: Row(
children: [
Container(
padding: const EdgeInsets.all(10.0),
child: const Text('CHEKILI Table of Content'))
],
),
),
body: Column(
children: <Widget>[
Flexible(
child: ListView.builder(
itemCount: propositions.length,
itemExtent: 50.0,
itemBuilder: (BuildContext context, int index) {
for (int i = 0; i < propositions.length; i++) {
selectedItemValue.add("Not Done");
}
return ListTile(
title: Text("${propositions[index]}"),
leading: _dropdown(),
);
},
),
),
],
));
}
Widget _dropdown() {
return DropdownButton<String>(
isExpanded: false,
value: selectedItemValue[index].toString(),
items: _dropDownItem(),
onChanged: (value) {
selectedItemValue[index] = value as String;
setState(() {});
},
);
}
List<DropdownMenuItem<String>> _dropDownItem() {
List<String> ddl = ["Not Done", "Partially Done", "Done"];
return ddl
.map((value) => DropdownMenuItem(
value: value,
child: Text(value),
))
.toList();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为您使用的是
index
类的变量。将索引传递到
_Dropdown
功能如下。其他注意事项:
不要将循环放置在列表中添加一些值,例如
selectionItemvalue.add(“ not done”);
在listView.builder
中。由于列表项目出现在屏幕上时,因此调用了构建器,因此
selectedItemvalue
将被添加过多。因此,在
initstate
函数下启动列表如下。Because you are using the
index
variable of the class.Pass the index to the
_dropdown
function like below.Other notes:
Don't place the loop that adding some value to the list like
selectedItemValue.add("Not Done");
in theListView.builder
.Because builder is called when the list item appears on the screen, the
selectedItemValue
will be added too many times.So init the list at the
initState
function like below.