mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-07-08 01:30:28 +08:00
Fix bug
This commit is contained in:
@@ -47,20 +47,7 @@ class _StringListFormField extends State<StringListFormField> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildItem(BuildContext context, int index) {
|
Widget _buildItem(BuildContext context, int index) {
|
||||||
final isLast = index == value.length;
|
Widget item = Row(
|
||||||
if (isLast) {
|
|
||||||
return IconButton(
|
|
||||||
key: lastKey,
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
value.add("");
|
|
||||||
keys.add(ValueKey("${parentKey}_${value.length}"));
|
|
||||||
});
|
|
||||||
widget.onChanged?.call(value);
|
|
||||||
},
|
|
||||||
icon: const Icon(Icons.add));
|
|
||||||
}
|
|
||||||
return Row(
|
|
||||||
key: keys[index],
|
key: keys[index],
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
@@ -94,6 +81,14 @@ class _StringListFormField extends State<StringListFormField> {
|
|||||||
index: index, child: const Icon(Icons.reorder)),
|
index: index, child: const Icon(Icons.reorder)),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
if (widget.padding != null) {
|
||||||
|
item = Padding(
|
||||||
|
key: item.key,
|
||||||
|
padding: widget.padding!,
|
||||||
|
child: item,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onReorder(int oldIndex, int newIndex) {
|
void onReorder(int oldIndex, int newIndex) {
|
||||||
@@ -111,18 +106,8 @@ class _StringListFormField extends State<StringListFormField> {
|
|||||||
|
|
||||||
Widget _buildList(BuildContext context) {
|
Widget _buildList(BuildContext context) {
|
||||||
Widget list = ReorderableList(
|
Widget list = ReorderableList(
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: _buildItem,
|
||||||
final item = _buildItem(context, index);
|
itemCount: value.length,
|
||||||
if (widget.padding == null) {
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
return Padding(
|
|
||||||
key: item.key,
|
|
||||||
padding: widget.padding!,
|
|
||||||
child: item,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
itemCount: value.length + 1,
|
|
||||||
onReorder: onReorder,
|
onReorder: onReorder,
|
||||||
proxyDecorator: proxyDecorator,
|
proxyDecorator: proxyDecorator,
|
||||||
shrinkWrap: true);
|
shrinkWrap: true);
|
||||||
@@ -176,6 +161,30 @@ class _StringListFormField extends State<StringListFormField> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildAddButton(BuildContext context) {
|
||||||
|
Widget button = LayoutBuilder(builder: (context, box) {
|
||||||
|
return SizedBox(
|
||||||
|
width: box.maxWidth,
|
||||||
|
child: IconButton(
|
||||||
|
key: lastKey,
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
value.add("");
|
||||||
|
keys.add(ValueKey("${parentKey}_${value.length}"));
|
||||||
|
});
|
||||||
|
widget.onChanged?.call(value);
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.add)));
|
||||||
|
});
|
||||||
|
if (widget.padding != null) {
|
||||||
|
button = Padding(
|
||||||
|
padding: widget.padding!,
|
||||||
|
child: button,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (value.length != keys.length) {
|
if (value.length != keys.length) {
|
||||||
@@ -190,6 +199,7 @@ class _StringListFormField extends State<StringListFormField> {
|
|||||||
children: [
|
children: [
|
||||||
_buildLabel(context),
|
_buildLabel(context),
|
||||||
_buildList(context),
|
_buildList(context),
|
||||||
|
_buildAddButton(context),
|
||||||
_buildHelper(context),
|
_buildHelper(context),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user