flutter_keyboard_scroll 1.0.22 copy "flutter_keyboard_scroll: ^1.0.22" to clipboard
flutter_keyboard_scroll: ^1.0.22 copied to clipboard

A plugin for keyboard show listen. and scroll the widget to the top of the keyboard.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter_keyboard_scroll/keyboard_observer.dart';
import 'package:flutter_keyboard_scroll/keyboard_scroll.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  ///底部
  double _marginBottom = 0;

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {}

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        resizeToAvoidBottomInset: false,
        appBar: AppBar(
          title: GestureDetector(
            behavior: HitTestBehavior.translucent,
            onTap: () {
              FocusScope.of(context).requestFocus(FocusNode());
            },
            child: const Text('Plugin example app'),
          ),
        ),
        body: KeyboardObserver(
          showListener: (double former, double newer, int time) {
            print("AAA:::$newer");
          },
          hideListener: (double former, double newer, int time) {
            print("BBB:::$newer");
          },
          showAnimationListener: (value, flag) {
            print("AAAA:::$value Flag:$flag");
            setState(() {
              _marginBottom = value;
            });
          },
          hideAnimationListener: (value, flag) {
            print("BBBB:::$value Flag:$flag");
            setState(() {
              _marginBottom = value;
            });
          },
          animationMode: KeyboardAnimationMode.mediaQuery,
          child: Container(
            width: double.infinity,
            height: double.infinity,
            alignment: Alignment.bottomCenter,
            child: Container(
              width: MediaQuery.of(context).size.width,
              decoration: const BoxDecoration(
                color: Colors.red,
              ),
              margin: EdgeInsets.fromLTRB(0, 0, 0, _marginBottom),
              height: 45,
              child: const TextField(
                textAlign: TextAlign.center,
                decoration: InputDecoration(
                  hintText: "Input your words",
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
1
likes
150
points
117
downloads

Publisher

unverified uploader

Weekly Downloads

A plugin for keyboard show listen. and scroll the widget to the top of the keyboard.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_keyboard_scroll

Packages that implement flutter_keyboard_scroll