KeyboardVisibilityController().isVisible always returns false (Android)
Describe the bug
I'm trying to use the Example #3 - Direct Query (without subscription). It always returns that the keyboard it not visible.
Example 1 and Example 2 seem to work fine.
To Reproduce
Open or close the keyboard by clicking the text field, or click the button. Observe that KeyboardVisibilityController().isVisible is always false.
import 'package:flutter/material.dart';
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// Always shows false
Text(
'Is keyboard visible? ${KeyboardVisibilityController().isVisible}',
),
ElevatedButton(
onPressed: () {
// Always prints false
print(
'Is keyboard visible? ${KeyboardVisibilityController().isVisible}');
setState(() {});
},
child: const Text('Button'),
),
// Just to show/hide the keyboard
const TextField(),
],
),
),
);
}
}
Expected behavior Return true when the keyboard is visible.
Info (please complete the following information):
flutter_keyboard_visibility version: 5.2.0
Reproducible on platforms (Android, iOS, etc): Android (emulator)
flutter doctor output:
x@x /tmp/ko> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.5, on macOS 11.6 20G165 darwin-x64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.67.1)
[✓] VS Code (version 1.66.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
Additional context N/A
Assume you have hard-refreshed the app, correct? This plugin uses channel methods and to sync them you need to hard-refresh and not just hot-reload.
am facing the same problem.
Assume you have hard-refreshed the app, correct? This plugin uses channel methods and to sync them you need to hard-refresh and not just hot-reload.
Yes.