【flutter】下部弹出组件

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/ivy_doudou/article/details/96431650
/**
   * 下部弹出框
   */
  Future<void> _bottomSheet(BuildContext context) async {
    return showModalBottomSheet(
      context: context,
      builder: (BuildContext context) {
        return _bottomSheetBody();
      },
    );
  }

  /**
   * 底部弹出
   */
  Widget _bottomSheetBody() {
    return Container(
      height: 215.0,
      child: Column(
        children: <Widget>[
          Container(
              color: Color.fromARGB(50, 180, 180, 180),
              margin: EdgeInsets.fromLTRB(0, 0, 0, 5),
              height: 50,
              child: Center(
                child: Text(
                  "操作",
                  style: TextStyle(
                      fontSize: 16.0,
                      color: Color.fromARGB(255, 180, 180, 180)),
                ),
              )),
          _buttom_Text(
              40.0,
              "                             摄像头                            ",
              "Camera",
              color_public),
          Divider(),
          _buttom_Text(
              40.0,
              "                             本地相册                             ",
              "Local",
              Colors.red),
          Container(
            width: MediaQuery.of(context).size.width,
            height: 10.0,
            color: Color.fromARGB(50, 180, 180, 180),
          ),
          _buttom_Text(
              40.0,
              "                             取消                             ",
              "Cancel",
              Colors.black),
        ],
      ),
    );
  }

  /**
   * 下部弹出普通组件
   */
  _buttom_Text(double heigh, String text, String type, Color color) {
    return GestureDetector(
        onTap: () {
          switch (type) {
            case "Camera":
              {
                //摄像头
                Navigator.of(context).pop();
                getImage(type);
                /*Navigator.of(context).push(
                  CustomRoute(EditGreenhouse(id: id), customRoute));*/
                break;
              }
            case "Local":
              {
                //本地
                Navigator.of(context).pop();
                getImage(type);
                /*Navigator.of(context).push(
                  CustomRoute(EditPlant(id: id), customRoute));*/
                break;
              }
            case "Cancel":
              {
                //取消
                Navigator.of(context).pop();
                break;
              }
          }
        },
        child: Container(
          height: heigh,
          width: MediaQuery.of(context).size.width,
          child: Center(
            child: Text(
              text,
              style: TextStyle(fontSize: 16.0, color: color),
            ),
          ),
        ));
  }

猜你喜欢

转载自blog.csdn.net/ivy_doudou/article/details/96431650