skip to Main Content

i got stuck while creating app, when i tap on textfield , the keyboard hide textfild , i used SingleChildScrollView and Padding but nothing happend, i dont know what exactly happened ,that keyboard hides textfield

here is my code

mobileView() {


    return Column(

      children: [
        Expanded(
          child: BlocListener<IndexStackBloc, IndexStackState>(
            listenWhen: (previousState, currentState) =>
                currentState != previousState,
            listener: (context, state) {
              if (state is LoadingState) {
                isLoadingSubCategory = true;
              }
              if (state is SearchSubCategoryResultState) {
                isLoadingSubCategory = false;
              }
              if (state is NoResultState) {
                isLoadingSubCategory = false;
              }
            },
            child:  SingleChildScrollView(
              child: Container(
                height: 500,
                child: IndexedStack(
                  index: _selectedIndexStack,
                  children: [
                    pAccountListView(),
                    accountCategorySearch(),
                    subAccountCategorySearch(),
                  ],
                ),
              ),
            ),)
        ),
        Divider(
          height: 1,
          color: Theme.of(context).dividerColor,
        ),
        actionBar(),
      ],
    );

 }

and actionbar is

actionBar() {
return Container(
  decoration: BoxDecoration(color: Theme.of(context).canvasColor),
  child: Column(
    children: [
      Container(
        // margin: paddingAll(),
        decoration: BoxDecoration(
            color:
                _isActionbarOpened ? Theme.of(context).canvasColor : null,
            borderRadius: BorderRadius.circular(defaultPadding * 5)),
        child: _isActionbarOpened
            ? InkWell(
                onTap: () {
                  setState(() {
                    if (_isActionbarOpened) {
                      _isActionbarOpened = false;
                    } else {
                      _isActionbarOpened = true;
                    }
                  });
                },
                child: Container(
                  height: 5.sp,
                ))
            : TextButton(
                onPressed: () {
                  setState(() {
                    if (_isActionbarOpened) {
                      _isActionbarOpened = false;
                    } else {
                      _isActionbarOpened = true;
                    }
                    if (_searchAccountController.text.isNotEmpty) {
                      setState(() {
                        _searchAccountController.text = '';
                        _focuseNodeSearchAccount.unfocus();
                      });
                    }
                    setState(() {
                      _selectedIndexStack = 1;
                      _focuseNodeCategory.requestFocus();
                    });
                  });
                },
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    const Icon(Icons.edit),
                    wSpacer(),
                    Text(
                      'write_account'.tr(),
                      style: Theme.of(context).textTheme.titleLarge,
                    ),
                  ],
                ),
              ),
      ),
      Visibility(
        visible: _isActionbarOpened,
        child: Container(
          padding: paddingAll(),
          margin: EdgeInsets.only(bottom: defaultPadding),
          decoration: BoxDecoration(color: Theme.of(context).canvasColor),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Row(
                children: [
                  Expanded(
                      child: appTextFiled(
                          controller: categoryController,
                          focusNode: _focuseNodeCategory,
                          context: context,
                          label: 'account_name'.tr(),
                          hint: 'e.g .. Home Expanse',
                          style: Theme.of(context).textTheme.labelMedium,
                          onChanged: (value) async {
                            List<Map<String, dynamic>> result =
                                await dbServices.searchCategory(
                                    category: value);
                            setState(() {
                              if (_selectedIndexStack != 1) {
                                _selectedIndexStack = 1;
                              }
                              categories = [];
                              categories.addAll(result);
                            });
                          },
                          onTap: () {
                            setState(() {
                              _selectedIndexStack = 1;
                              isCategorySelected = false;
                              isSubCategorySelected = false;
                              subCategoryController.text = '';
                              amountController.text = '';

                            });
                          })),
                  wSpacer(),
                  Expanded(
                    child: appTextFiled(
                        controller: subCategoryController,
                        context: context,
                        isDisable: isCategorySelected,
                        focusNode: _focuseNodeSubCategory,
                        style: Theme.of(context).textTheme.labelMedium,
                        label: 'sub_account'.tr(),
                        hint: 'e.g., Vegetable',
                        onChanged: (value) async {
                          setState(() {
                            if (_selectedIndexStack != 2) {
                              _selectedIndexStack = 2;
                            }
                          });

                          context.read<IndexStackBloc>().add(
                              SearchSubCategoryByCategoryIdAndNameEvent(
                                  categoryId: _selectedCategoryId,
                                  categoryName: value));
                        },
                        onTap: () {
                          setState(() {
                            _selectedIndexStack = 2;
                          });
                        }),
                  ),
                ],
              ),
              if (_selectedSubCategoryType == 2 && isSubCategorySelected)
                ToggleSwitch(
                  minWidth: 50.sp,
                  initialLabelIndex: _transactionTypeIndex,
                  cornerRadius: 20.0,
                  activeFgColor: Colors.white,
                  inactiveBgColor: Colors.grey,
                  inactiveFgColor: Colors.white,
                  totalSwitches: 2,
                  icons: const [Icons.add, Icons.remove],
                  borderColor: const [Colors.white54],
                  borderWidth: 4,
                  onToggle: (index) {
                    setState(() {
                      _transactionTypeIndex = index!;
                      // index == 0 ? isIncome = true : isIncome = false;
                    });
                  },
                ),
              hSpacer(),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  wSpacer(),
                  Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      InkWell(
                          onDoubleTap: () {
                            setState(() {
                              _isDatetimeSelected = false;
                            });
                          },
                          onLongPress: () {
                            setState(() {
                              _isDatetimeSelected = false;
                            });
                          },
                          onTap: () async {
                            if (isSubCategorySelected == true) {
                              DateTime? datetime =
                                  await getMyDate(context: context);
                              if (datetime != null) {
                                setState(() {
                                  _isDatetimeSelected = true;
                                  _selectedDateTime = datetime;
                                });
                              } else {
                                print('nul');
                              }
                            }
                          },
                          child: Icon(
                            Icons.timer_outlined,
                            color: _isDatetimeSelected
                                ? Colors.yellow
                                : Theme.of(context).iconTheme.color,
                          )),
                      Text(
                        'time'.tr(),
                        style: appTextStyle(
                            size: fsizeSmallTo,
                            color: secondaryColor,
                            weight: FontWeight.w600),
                      )
                    ],
                  ),
                  wSpacer(),
                  Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      InkWell(
                          onLongPress: () {
                            setState(() {
                              _isNoteCreated = false;
                              _createNoteIs = '';
                            });
                          },
                          onTap: () async {
                            if (isSubCategorySelected == true) {
                              String getNote =
                                  await _showCreateNoteDialoge() ?? '';
                              if (getNote.isNotEmpty) {
                                setState(() {
                                  _createNoteIs = getNote;
                                  _isNoteCreated = true;
                                });
                              }
                            }
                          },
                          child: Icon(
                            Icons.note_add,
                            color: _isNoteCreated
                                ? Colors.yellow
                                : Theme.of(context).iconTheme.color,
                          )),
                      Text(
                        'note'.tr(),
                        style: appTextStyle(
                            size: fsizeSmallTo,
                            color: secondaryColor,
                            weight: FontWeight.w600),
                      )
                    ],
                  ),
                  wSpacer(),
                  Expanded(
                      child: appTextFiled(
                          controller: amountController,
                          context: context,
                          maxLength: 12,
                          isDisable: isSubCategorySelected,
                          type: TextInputType.number,
                          focusNode: _focuseNodeAmount,
                          style: Theme.of(context).textTheme.labelMedium,
                          onChanged: (v) {
                            if (_selectedIndexStack != 0) {
                              setState(() {
                                _selectedIndexStack = 0;
                              });
                            }
                          },
                          onTap: () {
                            if (_selectedIndexStack != 0) {
                              setState(() {
                                _selectedIndexStack = 0;
                              });
                            }
                          },
                          label: 'amount'.tr())),
                  FloatingActionButton(
                    mini: true,
                    backgroundColor: _transactionTypeIndex == 0
                        ? Colors.green
                        : Colors.red,
                    onPressed: () {
                      // dbServices.addCategory(name: categoryController, type: 'both', transType: 'minus');
                      // dbServices.deleteAllData();
                      saveAccounts();
                    },
                    child: Icon(_transactionTypeIndex == 0
                        ? Icons.add
                        : Icons.remove),
                  )
                ],
              ),
            ],
          ),
        ),
      ),
    ],
  ),
);
}

please help me about this,

2

Answers


  1. Check in your code have you used this "//ignore: must_be_immutable" comment any where. If yes then remove it, because it prevent class to update it’s state.

    Login or Signup to reply.
  2. Just use resizeToAvoidBottomInset in Scaffold

    like :
    Scaffold(
    resizeToAvoidBottomInset: true,
    )

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search