Skip to content

Commit

Permalink
feat(name_section): select all text on focus (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertms10 committed Apr 4, 2023
1 parent 4c118f1 commit 2c9873c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
8 changes: 8 additions & 0 deletions lib/widgets/name_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 15 additions & 7 deletions lib/widgets/name_shelf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
],
),
);
}
}

1 comment on commit 2c9873c

@vercel
Copy link

@vercel vercel bot commented on 2c9873c Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

note-names – ./

note-names.vercel.app
note-names-git-main-albertms10.vercel.app
note-names-albertms10.vercel.app

Please sign in to comment.