unfocus_widget 0.0.8
unfocus_widget: ^0.0.8 copied to clipboard
Useful widget for unfocusing the TextField when touching outside
unfocus_widget #
Wrap your UI with UnFocusWidget so tapping outside TextFields dismisses the keyboard.
Add the dependency #
dependencies:
unfocus_widget: <latest>
dart pub add unfocus_widget
Use it #
import 'package:unfocus_widget/unfocus_widget.dart';
Put it around the area that should receive “outside” taps—usually Scaffold.body:
Scaffold(
body: UnFocusWidget(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
TextField(decoration: InputDecoration(labelText: 'Email')),
TextField(decoration: InputDecoration(labelText: 'Password')),
],
),
),
),
);
With a scrollable form, wrap the scroll view:
body: UnFocusWidget(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
children: [
// TextFields...
],
),
),
),
Run the demo: cd example && flutter run
Repository: https://github.com/thomas-p95/unfocus_widget