|
| 1 | +// Copyright 2020, the Flutter project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:flutter/material.dart'; |
| 6 | +import 'package:flutter/services.dart'; |
| 7 | + |
| 8 | +import 'adaptive_breakpoints.dart'; |
| 9 | + |
| 10 | +/// AdaptiveAppBar has a leading width of 72.0. Everything else is the same as |
| 11 | +/// [AppBar]. |
| 12 | +class AdaptiveAppBar extends StatelessWidget implements PreferredSizeWidget { |
| 13 | + AdaptiveAppBar({ |
| 14 | + super.key, |
| 15 | + this.leading, |
| 16 | + this.automaticallyImplyLeading = true, |
| 17 | + this.title, |
| 18 | + this.actions, |
| 19 | + this.flexibleSpace, |
| 20 | + this.bottom, |
| 21 | + this.elevation, |
| 22 | + this.shadowColor, |
| 23 | + this.shape, |
| 24 | + this.backgroundColor, |
| 25 | + this.iconThemeData, |
| 26 | + this.actionsIconThemeData, |
| 27 | + this.primary = true, |
| 28 | + this.centerTitle, |
| 29 | + this.excludeHeaderSemantics = false, |
| 30 | + this.titleSpacing = NavigationToolbar.kMiddleSpacing, |
| 31 | + this.toolbarOpacity = 1.0, |
| 32 | + this.bottomOpacity = 1.0, |
| 33 | + this.toolbarHeight, |
| 34 | + this.leadingWidth, |
| 35 | + this.toolbarTextStyle, |
| 36 | + this.titleTextStyle, |
| 37 | + this.systemOverlayStyle, |
| 38 | + }) : assert(elevation == null || elevation >= 0.0), |
| 39 | + preferredSize = Size.fromHeight( |
| 40 | + toolbarHeight ?? |
| 41 | + kToolbarHeight + (bottom?.preferredSize.height ?? 0.0), |
| 42 | + ); |
| 43 | + |
| 44 | + final Widget? leading; |
| 45 | + final bool automaticallyImplyLeading; |
| 46 | + final Widget? title; |
| 47 | + final List<Widget>? actions; |
| 48 | + final Widget? flexibleSpace; |
| 49 | + final PreferredSizeWidget? bottom; |
| 50 | + final double? elevation; |
| 51 | + final Color? shadowColor; |
| 52 | + final ShapeBorder? shape; |
| 53 | + final Color? backgroundColor; |
| 54 | + final IconThemeData? iconThemeData; |
| 55 | + final IconThemeData? actionsIconThemeData; |
| 56 | + final bool primary; |
| 57 | + final bool? centerTitle; |
| 58 | + final bool excludeHeaderSemantics; |
| 59 | + final double titleSpacing; |
| 60 | + final double toolbarOpacity; |
| 61 | + final double bottomOpacity; |
| 62 | + @override |
| 63 | + final Size preferredSize; |
| 64 | + final double? toolbarHeight; |
| 65 | + final double? leadingWidth; |
| 66 | + final TextStyle? toolbarTextStyle; |
| 67 | + final TextStyle? titleTextStyle; |
| 68 | + final SystemUiOverlayStyle? systemOverlayStyle; |
| 69 | + |
| 70 | + @override |
| 71 | + Widget build(BuildContext context) { |
| 72 | + return AppBar( |
| 73 | + key: key, |
| 74 | + leading: leading, |
| 75 | + automaticallyImplyLeading: automaticallyImplyLeading, |
| 76 | + title: title, |
| 77 | + actions: actions, |
| 78 | + flexibleSpace: flexibleSpace, |
| 79 | + bottom: bottom, |
| 80 | + elevation: elevation, |
| 81 | + shadowColor: shadowColor, |
| 82 | + shape: shape, |
| 83 | + backgroundColor: backgroundColor, |
| 84 | + iconTheme: iconThemeData, |
| 85 | + actionsIconTheme: actionsIconThemeData, |
| 86 | + primary: primary, |
| 87 | + centerTitle: centerTitle, |
| 88 | + excludeHeaderSemantics: excludeHeaderSemantics, |
| 89 | + titleSpacing: titleSpacing, |
| 90 | + toolbarOpacity: toolbarOpacity, |
| 91 | + bottomOpacity: bottomOpacity, |
| 92 | + toolbarHeight: toolbarHeight, |
| 93 | + // TODO(https://github.com/material-foundation/flutter-packages/issues/320): |
| 94 | + // This needs to depend on whether the rail is showing or not. |
| 95 | + leadingWidth: getWindowType(context) == AdaptiveWindowType.medium |
| 96 | + ? 72.0 |
| 97 | + : 56.0, |
| 98 | + toolbarTextStyle: toolbarTextStyle, |
| 99 | + titleTextStyle: titleTextStyle, |
| 100 | + systemOverlayStyle: systemOverlayStyle, |
| 101 | + ); |
| 102 | + } |
| 103 | +} |
0 commit comments