Skip to content

Instantly share code, notes, and snippets.

@r100-stack
Created March 11, 2021 02:31
Show Gist options
  • Save r100-stack/d2c60e93f939558d71d6879246dcf1ec to your computer and use it in GitHub Desktop.
Save r100-stack/d2c60e93f939558d71d6879246dcf1ec to your computer and use it in GitHub Desktop.
Hide keyboard in TextFormField
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.red,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Hide keyboard in TextFormField'),
),
body: Form(
child: Column(
children: [
TextFormField(),
TextButton(
onPressed: () => FocusScope.of(context).unfocus(),
child: Text('Hide keyboard'),
)
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment