her*_*ell 7 flutter flutter-sliver flutter-layout
这就是我想要做的,它是 iOS 上非常常见的 Widget。这是我的代码:
return Scaffold(
backgroundColor: Colors.white,
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
automaticallyImplyLeading: false,
pinned: true,
titleSpacing: 0,
backgroundColor: Colors.white,
elevation: 1.0,
title: Container(
width: double.infinity,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceAround,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
CupertinoButton(
padding: EdgeInsets.all(0),
onPressed: () {},
child: AutoSizeText(
'Ordenar',
style: TextStyle(
color: Color(0xff16161F),
fontFamily: 'Brutal',
fontSize: 17.0,
),
),
),
AutoSizeText(
'Equipos 14',
style: TextStyle(
color: Color(0xff16161F),
fontFamily: 'Archia',
fontSize: 22.0,
),
),
CupertinoButton(
padding: EdgeInsets.all(0),
onPressed: () {},
child: AutoSizeText(
'Editar',
style: TextStyle(
color: Color(0xff16161F),
fontFamily: 'Brutal',
fontSize: 17.0,
),
),
),
],
),
),
centerTitle: true,
),
SliverFillRemaining(
child: Center(
child: CupertinoButton(
onPressed: () {
setState(() {
(isBottom) ? isBottom = false : isBottom = true;
});
},
child: Text('YESSS'),
),
),
),
],
),
bottomNavigationBar: (isBottom) ? _toolBar() : _tabBar(),
);
Run Code Online (Sandbox Code Playgroud)
我试过CupertinoTextField()在bottom属性中添加一个,但它进入了我的Row()并弄乱了一切。有没有人这样做过,或者知道如何实现它?
谢谢。
her*_*ell 16
我设法解决了它。SliverAppBar 有一个名为flexibleSpace. 在这里放置一个FlexibleSpaceBar,其中包含一个background属性。现在,不要被愚弄,这不仅限于纯色或图像。它可以带任何你想要的 Widget。就我而言,我想添加一个搜索栏。因为这个属性会填满整个expandedHeight属性,所以你想添加一个小的空白区域,这样你的自定义小部件就不会被绘制到你的 SliverAppBar 上。这是相关的一段代码:
flexibleSpace: FlexibleSpaceBar(
background: Column(
children: <Widget>[
SizedBox(height: 90.0),
Padding(
padding: const EdgeInsets.fromLTRB(16.0, 6.0, 16.0, 16.0),
child: Container(
height: 36.0,
width: double.infinity,
child: CupertinoTextField(
keyboardType: TextInputType.text,
placeholder: 'Filtrar por nombre o nombre corto',
placeholderStyle: TextStyle(
color: Color(0xffC4C6CC),
fontSize: 14.0,
fontFamily: 'Brutal',
),
prefix: Padding(
padding:
const EdgeInsets.fromLTRB(9.0, 6.0, 9.0, 6.0),
child: Icon(
Icons.search,
color: Color(0xffC4C6CC),
),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.0),
color: Color(0xffF0F1F5),
),
),
),
),
],
),
),
),
Run Code Online (Sandbox Code Playgroud)
这是结果。向上滚动时,搜索栏将消失。希望这可以帮助任何想要这样做的人。
| 归档时间: |
|
| 查看次数: |
6132 次 |
| 最近记录: |