Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
7d794725
Unverified
Commit
7d794725
authored
Oct 13, 2023
by
Kostia Sokolovskyi
Committed by
GitHub
Oct 13, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SearchAnchor should dispose created FocusNode and SearchController. (#136120)
parent
e0b8ec07
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
245 additions
and
82 deletions
+245
-82
search_anchor.dart
packages/flutter/lib/src/material/search_anchor.dart
+30
-21
search_anchor_test.dart
packages/flutter/test/material/search_anchor_test.dart
+215
-61
No files found.
packages/flutter/lib/src/material/search_anchor.dart
View file @
7d794725
...
@@ -310,15 +310,12 @@ class _SearchAnchorState extends State<SearchAnchor> {
...
@@ -310,15 +310,12 @@ class _SearchAnchorState extends State<SearchAnchor> {
bool
_anchorIsVisible
=
true
;
bool
_anchorIsVisible
=
true
;
final
GlobalKey
_anchorKey
=
GlobalKey
();
final
GlobalKey
_anchorKey
=
GlobalKey
();
bool
get
_viewIsOpen
=>
!
_anchorIsVisible
;
bool
get
_viewIsOpen
=>
!
_anchorIsVisible
;
late
SearchController
?
_internalSearchController
;
SearchController
?
_internalSearchController
;
SearchController
get
_searchController
=>
widget
.
searchController
??
_internalSearchController
!
;
SearchController
get
_searchController
=>
widget
.
searchController
??
(
_internalSearchController
??=
SearchController
())
;
@override
@override
void
initState
()
{
void
initState
()
{
super
.
initState
();
super
.
initState
();
if
(
widget
.
searchController
==
null
)
{
_internalSearchController
=
SearchController
();
}
_searchController
.
_attach
(
this
);
_searchController
.
_attach
(
this
);
}
}
...
@@ -334,11 +331,21 @@ class _SearchAnchorState extends State<SearchAnchor> {
...
@@ -334,11 +331,21 @@ class _SearchAnchorState extends State<SearchAnchor> {
_screenSize
=
updatedScreenSize
;
_screenSize
=
updatedScreenSize
;
}
}
@override
void
didUpdateWidget
(
SearchAnchor
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
if
(
oldWidget
.
searchController
!=
widget
.
searchController
)
{
oldWidget
.
searchController
?.
_detach
(
this
);
_searchController
.
_attach
(
this
);
}
}
@override
@override
void
dispose
()
{
void
dispose
()
{
super
.
dispose
();
super
.
dispose
();
_searchController
.
_detach
(
this
);
widget
.
searchController
?.
_detach
(
this
);
_internalSearchController
=
null
;
_internalSearchController
?.
_detach
(
this
);
_internalSearchController
?.
dispose
();
}
}
void
_openView
()
{
void
_openView
()
{
...
@@ -680,12 +687,6 @@ class _ViewContentState extends State<_ViewContent> {
...
@@ -680,12 +687,6 @@ class _ViewContentState extends State<_ViewContent> {
}
}
}
}
@override
void
dispose
(){
_controller
.
removeListener
(
updateSuggestions
);
super
.
dispose
();
}
@override
@override
void
didUpdateWidget
(
covariant
_ViewContent
oldWidget
)
{
void
didUpdateWidget
(
covariant
_ViewContent
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
super
.
didUpdateWidget
(
oldWidget
);
...
@@ -710,6 +711,13 @@ class _ViewContentState extends State<_ViewContent> {
...
@@ -710,6 +711,13 @@ class _ViewContentState extends State<_ViewContent> {
unawaited
(
updateSuggestions
());
unawaited
(
updateSuggestions
());
}
}
@override
void
dispose
()
{
_controller
.
removeListener
(
updateSuggestions
);
_focusNode
.
dispose
();
super
.
dispose
();
}
Widget
viewBuilder
(
Iterable
<
Widget
>
suggestions
)
{
Widget
viewBuilder
(
Iterable
<
Widget
>
suggestions
)
{
if
(
widget
.
viewBuilder
==
null
)
{
if
(
widget
.
viewBuilder
==
null
)
{
return
MediaQuery
.
removePadding
(
return
MediaQuery
.
removePadding
(
...
@@ -949,15 +957,18 @@ class SearchController extends TextEditingController {
...
@@ -949,15 +957,18 @@ class SearchController extends TextEditingController {
// it controls.
// it controls.
_SearchAnchorState
?
_anchor
;
_SearchAnchorState
?
_anchor
;
/// Whether this controller has associated search anchor.
bool
get
isAttached
=>
_anchor
!=
null
;
/// Whether or not the associated search view is currently open.
/// Whether or not the associated search view is currently open.
bool
get
isOpen
{
bool
get
isOpen
{
assert
(
_anchor
!=
null
);
assert
(
isAttached
);
return
_anchor
!.
_viewIsOpen
;
return
_anchor
!.
_viewIsOpen
;
}
}
/// Opens the search view that this controller is associated with.
/// Opens the search view that this controller is associated with.
void
openView
()
{
void
openView
()
{
assert
(
_anchor
!=
null
);
assert
(
isAttached
);
_anchor
!.
_openView
();
_anchor
!.
_openView
();
}
}
...
@@ -966,7 +977,7 @@ class SearchController extends TextEditingController {
...
@@ -966,7 +977,7 @@ class SearchController extends TextEditingController {
/// If `selectedText` is given, then the text value of the controller is set to
/// If `selectedText` is given, then the text value of the controller is set to
/// `selectedText`.
/// `selectedText`.
void
closeView
(
String
?
selectedText
)
{
void
closeView
(
String
?
selectedText
)
{
assert
(
_anchor
!=
null
);
assert
(
isAttached
);
_anchor
!.
_closeView
(
selectedText
);
_anchor
!.
_closeView
(
selectedText
);
}
}
...
@@ -1166,7 +1177,8 @@ class SearchBar extends StatefulWidget {
...
@@ -1166,7 +1177,8 @@ class SearchBar extends StatefulWidget {
class
_SearchBarState
extends
State
<
SearchBar
>
{
class
_SearchBarState
extends
State
<
SearchBar
>
{
late
final
MaterialStatesController
_internalStatesController
;
late
final
MaterialStatesController
_internalStatesController
;
late
final
FocusNode
_focusNode
;
FocusNode
?
_internalFocusNode
;
FocusNode
get
_focusNode
=>
widget
.
focusNode
??
(
_internalFocusNode
??=
FocusNode
());
@override
@override
void
initState
()
{
void
initState
()
{
...
@@ -1175,15 +1187,12 @@ class _SearchBarState extends State<SearchBar> {
...
@@ -1175,15 +1187,12 @@ class _SearchBarState extends State<SearchBar> {
_internalStatesController
.
addListener
(()
{
_internalStatesController
.
addListener
(()
{
setState
(()
{});
setState
(()
{});
});
});
_focusNode
=
widget
.
focusNode
??
FocusNode
();
}
}
@override
@override
void
dispose
()
{
void
dispose
()
{
_internalStatesController
.
dispose
();
_internalStatesController
.
dispose
();
if
(
widget
.
focusNode
==
null
)
{
_internalFocusNode
?.
dispose
();
_focusNode
.
dispose
();
}
super
.
dispose
();
super
.
dispose
();
}
}
...
...
packages/flutter/test/material/search_anchor_test.dart
View file @
7d794725
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment