如何通过单击按钮选择小部件和运行命令

时间:2021-04-19 09:32:33

标签: flutter dart button

我正在尝试创建一个具有 3 个容器和一个按钮的定位小部件。选择一个容器1并单击按钮时,它应该为Container1运行命令,而选择Container2,它应该为Container2运行命令,等等。 我只能用第一个运行命令。容器。请我需要帮助谢谢

Positioned(
  left: 0,
  right: 0,
  bottom: 0,
  child: AnimatedSize(
    vsync: this,
    duration: Duration(milliseconds: 150),
    child: Container(
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.only(topLeft: Radius.circular(15), topRight: Radius.circular(15)),
        boxShadow: [
          BoxShadow(
              color: Colors.black26,
              blurRadius: 15.0,
              spreadRadius: 0.5,
              offset: Offset(
                0.7, 0.7,
              )
          )
        ],
      ),
      height:  300,
      child: Padding(
        padding:  EdgeInsets.symmetric(vertical: 18),
        child: SingleChildScrollView(
          child: Column(
            children: [
              Container(
                color: Colors.blue,
                width: double.infinity,
                child: Padding(
                  padding:  EdgeInsets.symmetric(horizontal: 2),
                  child: FlatButton(
                    onPressed: (){},
                    child: Row(
                      children: [
                        Image.asset('c', height: 70, width: 70,),
                        SizedBox(width: 16,),
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(‘c’, style: TextStyle(fontSize: 18, fontFamily: ‘b’),),
                            Text(
                              (“”, style: TextStyle(fontSize: 16.0, color: Colors.grey,),
                            ),
                          ],
                        ),
                        Expanded(child: Container()),
                        Text(“”, style: TextStyle(fontFamily: “c”,),
                        ),  ],
                    ),
                  ),
                ),

              ),
              Container(
              color: Colors.blue,
                width: double.infinity,
                child: Padding(
                  padding:  EdgeInsets.symmetric(horizontal: 16),
                  child: Row(
                    children: [
                      Image.asset(‘x’, height: 70, width: 70,),
                      SizedBox(width: 16,),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(‘x’, style: TextStyle(fontSize: 18, fontFamily: ‘x’),),
                          Text(datafromFirebase,TextStyle(fontSize: 16.0, color: Colors.grey,),
                          ),
                        ],
                      ),
                      Expanded(child: Container()),
                      Text(“”, style: TextStyle(fontFamily: “x”,),
                      ),  ],
                  ),
                ),

              ),
              Container(
                 color: Colors.blue,
                width: double.infinity,
                child: Padding(
                  padding:  EdgeInsets.symmetric(horizontal: 16),
                  child: Row(
                    children: [
                      Image.asset(‘z’, height: 70, width: 70,),
                      SizedBox(width: 16,),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(‘z’, style: TextStyle(fontSize: 18, fontFamily: ‘z’),),
                          Text(“Hello World“style: TextStyle(fontSize: 16.0, color: Colors.grey,),
                          ),
                        ],
                      ),
                      Expanded(child: Container()),
                      Text(“Hello World”, style: TextStyle(fontFamily: “z”,),
                      ),  ],
                  ),
                ),

              ),
              SizedBox(height: 22,),
              Padding(
                padding:  EdgeInsets.symmetric(horizontal: 16),
                child: Row(
                  children: [
                    Icon(),
                    SizedBox(width: 16,),
                    Text(‘blue’),
                    SizedBox(width: 5,),
                    Icon(),
                  ],

                ),
              ),
              SizedBox(height:  22,),
              Padding(padding: EdgeInsets.symmetric(horizontal: 16),
                child: ElevatedButton(
                  onPressed: (){
                    displayToastMessage(“x”, context);

                    setState(() {
                      state = “x”;
                    });
                    DisplayNewScreen();
                     

                  },
                  
                  style: ElevatedButton.styleFrom(
                    primary: Colors.red
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(25),
                    ),

                  ),
                  child:  Container(
                    height: 50,
                    child: Center(
                      child: Text(“x”,
                        style: TextStyle(fontSize: 18, ),
                    ),
                  ),




                  ),),
            ],
          ),
        ),
      ),
    ),
  ),
),

1 个答案:

答案 0 :(得分:0)

我不知道这是否有帮助,但据我所知,您的情况可能会通过此软件包 toggle_switch 解决。

希望能帮到你

相关问题