Skip to content

Instantly share code, notes, and snippets.

@rydmike
Last active February 28, 2021 22:04
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 rydmike/4a24276592bf0bf0657b2de5b49e7c0d to your computer and use it in GitHub Desktop.
Save rydmike/4a24276592bf0bf0657b2de5b49e7c0d to your computer and use it in GitHub Desktop.
CTRL-V paste shortcut throws in Flutter Windows
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