keyboard_insets 0.1.2 copy "keyboard_insets: ^0.1.2" to clipboard
keyboard_insets: ^0.1.2 copied to clipboard

A Flutter plugin that provides real-time keyboard height and visibility state across platforms.

example/lib/main.dart

import 'dart:math';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:keyboard_insets/keyboard_insets.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    PersistentSafeAreaBottom.startObserving();
    PersistentSafeAreaBottom.notifier?.addListener(printSafeAreaBottom);
    KeyboardInsets.stateStream.listen((event) {
      if (kDebugMode) {
        print(
            'Keyboard height: ${event.isAnimating} v=${event.isVisible} ${KeyboardInsets.keyboardHeight}');
      }
    });
  }

  @override
  void dispose() {
    PersistentSafeAreaBottom.notifier?.removeListener(printSafeAreaBottom);
    PersistentSafeAreaBottom.stopObserving();
    super.dispose();
  }

  void printSafeAreaBottom() {
    if (kDebugMode) {
      print('Safe area height: ${PersistentSafeAreaBottom.notifier?.value}');
    }
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    const textStyle = TextStyle(fontSize: 16);

    return MaterialApp(
      home: Material(
        child: StreamBuilder(
          stream: KeyboardInsets.insets,
          builder: (context, snapshot) {
            return Stack(
              children: [
                Align(
                  alignment: Alignment.bottomCenter,
                  child: Container(
                    height: PersistentSafeAreaBottom.notifier?.value ?? 0.0,
                    width: double.infinity,
                    margin: EdgeInsets.only(
                      bottom: max(0, (snapshot.data ?? 0)),
                    ),
                    color: Colors.red,
                  ),
                ),
                Center(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Padding(
                        padding: const EdgeInsets.only(left: 40.0),
                        child: Text(
                          'insets: ${snapshot.data}',
                          style: textStyle,
                        ),
                      ),
                      const SizedBox(height: 16),
                      Padding(
                        padding: const EdgeInsets.symmetric(horizontal: 40),
                        child: TextField(
                          decoration: const InputDecoration(
                            border: OutlineInputBorder(),
                            labelText: 'Focus to see view inset change',
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            );
          },
        ),
      ),
    );
  }
}
1
likes
160
points
188
downloads

Publisher

verified publisher2gis.ru

Weekly Downloads

A Flutter plugin that provides real-time keyboard height and visibility state across platforms.

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

BSD-2-Clause (license)

Dependencies

flutter, keyboard_insets_mobile, keyboard_insets_platform_interface, keyboard_insets_web

More

Packages that depend on keyboard_insets

Packages that implement keyboard_insets