Answers for "drop keyboard flutter"

0

remove focus textfield flutter

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        FocusScopeNode currentFocus = FocusScope.of(context);

        if (!currentFocus.hasPrimaryFocus) {
          currentFocus.unfocus();
        }
      },
      child: MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: MyHomePage(),
      ),
    );
  }
}
Posted by: Guest on June-27-2020
0

how i can close keyboard in flutter

class YourPage extends StatefulWidget {
  createState() => _YourPageState();
}

class _YourPageState extends State<MobileHome> {

  FocusNode focusNode = new FocusNode();
  @override
  Widget build(BuildContext context) {
  return Scaffold(
  	body: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        TextField(
          focusNode: focusNode,
        ),
        SizedBox(height: 10,),
        RaisedButton(child: Text("UP"),onPressed: (){
          FocusScope.of(context).requestFocus(focusNode);
        },),
        SizedBox(height: 10,),
        RaisedButton(child: Text("DOWN"),onPressed: (){
          focusNode.unfocus();
        },),    
      ],
    )
  );
  }
}
Posted by: Guest on November-09-2020

Browse Popular Code Answers by Language