auto_hide_keyboard 1.0.0 copy "auto_hide_keyboard: ^1.0.0" to clipboard
auto_hide_keyboard: ^1.0.0 copied to clipboard

Automatically hides the keyboard when tapping outside the TextField.

example/lib/main.dart

import 'package:example/widgets/simple_button.dart';
import 'package:example/widgets/simple_text_field.dart';
import 'package:flutter/material.dart';
import 'package:auto_hide_keyboard/auto_hide_keyboard.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'AutoHideKeyboard',
      home: Home(),
    );
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        appBar: AppBar(
          title: const Text('AutoHideKeyboard'),
          centerTitle: true,
          bottom: const TabBar(tabs: [
            Tab(text: 'Single'),
            Tab(text: 'Multi'),
          ]),
        ),
        body: const TabBarView(children: [
          SinglePage(),
          MultiPage(),
        ]),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          AutoHideKeyboard(
            child: const SimpleTextField(hint: 'TextField 0'),
          ),
          const SimpleButton(),
        ],
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          AutoHideKeyboard(
            child: const SimpleTextField(
              hint: 'TextField 1',
            ),
          ),
          Container(height: 24),
          AutoHideKeyboard(
            child: const SimpleTextField(
              hint: 'TextField 2',
            ),
          ),
          const SimpleButton(),
        ],
      ),
    );
  }
}
4
likes
150
pub points
71%
popularity

Publisher

verified publisherxbox.work

Automatically hides the keyboard when tapping outside the TextField.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, visibility_detector

More

Packages that depend on auto_hide_keyboard