@@ -35,6 +35,7 @@ const Curve _kViewFadeOnInterval = Interval(0.0, 1/2);
35
35
const Curve _kViewIconsFadeOnInterval = Interval (1 / 6 , 2 / 6 );
36
36
const Curve _kViewDividerFadeOnInterval = Interval (0.0 , 1 / 6 );
37
37
const Curve _kViewListFadeOnInterval = Interval (133 / _kOpenViewMilliseconds, 233 / _kOpenViewMilliseconds);
38
+ const double _kDisableSearchBarOpacity = 0.38 ;
38
39
39
40
/// Signature for a function that creates a [Widget] which is used to open a search view.
40
41
///
@@ -1115,6 +1116,7 @@ class SearchBar extends StatefulWidget {
1115
1116
this .textStyle,
1116
1117
this .hintStyle,
1117
1118
this .textCapitalization,
1119
+ this .enabled = true ,
1118
1120
this .autoFocus = false ,
1119
1121
this .textInputAction,
1120
1122
this .keyboardType,
@@ -1239,6 +1241,9 @@ class SearchBar extends StatefulWidget {
1239
1241
/// {@macro flutter.widgets.editableText.textCapitalization}
1240
1242
final TextCapitalization ? textCapitalization;
1241
1243
1244
+ /// If false the text field is "disabled" so the SearchBar will ignore taps.
1245
+ final bool enabled;
1246
+
1242
1247
/// {@macro flutter.widgets.editableText.autofocus}
1243
1248
final bool autoFocus;
1244
1249
@@ -1340,62 +1345,69 @@ class _SearchBarState extends State<SearchBar> {
1340
1345
1341
1346
return ConstrainedBox (
1342
1347
constraints: widget.constraints ?? searchBarTheme.constraints ?? defaults.constraints! ,
1343
- child: Material (
1344
- elevation: effectiveElevation! ,
1345
- shadowColor: effectiveShadowColor,
1346
- color: effectiveBackgroundColor,
1347
- surfaceTintColor: effectiveSurfaceTintColor,
1348
- shape: effectiveShape? .copyWith (side: effectiveSide),
1349
- child: InkWell (
1350
- onTap: () {
1351
- widget.onTap? .call ();
1352
- if (! _focusNode.hasFocus) {
1353
- _focusNode.requestFocus ();
1354
- }
1355
- },
1356
- overlayColor: effectiveOverlayColor,
1357
- customBorder: effectiveShape? .copyWith (side: effectiveSide),
1358
- statesController: _internalStatesController,
1359
- child: Padding (
1360
- padding: effectivePadding! ,
1361
- child: Row (
1362
- textDirection: textDirection,
1363
- children: < Widget > [
1364
- if (leading != null ) leading,
1365
- Expanded (
1366
- child: Padding (
1367
- padding: effectivePadding,
1368
- child: TextField (
1369
- autofocus: widget.autoFocus,
1370
- onTap: widget.onTap,
1371
- onTapAlwaysCalled: true ,
1372
- focusNode: _focusNode,
1373
- onChanged: widget.onChanged,
1374
- onSubmitted: widget.onSubmitted,
1375
- controller: widget.controller,
1376
- style: effectiveTextStyle,
1377
- decoration: InputDecoration (
1378
- hintText: widget.hintText,
1379
- ).applyDefaults (InputDecorationTheme (
1380
- hintStyle: effectiveHintStyle,
1381
- // The configuration below is to make sure that the text field
1382
- // in `SearchBar` will not be overridden by the overall `InputDecorationTheme`
1383
- enabledBorder: InputBorder .none,
1384
- border: InputBorder .none,
1385
- focusedBorder: InputBorder .none,
1386
- contentPadding: EdgeInsets .zero,
1387
- // Setting `isDense` to true to allow the text field height to be
1388
- // smaller than 48.0
1389
- isDense: true ,
1390
- )),
1391
- textCapitalization: effectiveTextCapitalization,
1392
- textInputAction: widget.textInputAction,
1393
- keyboardType: widget.keyboardType,
1348
+ child: Opacity (
1349
+ opacity: widget.enabled ? 1 : _kDisableSearchBarOpacity,
1350
+ child: Material (
1351
+ elevation: effectiveElevation! ,
1352
+ shadowColor: effectiveShadowColor,
1353
+ color: effectiveBackgroundColor,
1354
+ surfaceTintColor: effectiveSurfaceTintColor,
1355
+ shape: effectiveShape? .copyWith (side: effectiveSide),
1356
+ child: IgnorePointer (
1357
+ ignoring: ! widget.enabled,
1358
+ child: InkWell (
1359
+ onTap: () {
1360
+ widget.onTap? .call ();
1361
+ if (! _focusNode.hasFocus) {
1362
+ _focusNode.requestFocus ();
1363
+ }
1364
+ },
1365
+ overlayColor: effectiveOverlayColor,
1366
+ customBorder: effectiveShape? .copyWith (side: effectiveSide),
1367
+ statesController: _internalStatesController,
1368
+ child: Padding (
1369
+ padding: effectivePadding! ,
1370
+ child: Row (
1371
+ textDirection: textDirection,
1372
+ children: < Widget > [
1373
+ if (leading != null ) leading,
1374
+ Expanded (
1375
+ child: Padding (
1376
+ padding: effectivePadding,
1377
+ child: TextField (
1378
+ autofocus: widget.autoFocus,
1379
+ onTap: widget.onTap,
1380
+ onTapAlwaysCalled: true ,
1381
+ focusNode: _focusNode,
1382
+ onChanged: widget.onChanged,
1383
+ onSubmitted: widget.onSubmitted,
1384
+ controller: widget.controller,
1385
+ style: effectiveTextStyle,
1386
+ enabled: widget.enabled,
1387
+ decoration: InputDecoration (
1388
+ hintText: widget.hintText,
1389
+ ).applyDefaults (InputDecorationTheme (
1390
+ hintStyle: effectiveHintStyle,
1391
+ // The configuration below is to make sure that the text field
1392
+ // in `SearchBar` will not be overridden by the overall `InputDecorationTheme`
1393
+ enabledBorder: InputBorder .none,
1394
+ border: InputBorder .none,
1395
+ focusedBorder: InputBorder .none,
1396
+ contentPadding: EdgeInsets .zero,
1397
+ // Setting `isDense` to true to allow the text field height to be
1398
+ // smaller than 48.0
1399
+ isDense: true ,
1400
+ )),
1401
+ textCapitalization: effectiveTextCapitalization,
1402
+ textInputAction: widget.textInputAction,
1403
+ keyboardType: widget.keyboardType,
1404
+ ),
1405
+ ),
1394
1406
),
1395
- ),
1407
+ if (trailing != null ) ...trailing,
1408
+ ],
1396
1409
),
1397
- if (trailing != null ) ...trailing,
1398
- ],
1410
+ ),
1399
1411
),
1400
1412
),
1401
1413
),
0 commit comments