Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyboardVisibilityController().isVisible always returns false (Android) #110

Open
aemelyanovff opened this issue May 10, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@aemelyanovff
Copy link

aemelyanovff commented May 10, 2022

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

@aemelyanovff aemelyanovff added the bug Something isn't working label May 10, 2022
@zvikarp
Copy link

zvikarp commented May 22, 2022

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.

@delltrak
Copy link

am facing the same problem.

@aemelyanovff
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants