Skip to content

Instantly share code, notes, and snippets.

@iampawan
Created December 6, 2019 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iampawan/efeff11154c6eba795ddf37730263968 to your computer and use it in GitHub Desktop.
Save iampawan/efeff11154c6eba795ddf37730263968 to your computer and use it in GitHub Desktop.
Keyboard freeze issue.
import 'package:flutter/material.dart';
class AliceExample extends StatefulWidget {
@override
_AliceExampleState createState() => _AliceExampleState();
}
class _AliceExampleState extends State<AliceExample> {
TextEditingController _textController;
FocusNode focusNode;
@override
void initState() {
super.initState();
_textController = TextEditingController();
focusNode = FocusNode();
}
_onTextChanged() {
_textController.text = "";
}
@override
Widget build(BuildContext context) {
print("Restarted");
// var cursorPos = new TextSelection.fromPosition(new TextPosition(offset: 0));
// _textController.selection = cursorPos;
_textController.addListener(_onTextChanged);
return Scaffold(
appBar: AppBar(
title: Text("Network Tool"),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
TextField(
maxLength: 2,
controller: _textController,
onChanged: (String str) {
focusNode.unfocus();
},
focusNode: focusNode,
)
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment