代码之家  ›  专栏  ›  技术社区  ›  mvasco

带有地图和信息面板的应用程序屏幕应在按钮点击或向下滑动时隐藏和显示面板

  •  0
  • mvasco  · 技术社区  · 4 年前

    我正在开发一个新的Flutter项目,它应该在上半屏幕上显示一个谷歌地图,在下半屏幕上展示一个包含信息和操作的面板,就像你在屏幕截图上看到的那样:

    enter image description here

    我想创建一种方法来隐藏面板,并在用户点击关闭按钮或向下滑动面板时全屏显示地图,另一种方法是,用户应该能够点击按钮以获得初始视图。 这里是类的主体:

    body: Stack(
              children: [
                GoogleMap(
                  padding: EdgeInsets.only(bottom: bottomPaddingOfMap),
                  mapType: MapType.normal,
                  compassEnabled:true,
                    myLocationButtonEnabled: true,
                    myLocationEnabled: true,
                    zoomGesturesEnabled: true,
                    zoomControlsEnabled: true,
                    initialCameraPosition: _kGooglePlex,
                    onMapCreated: (GoogleMapController controller){
                    _controllerGoogleMap.complete(controller);
                    newGoogleMapController = controller;
    
                    setState(() {
                      bottomPaddingOfMap = 300.0;
                    });
    
                    locatePosition();
    
                    },
                ),
                //extra hamburger Drawer
                Positioned(
                  top: 45.0,
                  left: 22.0,
                  child: GestureDetector(
                    onTap: (){
                      scaffoldKey.currentState.openDrawer();
    
                    },
    
                    child: Container(
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(22.0),
                        boxShadow: [
                          BoxShadow(
                            color: Colors.black,
                            blurRadius: 6.0,
                            spreadRadius: 0.5,
                            offset: Offset(
                            0.7,
                            0.7,
                          ),
                          ),
                        ],
                      ),
                      child: CircleAvatar(
                        backgroundColor: Colors.white,
                        child: Icon(Icons.menu, color: Colors.black,),
                        ),
                      ),
                  ),
                  ),
                Positioned(
                  left: 0.0,
                  right: 0.0,
                    bottom: 0.0,
                  child: Container(
                    height: 350.0,
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.only(topLeft: Radius.circular(18.0), topRight: Radius.circular(18.0)),
                      boxShadow: [
                        BoxShadow(
                          color: Colors.black,
                          blurRadius: 16.0,
                          spreadRadius: 0.5,
                          offset: Offset(0.7, 0.7),
                        )
                      ]
                    ),
    
                    child:
    
                    Padding(
                      padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 18.0),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Center(
                            child: SizedBox(
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.end,
                                children: [
                                  RaisedButton.icon(
                                    icon: Icon(Icons.cake),
                                    label: Text("Close"),
    
                                    onPressed: (){
                                      print("pulsaado");
                                    },
                                  ),
                                ],
                              ),
                            ),
                          ),
                          SizedBox(height: 6.0,),
                          Text("Hi there!", style: TextStyle(fontSize: 18.0),),
    
                          Text("Where do you want to create an alert?", style: TextStyle(fontSize: 20.0, fontFamily: "Brand-Bold"),),
                          SizedBox(height: 20.0,),
                          Container(
                          decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius: BorderRadius.circular(5.0),
                              boxShadow: [
                                BoxShadow(
                                  color: Colors.black,
                                  blurRadius: 6.0,
                                  spreadRadius: 0.5,
                                  offset: Offset(0.7, 0.7),
                                ),
                              ],
                          ),
                            child: Padding(
                              padding: const EdgeInsets.all(12.0),
                              child: Row(
                                children: [
                                  Icon(Icons.search, color: Colors.blueAccent ),
                                  SizedBox(width: 10.0,),
                                  Text("Search Drop Off"),
                                ],
                              ),
                            ),
                          ),
                          SizedBox(height: 24.0,),
                          Row(
                            children: [
                              Icon(Icons.home, color: Colors.grey,),
                              SizedBox(width: 12.0,),
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Text("Add Home"),
                                    SizedBox(height: 4.0,),
                                    Text("Your living home address", style: TextStyle(color: Colors.black54, fontSize: 12.0),),
    
                                  ],
    
                              ),
                            ],
                          ),
                          SizedBox(height: 10.0,),
                          DividerWidget(),
                          SizedBox(height: 16.0,),
                          Row(
                            children: [
                              Icon(Icons.home, color: Colors.grey,),
                              SizedBox(width: 12.0,),
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Text("Add Work"),
                                  SizedBox(height: 4.0,),
                                  Text("Your office address", style: TextStyle(color: Colors.black54, fontSize: 12.0),),
    
                                ],
    
                              ),
                            ],
                          )
                        ],
                      ),
                    ),
                  ),
                ),
              ],
            ),
    

    我希望你能提出建议,以实现预期的行为。

    0 回复  |  直到 4 年前
        1
  •  1
  •   David Buck Richard Ferris    4 年前

    要做到这一点,你必须改变三件事: 首先,将无状态Widget转换为StatefulWidget; 其次,为容器的高度创建一个变量,并使用初始高度进行初始化; Thread,你必须用AnimatedContaire ad crate和onPressed函数来更改容器,如下所示:

    AnimatedContainer(
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(5.0),
          boxShadow: [
            BoxShadow(
              color: Colors.black,
              blurRadius: 6.0,
              spreadRadius: 0.5,
              offset: Offset(0.7, 0.7),
            ),
          ],
        ),
        duration: Duration(milliseconds: 1),
        height: heigntValue,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            SizedBox(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  RaisedButton(
                    onPressed: () {
                      setState(() {
                        if (heigntValue == 350) {
                          heigntValue -= 300;
                        } else {
                          heigntValue += 300;
                        }
                        print(heigntValue);
                      });
                    },
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    
        2
  •  0
  •   bluenile    4 年前

    我没有显示“关闭”,而是显示了一些表示向下滑动的内容

    ▼ ==== ▼
    

    ▲ ==== ▲
    

    向上滑动