keyboard 0.0.1 copy "keyboard: ^0.0.1" to clipboard
keyboard: ^0.0.1 copied to clipboard

outdated

Flutter plugin to detect keyboard events.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:keyboard/keyboard.dart';
import 'package:flutter/scheduler.dart';

void main() {
  Keyboard.init();
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final events = <String>["(Start pressing keys to see events)"],
      controller = ScrollController();

  @override
  void initState() {
    super.initState();
    Keyboard.onKeyDown = (code, event) {
      if (!mounted) return;
      setState(() {
        events.add("OnKeyDown: $code\n$event");
      });
      SchedulerBinding.instance.addPostFrameCallback((_) {
        controller.jumpTo(controller.position.maxScrollExtent);
      });
    };
  }

  @override
  void dispose() {
    Keyboard.onKeyDown = null;
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Keyboard Plugin'),
        ),
        body: ListView(
          shrinkWrap: true,
          controller: controller,
          children: events.map((it) {
            return ListTile(
              title: Card(
                child: Text(
                  it,
                  textAlign: TextAlign.center,
                ),
              ),
            );
          }).toList(),
        ),
      ),
    );
  }
}
6
likes
0
points
18
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter plugin to detect keyboard events.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on keyboard