浏览代码

Update AppBar and BottomAppBar

/main
Yuncong Zhang 6 年前
当前提交
4b30d427
共有 8 个文件被更改,包括 291 次插入34 次删除
  1. 38
      Runtime/material/app_bar.cs
  2. 40
      Runtime/material/bottom_app_bar.cs
  3. 36
      Runtime/material/theme_data.cs
  4. 2
      Runtime/painting/notched_shapes.cs
  5. 113
      Runtime/material/app_bar_theme.cs
  6. 3
      Runtime/material/app_bar_theme.cs.meta
  7. 90
      Runtime/material/bottom_app_bar_theme.cs
  8. 3
      Runtime/material/bottom_app_bar_theme.cs.meta

38
Runtime/material/app_bar.cs


List<Widget> actions = null,
Widget flexibleSpace = null,
PreferredSizeWidget bottom = null,
float elevation = 4.0f,
float? elevation = null,
Color backgroundColor = null,
Brightness? brightness = null,
IconThemeData iconTheme = null,

float toolbarOpacity = 1.0f,
float bottomOpacity = 1.0f
) : base(key: key) {
D.assert(elevation == null || elevation >= 0.0);
this.leading = leading;
this.automaticallyImplyLeading = automaticallyImplyLeading;
this.title = title;

public readonly PreferredSizeWidget bottom;
public readonly float elevation;
public readonly float? elevation;
public readonly Color backgroundColor;

class _AppBarState : State<AppBar> {
const float _defaultElevation = 4.0f;
void _handleDrawerButton() {
Scaffold.of(this.context).openDrawer();
}

public override Widget build(BuildContext context) {
D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
ThemeData themeData = Theme.of(context);
AppBarTheme appBarTheme = AppBarTheme.of(context);
ScaffoldState scaffold = Scaffold.of(context, nullOk: true);
ModalRoute parentRoute = ModalRoute.of(context);

bool useCloseButton = parentRoute is PageRoute && ((PageRoute) parentRoute).fullscreenDialog;
IconThemeData appBarIconTheme = this.widget.iconTheme ?? themeData.primaryIconTheme;
TextStyle centerStyle = this.widget.textTheme?.title ?? themeData.primaryTextTheme.title;
TextStyle sideStyle = this.widget.textTheme?.body1 ?? themeData.primaryTextTheme.body1;
IconThemeData appBarIconTheme = this.widget.iconTheme
?? appBarTheme.iconTheme
?? themeData.primaryIconTheme;
TextStyle centerStyle = this.widget.textTheme?.title
?? appBarTheme.textTheme?.title
?? themeData.primaryTextTheme.title;
TextStyle sideStyle = this.widget.textTheme?.body1
?? appBarTheme.textTheme?.body1
?? themeData.primaryTextTheme.body1;
if (this.widget.toolbarOpacity != 1.0f) {
float opacity =

);
}
Brightness brightness = this.widget.brightness ?? themeData.primaryColorBrightness;
Brightness brightness = this.widget.brightness
?? appBarTheme.brightness
?? themeData.primaryColorBrightness;
SystemUiOverlayStyle overlayStyle = brightness == Brightness.dark
? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark;

child: new Material(
color: this.widget.backgroundColor ?? themeData.primaryColor,
elevation: this.widget.elevation,
color: this.widget.backgroundColor
?? appBarTheme.color
?? themeData.primaryColor,
elevation: this.widget.elevation
?? appBarTheme.elevation
?? _defaultElevation,
child: appBar
));
}

public override Widget build(BuildContext context, float shrinkOffset, bool overlapsContent) {
float? visibleMainHeight = this.maxExtent - shrinkOffset - this.topPadding;
float toolbarOpacity = this.pinned && !this.floating
? 1.0f
: ((visibleMainHeight - this._bottomHeight) / Constants.kToolbarHeight)?.clamp(0.0f, 1.0f) ?? 0.0f;
float toolbarOpacity = !this.pinned || (!this.floating && this.bottom != null)
? ((visibleMainHeight - this._bottomHeight) / Constants.kToolbarHeight)?.clamp(0.0f, 1.0f) ?? 1.0f
: 1.0f;
Widget appBar = FlexibleSpaceBar.createSettings(
minExtent: this.minExtent,
maxExtent: this.maxExtent,

40
Runtime/material/bottom_app_bar.cs


public BottomAppBar(
Key key = null,
Color color = null,
float elevation = 8.0f,
float? elevation = null,
D.assert(elevation >= 0.0f);
D.assert(elevation == null || elevation >= 0.0f);
this.child = child;
this.color = color;
this.elevation = elevation;

public readonly Color color;
public readonly float elevation;
public readonly float? elevation;
public readonly NotchedShape shape;

class _BottomAppBarState : State<BottomAppBar> {
ValueListenable<ScaffoldGeometry> geometryListenable;
const float _defaultElevation = 8.0f;
public override void didChangeDependencies() {
base.didChangeDependencies();

public override Widget build(BuildContext context) {
CustomClipper<Path> clipper = this.widget.shape != null
BottomAppBarTheme babTheme = BottomAppBarTheme.of(context);
NotchedShape notchedShape = this.widget.shape ?? babTheme.shape;
CustomClipper<Path> clipper = notchedShape != null
shape: this.widget.shape,
shape: notchedShape,
elevation: this.widget.elevation,
color: this.widget.color ?? Theme.of(context).bottomAppBarColor,
elevation: this.widget.elevation ?? babTheme.elevation ?? _defaultElevation,
color: this.widget.color ?? babTheme.color ?? Theme.of(context).bottomAppBarColor,
clipBehavior: this.widget.clipBehavior,
child: new Material(
type: MaterialType.transparency,

public readonly float notchMargin;
public override Path getClip(Size size) {
Rect appBar = Offset.zero & size;
if (this.geometry.value.floatingActionButtonArea == null) {
Path path = new Path();
path.addRect(appBar);
return path;
}
Rect button = this.geometry.value.floatingActionButtonArea
.translate(0.0f, (this.geometry.value.bottomNavigationBarTop * -1.0f) ?? 0.0f);
return this.shape.getOuterPath(appBar, button.inflate(this.notchMargin));
Rect button = this.geometry.value.floatingActionButtonArea?.translate(
0.0f,
(this.geometry.value.bottomNavigationBarTop ?? 0.0f) * -1.0f
);
return this.shape.getOuterPath(Offset.zero & size, button?.inflate(this.notchMargin));
public override bool shouldReclip(CustomClipper<Path> oldClipper) {
return (oldClipper as _BottomAppBarClipper).geometry != this.geometry;
public override bool shouldReclip(CustomClipper<Path> _oldClipper) {
_BottomAppBarClipper oldClipper = _oldClipper as _BottomAppBarClipper;
return oldClipper.geometry != this.geometry
|| oldClipper.shape != this.shape
|| oldClipper.notchMargin != this.notchMargin;
}
}
}

36
Runtime/material/theme_data.cs


RuntimePlatform? platform = null,
MaterialTapTargetSize? materialTapTargetSize = null,
PageTransitionsTheme pageTransitionsTheme = null,
AppBarTheme appBarTheme = null,
BottomAppBarTheme bottomAppBarTheme = null,
ColorScheme colorScheme = null,
DialogTheme dialogTheme = null,
Typography typography = null

errorColor = errorColor ?? Colors.red[700];
inputDecorationTheme = inputDecorationTheme ?? new InputDecorationTheme();
pageTransitionsTheme = pageTransitionsTheme ?? new PageTransitionsTheme();
appBarTheme = appBarTheme ?? new AppBarTheme();
bottomAppBarTheme = bottomAppBarTheme ?? new BottomAppBarTheme();
primaryIconTheme = primaryIconTheme ??
(primaryIsDark
? new IconThemeData(color: Colors.white)

D.assert(accentIconTheme != null);
D.assert(materialTapTargetSize != null);
D.assert(pageTransitionsTheme != null);
D.assert(appBarTheme != null);
D.assert(bottomAppBarTheme != null);
D.assert(colorScheme != null);
D.assert(typography != null);
D.assert(buttonColor != null);

this.platform = platform.Value;
this.materialTapTargetSize = materialTapTargetSize ?? MaterialTapTargetSize.padded;
this.pageTransitionsTheme = pageTransitionsTheme;
this.appBarTheme = appBarTheme;
this.bottomAppBarTheme = bottomAppBarTheme;
this.colorScheme = colorScheme;
this.dialogTheme = dialogTheme;
this.typography = typography;

RuntimePlatform? platform = null,
MaterialTapTargetSize? materialTapTargetSize = null,
PageTransitionsTheme pageTransitionsTheme = null,
AppBarTheme appBarTheme = null,
BottomAppBarTheme bottomAppBarTheme = null,
ColorScheme colorScheme = null,
DialogTheme dialogTheme = null,
Typography typography = null

D.assert(platform != null);
D.assert(materialTapTargetSize != null);
D.assert(pageTransitionsTheme != null);
D.assert(appBarTheme != null);
D.assert(bottomAppBarTheme != null);
D.assert(colorScheme != null);
D.assert(typography != null);
D.assert(buttonColor != null);

platform: platform,
materialTapTargetSize: materialTapTargetSize,
pageTransitionsTheme: pageTransitionsTheme,
appBarTheme: appBarTheme,
bottomAppBarTheme: bottomAppBarTheme,
colorScheme: colorScheme,
dialogTheme: dialogTheme,
typography: typography);

public readonly MaterialTapTargetSize materialTapTargetSize;
public readonly PageTransitionsTheme pageTransitionsTheme;
public readonly AppBarTheme appBarTheme;
public readonly BottomAppBarTheme bottomAppBarTheme;
public readonly ColorScheme colorScheme;

RuntimePlatform? platform = null,
MaterialTapTargetSize? materialTapTargetSize = null,
PageTransitionsTheme pageTransitionsTheme = null,
AppBarTheme appBarTheme = null,
BottomAppBarTheme bottomAppBarTheme = null,
ColorScheme colorScheme = null,
DialogTheme dialogTheme = null,
Typography typography = null

platform: platform ?? this.platform,
materialTapTargetSize: materialTapTargetSize ?? this.materialTapTargetSize,
pageTransitionsTheme: pageTransitionsTheme ?? this.pageTransitionsTheme,
appBarTheme: appBarTheme ?? this.appBarTheme,
bottomAppBarTheme: bottomAppBarTheme ?? this.bottomAppBarTheme,
colorScheme: colorScheme ?? this.colorScheme,
dialogTheme: dialogTheme ?? this.dialogTheme,
typography: typography ?? this.typography

platform: t < 0.5 ? a.platform : b.platform,
materialTapTargetSize: t < 0.5 ? a.materialTapTargetSize : b.materialTapTargetSize,
pageTransitionsTheme: t < 0.5 ? a.pageTransitionsTheme : b.pageTransitionsTheme,
appBarTheme: AppBarTheme.lerp(a.appBarTheme, b.appBarTheme, t),
bottomAppBarTheme: BottomAppBarTheme.lerp(a.bottomAppBarTheme, b.bottomAppBarTheme, t),
colorScheme: ColorScheme.lerp(a.colorScheme, b.colorScheme, t),
dialogTheme: DialogTheme.lerp(a.dialogTheme, b.dialogTheme, t),
typography: Typography.lerp(a.typography, b.typography, t)

other.platform == this.platform &&
other.materialTapTargetSize == this.materialTapTargetSize &&
other.pageTransitionsTheme == this.pageTransitionsTheme &&
other.appBarTheme == this.appBarTheme &&
other.bottomAppBarTheme == this.bottomAppBarTheme &&
other.colorScheme == this.colorScheme &&
other.dialogTheme == this.dialogTheme &&
other.typography == this.typography;

if (this._cachedHashCode != null) {
return this._cachedHashCode.Value;
}
unchecked {
var hashCode = this.brightness.GetHashCode();
hashCode = (hashCode * 397) ^ this.primaryColor.GetHashCode();

hashCode = (hashCode * 397) ^ this.platform.GetHashCode();
hashCode = (hashCode * 397) ^ this.materialTapTargetSize.GetHashCode();
hashCode = (hashCode * 397) ^ this.pageTransitionsTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.appBarTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.bottomAppBarTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.colorScheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.dialogTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.typography.GetHashCode();

properties.add(new DiagnosticsProperty<TextTheme>("textTheme", this.textTheme));
properties.add(new DiagnosticsProperty<TextTheme>("primaryTextTheme", this.primaryTextTheme));
properties.add(new DiagnosticsProperty<TextTheme>("accentTextTheme", this.accentTextTheme));
properties.add(new DiagnosticsProperty<InputDecorationTheme>("inputDecorationTheme", this.inputDecorationTheme));
properties.add(
new DiagnosticsProperty<InputDecorationTheme>("inputDecorationTheme", this.inputDecorationTheme));
properties.add(new DiagnosticsProperty<Color>("toggleableActiveColor", this.toggleableActiveColor,
defaultValue: defaultData.toggleableActiveColor));
properties.add(new DiagnosticsProperty<IconThemeData>("iconTheme", this.iconTheme));

new DiagnosticsProperty<MaterialTapTargetSize>("materialTapTargetSize", this.materialTapTargetSize));
properties.add(
new DiagnosticsProperty<PageTransitionsTheme>("pageTransitionsTheme", this.pageTransitionsTheme));
properties.add(new DiagnosticsProperty<AppBarTheme>("appBarTheme", this.appBarTheme));
properties.add(new DiagnosticsProperty<BottomAppBarTheme>("bottomAppBarTheme", this.bottomAppBarTheme));
properties.add(new DiagnosticsProperty<ColorScheme>("colorScheme", this.colorScheme,
defaultValue: defaultData.colorScheme));
properties.add(new DiagnosticsProperty<DialogTheme>("dialogTheme", this.dialogTheme,

public V putIfAbsent(K key, Func<V> value) {
D.assert(key != null);
D.assert(value != null);
V get_value;
if (this._cache.TryGetValue(key, out get_value)) {
return get_value;

2
Runtime/painting/notched_shapes.cs


}
public override Path getOuterPath(Rect host, Rect guest) {
if (!host.overlaps(guest)) {
if (guest == null || !host.overlaps(guest)) {
Path path = new Path();
path.addRect(host);
return path;

113
Runtime/material/app_bar_theme.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
public class AppBarTheme : Diagnosticable {
public AppBarTheme(
Brightness? brightness = null,
Color color = null,
float? elevation = null,
IconThemeData iconTheme = null,
TextTheme textTheme = null
) {
this.brightness = brightness;
this.color = color;
this.elevation = elevation;
this.iconTheme = iconTheme;
this.textTheme = textTheme;
}
public readonly Brightness? brightness;
public readonly Color color;
public readonly float? elevation;
public readonly IconThemeData iconTheme;
public readonly TextTheme textTheme;
AppBarTheme copyWith(
Brightness? brightness = null,
Color color = null,
float? elevation = null,
IconThemeData iconTheme = null,
TextTheme textTheme = null
) {
return new AppBarTheme(
brightness: brightness ?? this.brightness,
color: color ?? this.color,
elevation: elevation ?? this.elevation,
iconTheme: iconTheme ?? this.iconTheme,
textTheme: textTheme ?? this.textTheme
);
}
public static AppBarTheme of(BuildContext context) {
return Theme.of(context).appBarTheme;
}
public static AppBarTheme lerp(AppBarTheme a, AppBarTheme b, float t) {
D.assert(t != null);
return new AppBarTheme(
brightness: t < 0.5f ? a?.brightness : b?.brightness,
color: Color.lerp(a?.color, b?.color, t),
elevation: MathUtils.lerpFloat(a?.elevation ?? 0.0f, b?.elevation ?? 0.0f, t),
iconTheme: IconThemeData.lerp(a?.iconTheme, b?.iconTheme, t),
textTheme: TextTheme.lerp(a?.textTheme, b?.textTheme, t)
);
}
public override int GetHashCode() {
var hashCode = this.brightness?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ this.color?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ this.elevation?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ this.iconTheme?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ this.textTheme?.GetHashCode() ?? 0;
return hashCode;
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {
return false;
}
if (ReferenceEquals(this, obj)) {
return true;
}
if (obj.GetType() != this.GetType()) {
return false;
}
return this.Equals((AppBarTheme) obj);
}
public static bool operator ==(AppBarTheme left, AppBarTheme right) {
return Equals(left, right);
}
public static bool operator !=(AppBarTheme left, AppBarTheme right) {
return !Equals(left, right);
}
public bool Equals(AppBarTheme other) {
return other.brightness == this.brightness
&& other.color == this.color
&& other.elevation == this.elevation
&& other.iconTheme == this.iconTheme
&& other.textTheme == this.textTheme;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<Brightness?>("brightness", this.brightness, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("color", this.color, defaultValue: null));
properties.add(new DiagnosticsProperty<float?>("elevation", this.elevation, defaultValue: null));
properties.add(new DiagnosticsProperty<IconThemeData>("iconTheme", this.iconTheme, defaultValue: null));
properties.add(new DiagnosticsProperty<TextTheme>("textTheme", this.textTheme, defaultValue: null));
}
}
}

3
Runtime/material/app_bar_theme.cs.meta


fileFormatVersion: 2
guid: 0c0ee979ef6b4f32a092532c3bdae31e
timeCreated: 1556178331

90
Runtime/material/bottom_app_bar_theme.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
public class BottomAppBarTheme : Diagnosticable {
public BottomAppBarTheme(
Color color = null,
float? elevation = null,
NotchedShape shape = null
) {
}
public readonly Color color;
public readonly float? elevation;
public readonly NotchedShape shape;
BottomAppBarTheme copyWith(
Color color = null,
float? elevation = null,
NotchedShape shape = null
) {
return new BottomAppBarTheme(
color: color ?? this.color,
elevation: elevation ?? this.elevation,
shape: shape ?? this.shape
);
}
public static BottomAppBarTheme of(BuildContext context) {
return Theme.of(context).bottomAppBarTheme;
}
public static BottomAppBarTheme lerp(BottomAppBarTheme a, BottomAppBarTheme b, float t) {
D.assert(t != null);
return new BottomAppBarTheme(
color: Color.lerp(a?.color, b?.color, t),
elevation: MathUtils.lerpFloat(a?.elevation ?? 0.0f, b?.elevation ?? 0.0f, t),
shape: t < 0.5f ? a?.shape : b?.shape
);
}
public override int GetHashCode() {
var hashCode = this.color?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ this.elevation?.GetHashCode() ?? 0;
hashCode = (hashCode * 397) ^ this.shape?.GetHashCode() ?? 0;
return hashCode;
}
public bool Equals(BottomAppBarTheme other) {
return other.color == this.color
&& other.elevation == this.elevation
&& other.shape == this.shape;
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {
return false;
}
if (ReferenceEquals(this, obj)) {
return true;
}
if (obj.GetType() != this.GetType()) {
return false;
}
return this.Equals((BottomAppBarTheme) obj);
}
public static bool operator ==(BottomAppBarTheme left, BottomAppBarTheme right) {
return Equals(left, right);
}
public static bool operator !=(BottomAppBarTheme left, BottomAppBarTheme right) {
return !Equals(left, right);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<Color>("color", this.color, defaultValue: null));
properties.add(new DiagnosticsProperty<float?>("elevation", this.elevation, defaultValue: null));
properties.add(new DiagnosticsProperty<NotchedShape>("shape", this.shape, defaultValue: null));
}
}
}

3
Runtime/material/bottom_app_bar_theme.cs.meta


fileFormatVersion: 2
guid: 9c88d19dd1254f4eb6c0c998084832ea
timeCreated: 1556185402
正在加载...
取消
保存