Buscar pacotes, repositórios e categorias de apps

Repositório GitHubmartinrybak/keyboard_avoider

evitador de teclado

Uma alternativa leve ao widget Scaffold para evitar o teclado de software na tela. Rolagem automática dos filhos TextField obscurecidos para a visão ao foco.

Capa do projeto evitador de teclado
Estrelas
124
Forks
41
Último push (UTC)
15 de mai. de 2024
Status do projeto
Ativo

README original

Texto original em inglês. Visite o GitHub para a versão atual.

keyboard_avoider

A lightweight alternative to the Scaffold widget for avoiding the on-screen software keyboard. Automatically scrolls obscured TextField child widgets into view on focus.

In the video above, every colored area is wrapped in its own KeyboardAvoider.

Examples

A basic Placeholder:

import 'package:keyboard_avoider/keyboard_avoider.dart';

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return KeyboardAvoider(
      child: Placeholder(),
    );
  }
}

A ListView containing multiple TextFields, with auto-scroll enabled:

import 'package:keyboard_avoider/keyboard_avoider.dart';

class MyWidget extends StatelessWidget {
  final ScrollController _scrollController = ScrollController();

  @override
  Widget build(BuildContext context) {
    return KeyboardAvoider(
      autoScroll: true,
      child: ListView.builder(
        controller: _scrollController,
        itemCount: 40,
        itemBuilder: (context, index) {
          return TextFormField(
            initialValue: 'TextFormField ${index + 1}',
          );
        },
      ),
    );
  }
}

Why not use a Scaffold?

Flutter comes with a built-in Scaffold widget that automatically adjusts the bottom padding of its body widget to accomodate the on-screen keyboard. However, it comes with 2 major caveats:

  1. It pushes all content up, which you may not want.
  2. It assumes that it fills the whole screen, which it may not.

In contrast, you can apply the KeyboardAvoider selectively to only certain widgets, and it only insets its bottom padding by the actual amount obscured by the keyboard.

Auto Scroll

To auto-scroll to a focused widget such as a TextField, set the autoScroll property to true. If child is not a ScrollView, it is automatically embedded in a SingleChildScrollView to make it scrollable.

Martin Rybak GitHub avatar
Autor no GitHub

Martin Rybak ↗

Very Good VenturesNew York, NY
LinguagensC++CMakeDartSwiftCHTMLKotlinObjective-C

Dependências usadas

Lista de dependências 3 itens

  • flutter{"sdk":"flutter"}
  • flutter_testDesenvolvimento{"sdk":"flutter"}
  • flutter_lintsDesenvolvimento^4.0.0

Como escolher um repositório para seu projeto?

Filtre pelo caso de uso, compare a atividade e confira o projeto original antes de adotá-lo.

  1. Busque por nome, autor ou descrição e filtre por tema.
  2. Compare estrelas, forks e envios recentes. Estrelas indicam interesse, mas não garantem qualidade.
  3. Confira o README, a licença e as issues no GitHub antes de usar o projeto.

Fontes e manutenção

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗