Skip to content

Instantly share code, notes, and snippets.

@rydmike

rydmike/main.dart

Last active Feb 28, 2021
Embed
What would you like to do?
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