【发布时间】:2020-09-23 05:19:10
【问题描述】:
我正在尝试将容器 appBar 的子元素垂直居中,它是文本,我是新来的,所以我在这里缺少什么。 它只是水平居中
小部件
import 'package:flutter/material.dart';
class MyAppbar extends StatelessWidget implements PreferredSizeWidget {
final Widget title;
const MyAppbar({Key key, this.title}) : super(key: key);
@override
Widget build(BuildContext context) {
return Material(
elevation: 0.0,
color: Colors.white,
child: Container(
padding: const EdgeInsets.all(0.0),
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.red,
border: Border(
bottom: BorderSide(
color: Color(0xffd9d9d9),
width: .8,
style: BorderStyle.solid,
),
),
),
child: Center(child: title),
),
);
}
final Size preferredSize = const Size.fromHeight(kToolbarHeight);
}
我在哪里称呼它
Scaffold(
appBar: MyAppbar(title: Text('Welcome to Ikaze', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w400, color: Colors.black))),
body: Center(),
);
【问题讨论】:
-
可以上传完整代码吗?
-
Column(mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children:
[]) -
这是完整的代码,我刚刚上传了我称之为@BilaalAbdelHassan的地方
-
@bihireboris 使用 AppBar 小部件自定义您的应用栏。它有一个使文本居中的论点。请参阅下面的答案。