Flutter Cupertino文本字段在聚焦时会重建页面

时间:2019-04-09 11:40:08

标签: dart flutter flutter-cupertino

我曾经在单页中使用它而没有任何问题,但是现在我尝试使用bottomtabbar小部件来实现,并且当我触摸到textfield区域时,该字段将聚焦并重建而没有任何错误消息或警告。

有一个gif,描述了我所面对的 http://www.giphy.com/gifs/Rf4SAqekKuvXFTSn6U

//here is my cupertino textfield that i have widgetized to use it many //places

Widget build(BuildContext context) {

    return Container(
      height: 48,
      padding: EdgeInsets.only(left: 8, right: 8, top: 6, bottom: 6),
      child: Form(
        child: CupertinoTextField(
          key: CustomSearchBar._orderFormKey,
          placeholder: this.widget.placeholder,
          cursorColor: Colors.black,
          maxLines: 1,
          controller: this.widget.controller,
          focusNode: this.widget.focusNode,
          maxLength: 10,
          suffixMode: OverlayVisibilityMode.editing,
          prefix: Padding(
            padding: const EdgeInsets.only(right: 2, left: 8),
            child: Icon(
              Icons.search,
              size: 20,
              color: Colors.black54,
            ),
          ),
          onSubmitted: this.widget.onSubmitted,
          textInputAction: TextInputAction.search,
          suffix: Padding(
            padding: EdgeInsets.only(left: 0, right: 0),
            child: IconButton(
              icon: Icon(
                Icons.cancel,
                color: Colors.black38,
                size: 20,
              ),
              onPressed: this.widget.onClearPressed,
              padding: EdgeInsets.all(0),
              splashColor: Colors.transparent,
              iconSize: 20,

              highlightColor: Colors.transparent,
            ),
          ),
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(16),
              border: Border.all(color: Colors.black26)),
        ),
      ),
    );


     }




    /*and this one is where i call the textfield widget on the upper code*/

    Widget build(BuildContext context) {
        return Scaffold(
          resizeToAvoidBottomPadding: false,
          drawer: HomeDrawer(),
          body: Container(
            width: double.infinity,
            height: double.infinity,
            child: Column(
              children: <Widget>[
                CustomSearchBar(
                  controller: _searchTextController,
                  focusNode: _searchFocusNode,
                  onSubmitted: (String text) {
                    if (text.length > 0 && text.isNotEmpty) {
                      setState(
                        () {
                          searchText = text.trim();
                          searchOffers();
                        },
                      );
                    }
                  },
                  placeholder: 'Birşeyler yazın ve ara butonuna dokunun',
                  onClearPressed: () {
                    _searchFocusNode.unfocus();
                    _searchTextController.clear();
                    queryDetails = '';
                    getOffers();
                  },
                ),
                _queryDetails(),
                Expanded(
                  child: _renderPage(),
                ),
              ],
            ),
          ),
        );
   }

0 个答案:

没有答案