added enabled to search anchor (#153256)
Added the same parameter from #137388 to the `SearchAnchor` This PR will fix: #150331
This commit is contained in:
parent
d9dda9d08f
commit
ce15e3bcb5
@ -137,6 +137,7 @@ class SearchAnchor extends StatefulWidget {
|
|||||||
required this.suggestionsBuilder,
|
required this.suggestionsBuilder,
|
||||||
this.textInputAction,
|
this.textInputAction,
|
||||||
this.keyboardType,
|
this.keyboardType,
|
||||||
|
this.enabled = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Create a [SearchAnchor] that has a [SearchBar] which opens a search view.
|
/// Create a [SearchAnchor] that has a [SearchBar] which opens a search view.
|
||||||
@ -350,6 +351,13 @@ class SearchAnchor extends StatefulWidget {
|
|||||||
/// Defaults to the default value specified in [TextField].
|
/// Defaults to the default value specified in [TextField].
|
||||||
final TextInputType? keyboardType;
|
final TextInputType? keyboardType;
|
||||||
|
|
||||||
|
/// Whether or not this widget is currently interactive.
|
||||||
|
///
|
||||||
|
/// When false, the widget will ignore taps and appear dimmed.
|
||||||
|
///
|
||||||
|
/// Defaults to true.
|
||||||
|
final bool enabled;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<SearchAnchor> createState() => _SearchAnchorState();
|
State<SearchAnchor> createState() => _SearchAnchorState();
|
||||||
}
|
}
|
||||||
@ -450,15 +458,25 @@ class _SearchAnchorState extends State<SearchAnchor> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double _getOpacity() {
|
||||||
|
if (widget.enabled) {
|
||||||
|
return _anchorIsVisible ? 1.0 : 0.0;
|
||||||
|
}
|
||||||
|
return _kDisableSearchBarOpacity;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return AnimatedOpacity(
|
return AnimatedOpacity(
|
||||||
key: _anchorKey,
|
key: _anchorKey,
|
||||||
opacity: _anchorIsVisible ? 1.0 : 0.0,
|
opacity: _getOpacity(),
|
||||||
duration: _kAnchorFadeDuration,
|
duration: _kAnchorFadeDuration,
|
||||||
child: GestureDetector(
|
child: IgnorePointer(
|
||||||
onTap: _openView,
|
ignoring: !widget.enabled,
|
||||||
child: widget.builder(context, _searchController),
|
child: GestureDetector(
|
||||||
|
onTap: _openView,
|
||||||
|
child: widget.builder(context, _searchController),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1317,7 +1335,11 @@ class SearchBar extends StatefulWidget {
|
|||||||
/// {@macro flutter.widgets.editableText.textCapitalization}
|
/// {@macro flutter.widgets.editableText.textCapitalization}
|
||||||
final TextCapitalization? textCapitalization;
|
final TextCapitalization? textCapitalization;
|
||||||
|
|
||||||
/// If false the text field is "disabled" so the SearchBar will ignore taps.
|
/// Whether or not this widget is currently interactive.
|
||||||
|
///
|
||||||
|
/// When false, the widget will ignore taps and appear dimmed.
|
||||||
|
///
|
||||||
|
/// Defaults to true.
|
||||||
final bool enabled;
|
final bool enabled;
|
||||||
|
|
||||||
/// {@macro flutter.widgets.editableText.autofocus}
|
/// {@macro flutter.widgets.editableText.autofocus}
|
||||||
|
@ -3016,6 +3016,56 @@ void main() {
|
|||||||
expect(opacityWidget.opacity, 0.38);
|
expect(opacityWidget.opacity, 0.38);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('Check SearchAnchor opacity when disabled', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(MaterialApp(
|
||||||
|
home: Center(
|
||||||
|
child: Material(
|
||||||
|
child: SearchAnchor(
|
||||||
|
enabled: false,
|
||||||
|
builder: (BuildContext context, SearchController controller) {
|
||||||
|
return const Icon(Icons.search);
|
||||||
|
},
|
||||||
|
suggestionsBuilder: (BuildContext context, SearchController controller) {
|
||||||
|
return <Widget>[];
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
final Finder searchBarFinder = find.byType(SearchAnchor);
|
||||||
|
expect(searchBarFinder, findsOneWidget);
|
||||||
|
final Finder opacityFinder = find.descendant(
|
||||||
|
of: searchBarFinder,
|
||||||
|
matching: find.byType(AnimatedOpacity),
|
||||||
|
);
|
||||||
|
expect(opacityFinder, findsOneWidget);
|
||||||
|
final AnimatedOpacity opacityWidget = tester.widget<AnimatedOpacity>(opacityFinder);
|
||||||
|
expect(opacityWidget.opacity, 0.38);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('SearchAnchor tap failed when disabled', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(MaterialApp(
|
||||||
|
home: Center(
|
||||||
|
child: Material(
|
||||||
|
child: SearchAnchor(
|
||||||
|
enabled: false,
|
||||||
|
builder: (BuildContext context, SearchController controller) {
|
||||||
|
return const Icon(Icons.search);
|
||||||
|
},
|
||||||
|
suggestionsBuilder: (BuildContext context, SearchController controller) {
|
||||||
|
return <Widget>[];
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
final Finder searchBarFinder = find.byType(SearchAnchor);
|
||||||
|
expect(searchBarFinder, findsOneWidget);
|
||||||
|
expect(searchBarFinder.hitTestable().tryEvaluate(), false);
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('SearchAnchor respects headerHeight', (WidgetTester tester) async {
|
testWidgets('SearchAnchor respects headerHeight', (WidgetTester tester) async {
|
||||||
await tester.pumpWidget(MaterialApp(
|
await tester.pumpWidget(MaterialApp(
|
||||||
home: Center(
|
home: Center(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user