Last active
February 28, 2021 22:04
-
-
Save rydmike/4a24276592bf0bf0657b2de5b49e7c0d to your computer and use it in GitHub Desktop.
CTRL-V paste shortcut throws in Flutter Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
title: 'Text Edit', | |
home: _TextFieldExample(), | |
); | |
} | |
} | |
class _TextFieldExample extends StatefulWidget { | |
@override | |
_TextFieldExampleState createState() => _TextFieldExampleState(); | |
} | |
class _TextFieldExampleState extends State<_TextFieldExample> { | |
final FocusNode _focusNode = FocusNode(); | |
final TextEditingController _textController = TextEditingController(); | |
@override | |
void initState() { | |
_textController.text = 'Some text'; | |
super.initState(); | |
} | |
@override | |
void dispose() { | |
_focusNode.dispose(); | |
_textController.dispose(); | |
super.dispose(); | |
} | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Paste error demo'), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
ElevatedButton( | |
onPressed: () { | |
_textController.text = 'Set by button'; | |
_focusNode.requestFocus(); | |
}, | |
child: Text('Set focus and value'), | |
), | |
SizedBox(height: 8), | |
SizedBox( | |
width: 400, | |
child: TextField( | |
controller: _textController, | |
focusNode: _focusNode, | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment