From 2c9873c64292e27753a58eb508f997ce734aabdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Ma=C3=B1osa?= Date: Wed, 5 Apr 2023 01:15:29 +0200 Subject: [PATCH] feat(name_section): select all text on focus (#7) --- lib/widgets/name_section.dart | 8 ++++++++ lib/widgets/name_shelf.dart | 22 +++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/widgets/name_section.dart b/lib/widgets/name_section.dart index 9e71b85..a7dbfb2 100644 --- a/lib/widgets/name_section.dart +++ b/lib/widgets/name_section.dart @@ -153,9 +153,17 @@ class _NameSectionTextFieldState extends State<_NameSectionTextField> { } void _onFocusChange() { + if (_focusNode.hasFocus) _selectAll(); _focusNotifier.value = _focusNode.hasFocus; } + void _selectAll() { + _controller.selection = TextSelection( + baseOffset: 0, + extentOffset: _controller.text.length, + ); + } + @override Widget build(BuildContext context) { final theme = Theme.of(context); diff --git a/lib/widgets/name_shelf.dart b/lib/widgets/name_shelf.dart index 26bf791..23aba09 100644 --- a/lib/widgets/name_shelf.dart +++ b/lib/widgets/name_shelf.dart @@ -9,13 +9,21 @@ class NameShelf extends StatelessWidget { @override Widget build(BuildContext context) { - return Column( - children: [ - for (final name in names) - Expanded( - child: NameSection(name: name), - ), - ], + return Theme( + data: Theme.of(context).copyWith( + textSelectionTheme: const TextSelectionThemeData( + selectionColor: Colors.transparent, + selectionHandleColor: Colors.transparent, + ), + ), + child: Column( + children: [ + for (final name in names) + Expanded( + child: NameSection(name: name), + ), + ], + ), ); } }