keyboard_avoider 0.1.1 copy "keyboard_avoider: ^0.1.1" to clipboard
keyboard_avoider: ^0.1.1 copied to clipboard

outdated

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

example/lib/main.dart

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
   return new MaterialApp(home: Scaffold(body: Test(), resizeToAvoidBottomPadding: false));
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        Flexible(
          flex: 1,
          child: Column(
            children: <Widget>[
              Flexible(flex: 2, child: _buildPlaceholder(Colors.red)),
              Flexible(flex: 1, child: _buildPlaceholder(Colors.pink)),
            ],
          ),
        ),
        Flexible(
          flex: 2,
          child: Column(
            children: <Widget>[
              Flexible(flex: 2, child: _buildForm(40, Colors.green)),
              Flexible(flex: 1, child: GestureDetector(onTap: () => _onTap(context), child: _buildPlaceholder(Colors.lightGreen)),
              ),
            ],
          ),
        ),
        Flexible(
          flex: 1,
          child: Column(
            children: <Widget>[
              Flexible(flex: 1, child: _buildPlaceholder(Colors.blue)),
              Flexible(flex: 2, child: _buildPlaceholder(Colors.lightBlue)),
            ],
          ),
        ),
      ],
    );
  }

  void _onTap(BuildContext context)
  {
    Navigator.of(context).pushReplacement(new MaterialPageRoute(builder: (_) => new Container(color: Colors.white)));
  }

  Widget _buildForm(int rows, Color color) {
    return Container(
      color: color,
      child: KeyboardAvoider(
        autoScroll: true,
        child: ListView.builder(
          padding: EdgeInsets.zero,
          controller: _scrollController,
          itemCount: rows,
          itemBuilder: (context, index) {
            return Material(
              child: TextFormField(
                initialValue: 'TextFormField ${index + 1}',
                decoration: InputDecoration(fillColor: color, filled: true),
              ),
            );
          },
        ),
      ),
    );
  }

  Widget _buildPlaceholder(Color color) {
    return Container(
      color: color,
      child: KeyboardAvoider(
        child: Placeholder(),
      ),
    );
  }
}
113
likes
40
pub points
88%
popularity

Publisher

verified publishermartinrybak.com

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

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on keyboard_avoider