在颤动中无法更改高度的offset。 Flutter 遵循Material Design 原则,修改参数(如偏移量)的能力将超越这一目的。
正如你在source code 中看到的颤动阴影,海拔只不过是一个阴影列表。如果你想修改海拔参数,我建议创建一个自定义包装器并使用带有可覆盖参数的实际值。
import 'package:flutter/material.dart';
class CustomElevation extends StatelessWidget {
final Widget child;
final Offset offset;
final int elevation;
final Map<int, List<BoxShadow>> _elevationToShadow;
CustomElevation({@required this.child, @required this.elevation, this.offset = const Offset(0.0, 0.0)})
: assert(child != null),
// Here kElevationToShadow is a map exposed by flutter material design shadows
_elevationToShadow = kElevationToShadow.map<int, List<BoxShadow>>(
(int key, List<BoxShadow> value) => MapEntry<int, List<BoxShadow>>(
key,
value.map(
(BoxShadow bs) => BoxShadow(
offset: offset,
blurRadius: bs.blurRadius,
spreadRadius: bs.spreadRadius,
color: bs.color,
),
),
),
);
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
boxShadow: _elevationToShadow[elevation] ?? <BoxShadow>[],
),
child: child,
);
}
}
或者,如果您需要完全不同的东西,请继续前进,随心所欲地提升 :)