show method

dynamic show(
  1. BuildContext context
)

Implementation

show(BuildContext context) {
  var _list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0];
  int length = value!.length;
  List<String?> _codeList = [...value!.split("")];

  Widget buildTitle() {
    return (title != null || closeButtomText != null)
        ? Container(
            padding: Style.numberKeyboardTitlePadding,
            decoration: BoxDecoration(
                color: Style.numberKeyboardBackgroundColor,
                border: Border(
                    bottom: BorderSide(
                        width: Style.borderWidthBase,
                        color: Style.borderColor))),
            child: Row(
              mainAxisAlignment: closeButtomText != null
                  ? MainAxisAlignment.spaceBetween
                  : MainAxisAlignment.center,
              children: <Widget>[
                title != null
                    ? Text(
                        title!,
                        style: TextStyle(
                          fontSize: Style.numberKeyboardTitleFontSize,
                          color: Style.numberKeyboardTitleTextColor,
                        ),
                      )
                    : Container(),
                closeButtomText != null
                    ? GestureDetector(
                        child: Text(closeButtomText!,
                            style: TextStyle(
                                fontSize: Style.numberKeyboardCloseFontSize,
                                color: Style.numberKeyboardCloseColor)),
                        onTap: () {
                          Navigator.pop(context);
                          if (onClose != null) onClose!();
                        },
                      )
                    : Container(),
              ],
            ),
          )
        : Container();
  }

  GridView buildKeyBoard() {
    return GridView.builder(
        shrinkWrap: true,
        physics: NeverScrollableScrollPhysics(),
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 3,
          childAspectRatio: 2.5,
          mainAxisSpacing: Style.numberKeyboardNumSpacing,
          crossAxisSpacing: Style.numberKeyboardNumSpacing,
        ),
        itemCount: 12,
        itemBuilder: (_, index) {
          return Material(
            color: (index == 9 || index == 11)
                ? Style.numberKeyboardKeyBackground
                : Colors.white,
            child: InkWell(
              child: Center(
                child: index == 11
                    ? Text(showDeleteKey ? deleteButtonText : "",
                        style: TextStyle(
                            fontSize: Style.numberKeyboardDeleteFontSize))
                    : index == 9
                        ? Text(extraKey ?? "",
                            style: TextStyle(
                                fontSize: Style.numberKeyboardDeleteFontSize))
                        : Text(_list[index].toString(),
                            style: TextStyle(
                                fontSize: Style.numberKeyboardKeyFontSize)),
              ),
              onTap: () {
                if (index == 9 && extraKey == null ||
                    index == 9 &&
                        extraKey != null &&
                        _codeList.contains(extraKey) ||
                    (index == 11 && !showDeleteKey)) return;
                if (index == 11 && showDeleteKey) {
                  if (length == 0) return;
                  _codeList.removeLast();
                  length--;
                } else {
                  if (maxlength != null && _codeList.length == maxlength)
                    return;
                  _codeList.add(index == 9 && extraKey != null
                      ? extraKey
                      : _list[index].toString());
                  length++;
                }
                String code = "";
                for (int i = 0; i < _codeList.length; i++) {
                  code = code + _codeList[i].toString();
                }
                if (onChange != null) onChange!(code);
                if (maxlength != null &&
                    _codeList.length == maxlength &&
                    onSubmitted != null) {
                  onSubmitted!(code);
                }
              },
            ),
          );
        });
  }

  return showBottomSheet(
      context: context,
      backgroundColor: Style.numberKeyboardKeyBackground,
      builder: (BuildContext context) {
        return Container(
          decoration: BoxDecoration(
              border: Border(
                  top: BorderSide(
                      width: Style.borderWidthBase,
                      color: Style.borderColor))),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[buildTitle(), buildKeyBoard()],
          ),
        );
      });
}