@@ -193,6 +193,7 @@ class NavigationDrawerDestination extends StatelessWidget {
193
193
required this .icon,
194
194
this .selectedIcon,
195
195
required this .label,
196
+ this .enabled = true ,
196
197
});
197
198
198
199
/// Sets the color of the [Material] that holds all of the [Drawer] 's
@@ -229,12 +230,20 @@ class NavigationDrawerDestination extends StatelessWidget {
229
230
/// text style would use [TextTheme.labelLarge] with [ColorScheme.onSurfaceVariant] .
230
231
final Widget label;
231
232
233
+ /// Indicates that this destination is selectable.
234
+ ///
235
+ /// Defaults to true.
236
+ final bool enabled;
237
+
232
238
@override
233
239
Widget build (BuildContext context) {
234
240
const Set <MaterialState > selectedState = < MaterialState > {
235
241
MaterialState .selected
236
242
};
237
243
const Set <MaterialState > unselectedState = < MaterialState > {};
244
+ const Set <MaterialState > disabledState = < MaterialState > {
245
+ MaterialState .disabled
246
+ };
238
247
239
248
final NavigationDrawerThemeData navigationDrawerTheme =
240
249
NavigationDrawerTheme .of (context);
@@ -247,13 +256,13 @@ class NavigationDrawerDestination extends StatelessWidget {
247
256
return _NavigationDestinationBuilder (
248
257
buildIcon: (BuildContext context) {
249
258
final Widget selectedIconWidget = IconTheme .merge (
250
- data: navigationDrawerTheme.iconTheme? .resolve (selectedState) ??
251
- defaults.iconTheme! .resolve (selectedState)! ,
259
+ data: navigationDrawerTheme.iconTheme? .resolve (enabled ? selectedState : disabledState ) ??
260
+ defaults.iconTheme! .resolve (enabled ? selectedState : disabledState )! ,
252
261
child: selectedIcon ?? icon,
253
262
);
254
263
final Widget unselectedIconWidget = IconTheme .merge (
255
- data: navigationDrawerTheme.iconTheme? .resolve (unselectedState) ??
256
- defaults.iconTheme! .resolve (unselectedState)! ,
264
+ data: navigationDrawerTheme.iconTheme? .resolve (enabled ? unselectedState : disabledState ) ??
265
+ defaults.iconTheme! .resolve (enabled ? unselectedState : disabledState )! ,
257
266
child: icon,
258
267
);
259
268
@@ -263,18 +272,20 @@ class NavigationDrawerDestination extends StatelessWidget {
263
272
},
264
273
buildLabel: (BuildContext context) {
265
274
final TextStyle ? effectiveSelectedLabelTextStyle =
266
- navigationDrawerTheme.labelTextStyle? .resolve (selectedState) ??
267
- defaults.labelTextStyle! .resolve (selectedState);
275
+ navigationDrawerTheme.labelTextStyle? .resolve (enabled ? selectedState : disabledState ) ??
276
+ defaults.labelTextStyle! .resolve (enabled ? selectedState : disabledState );
268
277
final TextStyle ? effectiveUnselectedLabelTextStyle =
269
- navigationDrawerTheme.labelTextStyle? .resolve (unselectedState) ??
270
- defaults.labelTextStyle! .resolve (unselectedState);
278
+ navigationDrawerTheme.labelTextStyle? .resolve (enabled ? unselectedState : disabledState) ??
279
+ defaults.labelTextStyle! .resolve (enabled ? unselectedState : disabledState);
280
+
271
281
return DefaultTextStyle (
272
282
style: _isForwardOrCompleted (animation)
273
283
? effectiveSelectedLabelTextStyle!
274
284
: effectiveUnselectedLabelTextStyle! ,
275
285
child: label,
276
286
);
277
287
},
288
+ enabled: enabled,
278
289
);
279
290
}
280
291
}
@@ -296,6 +307,7 @@ class _NavigationDestinationBuilder extends StatelessWidget {
296
307
const _NavigationDestinationBuilder ({
297
308
required this .buildIcon,
298
309
required this .buildLabel,
310
+ this .enabled = true ,
299
311
});
300
312
301
313
/// Builds the icon for a destination in a [NavigationDrawer] .
@@ -322,20 +334,34 @@ class _NavigationDestinationBuilder extends StatelessWidget {
322
334
/// animation is decreasing or dismissed.
323
335
final WidgetBuilder buildLabel;
324
336
337
+ /// Indicates that this destination is selectable.
338
+ ///
339
+ /// Defaults to true.
340
+ final bool enabled;
341
+
325
342
@override
326
343
Widget build (BuildContext context) {
327
344
final _NavigationDrawerDestinationInfo info = _NavigationDrawerDestinationInfo .of (context);
328
345
final NavigationDrawerThemeData navigationDrawerTheme = NavigationDrawerTheme .of (context);
329
346
final NavigationDrawerThemeData defaults = _NavigationDrawerDefaultsM3 (context);
330
347
348
+ final Row destinationBody = Row (
349
+ children: < Widget > [
350
+ const SizedBox (width: 16 ),
351
+ buildIcon (context),
352
+ const SizedBox (width: 12 ),
353
+ buildLabel (context),
354
+ ],
355
+ );
356
+
331
357
return Padding (
332
358
padding: info.tilePadding,
333
359
child: _NavigationDestinationSemantics (
334
360
child: SizedBox (
335
361
height: navigationDrawerTheme.tileHeight ?? defaults.tileHeight,
336
362
child: InkWell (
337
363
highlightColor: Colors .transparent,
338
- onTap: info.onTap,
364
+ onTap: enabled ? info.onTap : null ,
339
365
customBorder: info.indicatorShape ?? navigationDrawerTheme.indicatorShape ?? defaults.indicatorShape! ,
340
366
child: Stack (
341
367
alignment: Alignment .center,
@@ -347,14 +373,7 @@ class _NavigationDestinationBuilder extends StatelessWidget {
347
373
width: (navigationDrawerTheme.indicatorSize ?? defaults.indicatorSize! ).width,
348
374
height: (navigationDrawerTheme.indicatorSize ?? defaults.indicatorSize! ).height,
349
375
),
350
- Row (
351
- children: < Widget > [
352
- const SizedBox (width: 16 ),
353
- buildIcon (context),
354
- const SizedBox (width: 12 ),
355
- buildLabel (context),
356
- ],
357
- ),
376
+ destinationBody
358
377
],
359
378
),
360
379
),
@@ -702,7 +721,9 @@ class _NavigationDrawerDefaultsM3 extends NavigationDrawerThemeData {
702
721
return MaterialStateProperty .resolveWith ((Set <MaterialState > states) {
703
722
return IconThemeData (
704
723
size: 24.0 ,
705
- color: states.contains (MaterialState .selected)
724
+ color: states.contains (MaterialState .disabled)
725
+ ? _colors.onSurfaceVariant.withOpacity (0.38 )
726
+ : states.contains (MaterialState .selected)
706
727
? _colors.onSecondaryContainer
707
728
: _colors.onSurfaceVariant,
708
729
);
@@ -714,7 +735,9 @@ class _NavigationDrawerDefaultsM3 extends NavigationDrawerThemeData {
714
735
return MaterialStateProperty .resolveWith ((Set <MaterialState > states) {
715
736
final TextStyle style = _textTheme.labelLarge! ;
716
737
return style.apply (
717
- color: states.contains (MaterialState .selected)
738
+ color: states.contains (MaterialState .disabled)
739
+ ? _colors.onSurfaceVariant.withOpacity (0.38 )
740
+ : states.contains (MaterialState .selected)
718
741
? _colors.onSecondaryContainer
719
742
: _colors.onSurfaceVariant,
720
743
);
0 commit comments