flutter - 如何在 Flutter 中更改 AppBar() 的宽度?
问题描述
我想为 Flutter Web 重用移动应用程序代码。我已经在所有屏幕的脚手架中使用 AppBar() 和 body 小部件进行了编码。现在我正在为 web 使用 400 宽度和中心,除了 appbar 之外它都很好。
Scaffold(
appBar: this.getAppBarWidget(),
body: Center(
child: Container(
width: kIsWeb ? 400.0 : MediaQuery.of(context).size.width,
child: this.getBodyWidget(),
),
))
上面的代码完美适用于除了 web 中的 appbar 之外的所有移动设备和 web 屏幕。
如何更改 appbar 的宽度以适应宽度 400?
如果我使用 Size.fromWidth(400) 会出错。
下面的代码适用于移动设备和网络。
Scaffold(
body: Center(
child: Container(
width: kIsWeb ? 400.0 : MediaQuery.of(context).size.width,
child: Column(
children: [
this.getCustomAppbarWidget(),
this.getBodyWidget(),
],
),
),
))
请给我建议。
解决方案
据我所知,AppBar 中不允许宽度。AppBar 中只允许高度
toolbarHeight: 60,
但是,如果您想在 AppBar 中手动应用宽度,您可以将 AppBar 包装在 Padding 组件中
return Scaffold(
body: Column(
children: [
Container(
width: kIsWeb? 400 : double.maxFinite,
child: AppBar(
title: Text('hello'),
),
),
Expanded(child: HomePageOne()), // this expanded is you page body
],
),
);
推荐阅读
- python - openpyxl 在 Visual Studio Code 中不起作用
- reactjs - 如何在firebase中将uid作为参数传递?反应+火力基地
- spring - Spring cloud config server on refresh -> logback config 也会自动刷新
- javascript - 如何使用 chrome 下载 api 判断下载何时完成?
- mysql - Laravel Eloquent Query 将一个 where 语句优先于其他语句
- marklogic - 在 MarkLogic 暂存数据库上计算具有 where 条件的 Json 文档数
- kotlin - 官方示例代码中变量 updateSection 的赋值是什么?
- r - 如何打印唯一值列表?
- angular - 我们如何将 Angular 组件的样式加载到 iframe 中?
- r - dplyr 过滤器可以成功检测到的观察数量是否有限制?