可容纳一个子组件,通过控制基线高度来控制子组件的位置。一般用于文字组件。
相关组件
Baseline基本使用
<br />【child】 : 孩子组件 【Widget】<br />【baseline】 : 基线位置 【double】<br />【baselineType】 : 基线类型 【TextBaseline】<br />![196.gif](https://cdn.nlark.com/yuque/0/2020/gif/326147/1589508836830-928e9e4f-1414-4d53-9b8a-243ab39e07c1.gif#align=left&display=inline&height=224&margin=%5Bobject%20Object%5D&name=196.gif&originHeight=224&originWidth=370&size=300196&status=done&style=none&width=370)
import 'package:flutter/material.dart';
class CustomBaseline extends StatefulWidget {
@override
_CustomBaselineState createState() => _CustomBaselineState();
}
class _CustomBaselineState extends State<CustomBaseline> {
double _baseline=20;
@override
Widget build(BuildContext context) {
var childBox = Text(
'你好,Flutter',
style: TextStyle(fontSize: 20,fontFamily: "Menlo"),
);
var baseline = Baseline(
child: childBox,
baseline: _baseline,
baselineType: TextBaseline.alphabetic
);
return Column(
children: <Widget>[
_buildSlider(),
Container(
width: 100/0.618,
height: 100,
color: Colors.grey.withAlpha(22),
child: baseline,
),
],
);
}
Widget _buildSlider() => Slider(
divisions: 20,
min: 0,
max: 60,
label: _baseline.toString(),
value: _baseline,
onChanged: (v) => setState(() => _baseline = v));
}