【问题标题】:How to update child dropdown after parent dropdown's selection changes?父下拉列表的选择更改后如何更新子下拉列表?
【发布时间】:2019-07-08 10:52:33
【问题描述】:

所以我有一列下拉列表,每个下拉列表都是下面下拉列表的先决条件。当Dropdown A 更改其值时,我会进行 API 调用并填充Dropdown BDropdown C 的选项取决于 B 的值,等等...

我很好地完成了这个场景,但我遇到的问题是当下拉菜单 A 到 D 被选中时,我更改了 Dropdown B 的值,下拉菜单 C 和 D 并没有改变它的值。

求救和求救

【问题讨论】:

  • 也粘贴你的代码

标签: flutter widget


【解决方案1】:

参考给定的例子:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

/// This is the main application widget.
class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample';

@override
Widget build(BuildContext context) {
return MaterialApp(
  title: _title,
  home: Scaffold(
    appBar: AppBar(title: const Text(_title)),
    body: Center(
      child: MyStatefulWidget(),
    ),
  ),
);
}
}

 /// This is the stateful widget that the main application instantiates.
 class MyStatefulWidget extends StatefulWidget {
 MyStatefulWidget({Key key}) : super(key: key);

 @override
 _MyStatefulWidgetState createState() => _MyStatefulWidgetState();
 }

 /// This is the private State class that goes with MyStatefulWidget.
 class _MyStatefulWidgetState extends State<MyStatefulWidget> {
 String dropdownValue = 'One';

 @override
 Widget build(BuildContext context) {
 return DropdownButton<String>(
  value: dropdownValue,
  icon: Icon(Icons.arrow_downward),
  iconSize: 24,
  elevation: 16,
  style: TextStyle(color: Colors.deepPurple),
  underline: Container(
    height: 2,
    color: Colors.deepPurpleAccent,
  ),
  onChanged: (String newValue) {
    setState(() {
      dropdownValue = newValue;
    });
  },
  items: <String>['One', 'Two', 'Free', 'Four']
      .map<DropdownMenuItem<String>>((String value) {
    return DropdownMenuItem<String>(
      value: value,
      child: Text(value),
    );
  }).toList(),
);

} }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-11
    • 1970-01-01
    相关资源
    最近更新 更多