jh_keyboard_helper 0.1.0 copy "jh_keyboard_helper: ^0.1.0" to clipboard
jh_keyboard_helper: ^0.1.0 copied to clipboard

Predictable keyboard visibility, dismissal, barriers, and layout helpers for Flutter applications.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:jh_keyboard_helper/jh_keyboard_helper.dart';
import 'package:shared_preferences/shared_preferences.dart';

const _keyboardHeightKey = 'keyboard_height';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  final preferences = await SharedPreferences.getInstance();
  final cachedHeight = preferences.getDouble(_keyboardHeightKey) ?? 0;

  runApp(
    KeyboardBuilder(
      initialHeight: cachedHeight,
      onHeightSettled: (height) async {
        await preferences.setDouble(_keyboardHeightKey, height);
      },
      child: const ExampleApp(),
    ),
  );
}

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(colorSchemeSeed: Colors.indigo),
      home: const KeyboardExamplePage(),
    );
  }
}

class KeyboardExamplePage extends StatelessWidget {
  const KeyboardExamplePage({super.key});

  @override
  Widget build(BuildContext context) {
    return KeyboardDismissOnTap(
      child: Scaffold(
        appBar: AppBar(title: const Text('Keyboard helper')),
        body: KeyboardBarrier(
          child: const Padding(
            padding: EdgeInsets.all(24),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                TextField(
                  decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    labelText: 'Tap to show the keyboard',
                  ),
                ),
                SizedBox(height: 16),
                _KeyboardStatus(),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class _KeyboardStatus extends StatelessWidget {
  const _KeyboardStatus();

  @override
  Widget build(BuildContext context) {
    return ValueListenableBuilder<double>(
      valueListenable: KeyboardManager.instance.height,
      builder: (context, height, child) {
        return Text('Keyboard height: ${height.toStringAsFixed(1)}');
      },
    );
  }
}
0
likes
160
points
57
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Predictable keyboard visibility, dismissal, barriers, and layout helpers for Flutter applications.

Repository (GitHub)
View/report issues

Topics

#keyboard #focus #layout #widget

License

MIT (license)

Dependencies

flutter

More

Packages that depend on jh_keyboard_helper