Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何在下拉列表中选择后使小部件可用?_Flutter_Dart_Flutter Layout - Fatal编程技术网

Flutter 如何在下拉列表中选择后使小部件可用?

Flutter 如何在下拉列表中选择后使小部件可用?,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,我想在用户在下拉列表中选择如何在颤振中实现这一点后创建一张卡。下面给出了UI模型 第一张卡与永久卡类似,但如果下拉按钮有任何更改,则第二张卡应在之后出现 较低的卡应该是可滚动的,并且大小应该像listview一样动态。如果键和数据增加,则值应增加 我用来创建应用程序栏和第一张卡的代码在这里 @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( tool

我想在用户在下拉列表中选择如何在颤振中实现这一点后创建一张卡。下面给出了UI模型

第一张卡与永久卡类似,但如果下拉按钮有任何更改,则第二张卡应在之后出现

较低的卡应该是可滚动的,并且大小应该像listview一样动态。如果键和数据增加,则值应增加

我用来创建应用程序栏和第一张卡的代码在这里

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        toolbarHeight: 75,
        title: Center(
          child: Text(
            'Flutter App',
            style: GoogleFonts.lato(
                textStyle:
                    TextStyle(fontWeight: FontWeight.bold, fontSize: 26)),
          ),
        ),
      ),
      body: ListView(children: [
        Column(
          children: [
            Container(
              height: 250,
              child: Column(children: [
                Card(
                  child: Column(
                    children: [
                      Row(children: [
                        Padding(
                          padding: EdgeInsets.only(left: 30, top: 15),
                          child: Text(
                            'Text here',
                            style: GoogleFonts.poppins(
                                textStyle: TextStyle(
                              fontWeight: FontWeight.w700,
                              fontSize: 37,
                            )),
                            textAlign: TextAlign.left,
                          ),
                        ),
                      ]),
                      Padding(
                        padding: EdgeInsets.only(top: 30),
                        child: Text(
                          'Some text here',
                          style: GoogleFonts.lato(
                              textStyle: TextStyle(fontSize: 18)),
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.only(top: 30),
                        child: DropdownButton(
                          items: markets
                              .map<DropdownMenuItem<String>>((String val) {
                            return DropdownMenuItem<String>(
                                value: val, child: Text(val));
                          }).toList(),
                          onChanged: (sto) {
                            setState(() {
                              _mySelection = sto;
                            });
                            retrievedata.getPrice(_mySelection);
                          },
                          value: _mySelection,
                          hint: Text('Hint text here'),
                        ),
                      ),
                    ],
                  ),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(10.0),
                  ),
                  elevation: 5,
                  margin: EdgeInsets.all(10),
                ),
              ]),
            ),
          ],
        ),
      ]),
    );
  }
@覆盖
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
身高:75,
标题:中心(
子:文本(
“颤振应用程序”,
风格:GoogleFonts.lato(
文本样式:
TextStyle(fontWeight:fontWeight.bold,fontSize:26)),
),
),
),
正文:列表视图(子项:[
纵队(
儿童:[
容器(
身高:250,
子项:列(子项:[
卡片(
子:列(
儿童:[
世界其他地区(儿童:[
填充物(
填充:仅限边缘设置(左:30,顶:15),
子:文本(
“此处文本”,
风格:GoogleFonts.poppins(
textStyle:textStyle(
fontWeight:fontWeight.w700,
尺码:37,
)),
textAlign:textAlign.left,
),
),
]),
填充物(
填充:仅限边缘设置(顶部:30),
子:文本(
'此处有一些文本',
风格:GoogleFonts.lato(
textStyle:textStyle(fontSize:18)),
),
),
填充物(
填充:仅限边缘设置(顶部:30),
孩子:下拉按钮(
项目:市场
.map((字符串val){
返回下拉菜单项(
值:val,子项:Text(val));
}).toList(),
一旦更改:(sto){
设置状态(){
_mySelection=sto;
});
retrievedata.getPrice(_mySelection);
},
值:_mySelection,
提示:Text('hint Text here'),
),
),
],
),
形状:圆形矩形边框(
边界半径:边界半径。圆形(10.0),
),
标高:5,
保证金:所有(10),
),
]),
),
],
),
]),
);
}

您可以通过另一个状态来实现这一点,该状态负责第二张卡的可见性。大概是这样的:

  final visible = false;

  @override
  Widget build(BuildContext context) {
    return 
       ...
             onChanged: (sto) {
                setState(() {
                   _mySelection = sto;
                   visible = true;
             });
            retrievedata.getPrice(_mySelection);
         },
       ...
稍后,我们可以根据此值使第二张卡可见:

visible ? SecondCard( 
              ...
          ) : SizedBox.shrink()

这样可以确保在将
可见
设置为

之前不会显示任何内容。您可以包装
,该卡应在下拉更改到
可见
小部件后显示

添加此变量

bool _isVisible = false;
更改下拉按钮

DropdownButton(
  ...
  onChanged: (sto) {
    setState(() {
      _mySelection = sto;
      _isVisible = true;
    });
     retrievedata.getPrice(_mySelection);
  },
  ...
),
可视性将
包装起来

Visibility (
  visible: _isVisible,
  child: Card(
    child: ....
  ),
),

如果您希望卡片始终可见,并且仅在
下拉按钮更改后才启用交互,请将卡片包装为
忽略指针
,而不是可见性。

请提供一些您已经拥有的代码。@Akif添加了代码!检查这个:@Ashok我不需要下拉列表。如果下拉列表中有任何更改,我需要在之后呈现第二张卡。