问题描述
问题
下图显示了Flutter中每个小部件的高度对齐方式(如果可以使用高度):
但是我想将高程移到此处"%URL%"
小部件的直接中心(Offset(0.0,0.0)
)。
解决方法
在颤动中无法更改高度offset
。 Flutter遵循Material Design原理,并且修改参数(例如offset)的功能将达到这个目的。
正如您在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,);
}
}
或者如果您需要其他完全不同的东西,请按照自己的内心需求进行提升:)