navigation_bar_template.dart 2.59 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'template.dart';

class NavigationBarTemplate extends TokenTemplate {
8 9 10 11
  const NavigationBarTemplate(super.blockName, super.fileName, super.tokens, {
    super.colorSchemePrefix = '_colors.',
    super.textThemePrefix = '_textTheme.',
  });
12 13 14

  @override
  String generate() => '''
15 16
class _${blockName}DefaultsM3 extends NavigationBarThemeData {
  _${blockName}DefaultsM3(this.context)
17
      : super(
18
          height: ${getToken("md.comp.navigation-bar.container.height")},
19 20 21 22
          elevation: ${elevation("md.comp.navigation-bar.container")},
          labelBehavior: NavigationDestinationLabelBehavior.alwaysShow,
        );

23 24 25
  final BuildContext context;
  late final ColorScheme _colors = Theme.of(context).colorScheme;
  late final TextTheme _textTheme = Theme.of(context).textTheme;
26

27 28
  @override Color? get backgroundColor => ${componentColor("md.comp.navigation-bar.container")};

29 30 31
  @override Color? get shadowColor => ${colorOrTransparent("md.comp.navigation-bar.container.shadow-color")};

  @override Color? get surfaceTintColor => ${colorOrTransparent("md.comp.navigation-bar.container.surface-tint-layer.color")};
32 33 34 35

  @override MaterialStateProperty<IconThemeData?>? get iconTheme {
    return MaterialStateProperty.resolveWith((Set<MaterialState> states) {
      return IconThemeData(
36
        size: ${getToken("md.comp.navigation-bar.icon.size")},
37 38 39 40 41
        color: states.contains(MaterialState.disabled)
          ? _colors.onSurfaceVariant.withOpacity(0.38)
          : states.contains(MaterialState.selected)
            ? ${componentColor("md.comp.navigation-bar.active.icon")}
            : ${componentColor("md.comp.navigation-bar.inactive.icon")},
42 43 44 45
      );
    });
  }

46
  @override Color? get indicatorColor => ${componentColor("md.comp.navigation-bar.active-indicator")};
47 48 49 50
  @override ShapeBorder? get indicatorShape => ${shape("md.comp.navigation-bar.active-indicator")};

  @override MaterialStateProperty<TextStyle?>? get labelTextStyle {
    return MaterialStateProperty.resolveWith((Set<MaterialState> states) {
51
    final TextStyle style = ${textStyle("md.comp.navigation-bar.label-text")}!;
52 53 54 55 56 57
      return style.apply(
        color: states.contains(MaterialState.disabled)
          ? _colors.onSurfaceVariant.withOpacity(0.38)
          : states.contains(MaterialState.selected)
            ? ${componentColor("md.comp.navigation-bar.active.label-text")}
            : ${componentColor("md.comp.navigation-bar.inactive.label-text")}
58 59 60 61 62 63
      );
    });
  }
}
''';
}