I have a TextFormField widget but I don’t know why keyboard isn’t working in it!!
When pressing on the widget it shows the keyboard then close it immediately, and prints this messages in console:
D/InputConnectionAdaptor( 7900): The input method toggled cursor monitoring on
W/OnBackInvokedCallback( 7900): OnBackInvokedCallback is not enabled for the application.
Set ‘android:enableOnBackInvokedCallback="true"’ in the application manifest.
D/InputConnectionAdaptor( 7900): The input method toggled cursor monitoring off
and when I add that line to the androidmanifest, it doesn’t do any thing!!!
This is my code:
class SearchBox extends StatelessWidget {
const SearchBox({
super.key,
required this.controller,
});
final TextEditingController controller;
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.symmetric(
horizontal: Dimensions.widthPercentage(context, 10),
vertical: Dimensions.heightPercentage(context, 2)),
child: Container(
height: Dimensions.heightPercentage(context, 8),
decoration: BoxDecoration(
color: AppColors.whiteColor,
borderRadius: BorderRadius.circular(
Dimensions.radius(context, 2.55),
),
),
child: TextFormField(
controller: controller,
textInputAction: TextInputAction.none,
decoration: InputDecoration(
hintText: 'What do you like to eat today?'.tr,
hintStyle: TextStyle(
fontSize: Dimensions.fontSize(context, 3.75),
color: AppColors.hintSmallText,
fontFamily: 'ReadexPro',
),
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(
horizontal:
Dimensions.widthPercentage(context, 10),
vertical:
Dimensions.heightPercentage(context, 3),
),
suffixIcon: Padding(
padding: EdgeInsets.only(
right: Dimensions.widthPercentage(
context, 3)), // Adjust as needed
child: const Icon(
Icons.search,
color: Colors.black,
),
),
),
),
),
);
}
}
Update: here where I call this widget "SearchBox" in HomePage screen:
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
GlobalKey<ScaffoldState> homeKey = GlobalKey<ScaffoldState>();
return Obx(
() {
final controller = Get.find<HomePageController>();
return SafeArea(
child: Material(
child: Stack(
alignment: Alignment.bottomCenter,
children: [
Scaffold(
backgroundColor: AppColors.background,
key: homeKey,
body: ListView(
children: [
BigImage(
controller: controller.pageController,
length: controller.images.length,
listItem: controller.images,
hasText: false,
isHomePage: true,
),
SearchBox(
controller: controller.searchController,
),
],
),
),
Visibility(
visible: !isDrawerOpen.value,
child: BNBWidget(
scaffoldKey: homeKey,
cartStatus: controller.items.isNotEmpty,
onHomeTap: () {},
),
),
],
),
),
);
},
);
}
}
2
Answers
after changing the manifest file you should uninstall app and flutter clean, flutter pub get and finally flutter run.
This is a bug/behavior of the framework itself. I made something very very similar to yours and stumbled upon the same error. Mine was closing the keyboard and Reinitialized the whole screen, I was using BLoC pattern so it went hard to debug but I just figured out that MaterialPageRoute was the culprit.
So I replaced:
with: