- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
当用户向下滚动列表时,我试图隐藏底部应用栏,就像它在行为部分的 Material 设计文档中显示的那样:
https://material.io/design/components/app-bars-bottom.html#behavior
我正在寻找的效果如下所示: https://storage.googleapis.com/spec-host-backup/mio-design%2Fassets%2F1gaSrddolFHd8BwOioeYz0ODiyEhCevtn%2Fbehavior-scroll.mp4
到目前为止,我在 Scaffold 中添加了底部应用栏,但它没有滚动行为。
在 StackOverflow 上回答了一个类似的问题,但它显示了一种解决方法,并且已经在不久前得到了回答。
在 Flutter 中是否有合法的方式来实现这种效果?
我的代码:
import 'package:fitness_fatality_flutter/data/entities/exercise.dart';
import 'package:fitness_fatality_flutter/data/entities/workout.dart';
import 'package:flutter/material.dart';
class WorkoutDetailsPage extends StatelessWidget {
Workout _workout = Workout();
final List<Exercise> exercises = [
Exercise(name: "Push Ups"),
Exercise(name: "Bench press"),
Exercise(name: "Pull ups"),
Exercise(name: "Press ups"),
Exercise(name: "Crunches"),
Exercise(name: "Sit ups"),
Exercise(name: "BIceps curl"),
Exercise(name: "Something else"),
Exercise(name: "Push Ups"),
Exercise(name: "Bench press"),
Exercise(name: "Pull ups"),
Exercise(name: "Press ups"),
Exercise(name: "Crunches"),
Exercise(name: "Sit ups"),
Exercise(name: "BIceps curl"),
Exercise(name: "Something else"),
Exercise(name: "Push Ups"),
Exercise(name: "Bench press"),
Exercise(name: "Pull ups"),
Exercise(name: "Press ups"),
Exercise(name: "Crunches"),
Exercise(name: "Sit ups"),
Exercise(name: "BIceps curl"),
Exercise(name: "Something else"),
Exercise(name: "Push Ups"),
Exercise(name: "Bench press"),
Exercise(name: "Pull ups"),
Exercise(name: "Press ups"),
Exercise(name: "Crunches"),
Exercise(name: "Sit ups"),
Exercise(name: "BIceps curl"),
Exercise(name: "Something else"),
Exercise(name: "Push Ups"),
Exercise(name: "Bench press"),
Exercise(name: "Pull ups"),
Exercise(name: "Press ups"),
Exercise(name: "Crunches"),
Exercise(name: "Sit ups"),
Exercise(name: "BIceps curl"),
Exercise(name: "Something else"),
];
WorkoutDetailsPage(this._workout);
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButtonAnimator: FloatingActionButtonAnimator.scaling,
floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.blue,
elevation: 12,
onPressed: () {},
),
bottomNavigationBar: BottomAppBar(
elevation: 8,
shape: CircularNotchedRectangle(),
color: Colors.blue,
child: Container(
height: 50,
child: Row(
children: <Widget>[Text("data")],
),
),
),
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
bottom:BottomAppBar(), //<-- This would throw an error
expandedHeight: 150,
pinned: true,
floating: true,
snap: true,
flexibleSpace: FlexibleSpaceBar(
title: Text(_workout.name),
),
),
SliverList(
delegate: SliverChildBuilderDelegate(buildSliverListItem,
childCount: exercises.length),
),
],
),
);
}
Widget buildSliverListItem(BuildContext context, int index) {
return Center(
child: ListTile(
title: Text(exercises[index].name),
),
);
}
}
最佳答案
BottomAppBar
是 Scaffold
小部件的一部分,而不是 Sliver
。有一种方法可以实现你所描述的,但它有点复杂,需要StatefulWiget
和ScrollController
、AnimatedContainer
。请参阅下面的完整示例代码:
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: WorkoutDetailsPage(Workout()),
);
}
}
class Exercise {
String name;
Exercise({@required name}) {
this.name = name;
}
}
class Workout {
String name = "my name";
}
class WorkoutDetailsPage extends StatefulWidget {
Workout _workout = Workout();
WorkoutDetailsPage(this._workout);
@override
_WorkoutDetailsPageState createState() => _WorkoutDetailsPageState();
}
class _WorkoutDetailsPageState extends State<WorkoutDetailsPage> {
final List<Exercise> exercises = [
Exercise(name: "Push Ups"),
Exercise(name: "Bench press"),
Exercise(name: "Pull ups"),
Exercise(name: "Press ups"),
Exercise(name: "Crunches"),
Exercise(name: "Sit ups"),
Exercise(name: "BIceps curl"),
Exercise(name: "Something else"),
Exercise(name: "Push Ups"),
Exercise(name: "Bench press"),
Exercise(name: "Pull ups"),
Exercise(name: "Press ups"),
Exercise(name: "Crunches"),
Exercise(name: "Sit ups"),
Exercise(name: "BIceps curl"),
Exercise(name: "Something else"),
Exercise(name: "Push Ups"),
Exercise(name: "Bench press"),
Exercise(name: "Pull ups"),
Exercise(name: "Press ups"),
Exercise(name: "Crunches"),
Exercise(name: "Sit ups"),
Exercise(name: "BIceps curl"),
Exercise(name: "Something else"),
Exercise(name: "Push Ups"),
Exercise(name: "Bench press"),
Exercise(name: "Pull ups"),
Exercise(name: "Press ups"),
Exercise(name: "Crunches"),
Exercise(name: "Sit ups"),
Exercise(name: "BIceps curl"),
Exercise(name: "Something else"),
Exercise(name: "Push Ups"),
Exercise(name: "Bench press"),
Exercise(name: "Pull ups"),
Exercise(name: "Press ups"),
Exercise(name: "Crunches"),
Exercise(name: "Sit ups"),
Exercise(name: "BIceps curl"),
Exercise(name: "Something else"),
];
ScrollController _hideButtonController;
bool _isVisible = true;
@override
void initState() {
super.initState();
_isVisible = true;
_hideButtonController = new ScrollController();
_hideButtonController.addListener(() {
print("listener");
if (_hideButtonController.position.userScrollDirection ==
ScrollDirection.reverse) {
setState(() {
_isVisible = false;
print("**** $_isVisible up");
});
}
if (_hideButtonController.position.userScrollDirection ==
ScrollDirection.forward) {
setState(() {
_isVisible = true;
print("**** $_isVisible down");
});
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButtonAnimator: FloatingActionButtonAnimator.scaling,
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: _isVisible
? FloatingActionButton(
backgroundColor: Colors.blue,
elevation: 12,
onPressed: () {},
)
: null,
bottomNavigationBar: AnimatedContainer(
duration: Duration(milliseconds: 200),
height: _isVisible ? 60 : 0.0,
child: BottomAppBar(
elevation: 8,
shape: CircularNotchedRectangle(),
color: Colors.blue,
child: Container(
height: 60,
child: Row(
children: <Widget>[Text("data")],
),
),
),
),
body: CustomScrollView(
controller: _hideButtonController,
slivers: <Widget>[
SliverAppBar(
expandedHeight: 150,
pinned: true,
floating: true,
snap: true,
flexibleSpace: FlexibleSpaceBar(
title: Text(widget._workout.name),
),
),
SliverList(
delegate: SliverChildBuilderDelegate(buildSliverListItem,
childCount: exercises.length),
),
],
),
);
}
Widget buildSliverListItem(BuildContext context, int index) {
return Center(
child: ListTile(
title: Text(exercises[index].name),
),
);
}
}
关于android - Flutter:使用 Sliver 小部件时如何在滚动时隐藏 BottomAppBar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55033031/
我正在尝试使嵌套的 Sliver header 具有粘性。 我无法在“bruh”标题(粘性)下使“今天”标题具有粘性。让它感觉像是一些折叠的标题。 有人可以帮忙吗 class ListExample
我尝试在 Sliver List (CustomScrollview - SliverList) 中制作水平滚动列表 这是我的代码: import 'package:flutter/material.
我在 CustomScrollView 中有一个 Sliver 网格,我想在下拉网格时刷新内容。 我深入研究了小部件,但似乎不容易。看起来它实际上与sliver没有密切关系,而是 ListView 。
因此,我正在基于 this 创建一个基于 sliver 的 AppBar我发现的示例,并且正面临错误 named parameter 'slivers' isn't defined。 我的代码看起来有
我试图将 Sliver AppBar 的标题居中并在其下方添加第二个文本。我做不到。 下面是现在的图像以及它应该如何。 谁能帮帮我? 这是我的代码。 import 'package:flutter/m
我制作了一个 sliverappbar,我想在这个 sliverappbar 上放一张卡片。如何在 sliverappbar 上放一张卡片,然后这张卡片与 sliverappbar 一起折叠? 卡片应
我正在尝试使用 Sliver 来实现可折叠列表标题。当我将小部件从正常更改为 Sliver 时,我经常会遇到如下错误: I/flutter ( 3141): ══╡ EXCEPTION CAUGHT
希望你有美好的一天。我想在下面实现这样的事情 => gif image 1 谁的 gif 不清楚。这是来自名为 Yelp 的应用程序的屏幕截图.它是具有扩展和折叠功能的银色应用栏。当它折叠搜索栏固定到
在下面的代码中我遇到了问题,我正在尝试为 Sliver child 的每个 child 设置自定义高度,我刚刚在 Flutter 上了解了这个小部件,我想修复它,例如: CustomScrollVie
我有一个简单的银色应用栏,我将我的主要颜色设置为: theme: ThemeData(primary Color: Color. fromRGBO(50, 50, 205, 1)), 在我添加 sl
我试图在我的 sliver 应用栏上包含一个圆形个人资料图像按钮,但 sliver 应用栏并没有完全正确地呈现它。这就是我得到的,如何在条形应用栏上获得圆形个人资料图片? 我的代码: @ove
将 SliverAppBar 添加到 DraggableScrollableSheet 后,我无法将工作表向上或向下滚动到屏幕,但 SliverAppbar 内的列表工作正常, 完整源代码: impo
我正在使用 SliverAppBar在 Flutter 中,带有背景小部件。 问题是,当它展开时,标题和图标(引导和操作)应该是白色以便正确看到,当它折叠时,它们应该改为黑色。 关于如何从中获得 bo
@override Widget build(BuildContext context) { return Scaffold( body: CustomScrollView(
我在 GridView 上方使用 2 个 Sliver Headers,在 CustomScrollView 上使用 ListView。当我向下滚动时,我只想固定 1 个标题(我正在滚动的标题)。我希
我将 CustomScrollView 与 Sliver 一起使用。在 header 中,我有一些带有自动完成功能的文本字段(在数据库中搜索数据),当输入文本等于某个值时,我需要做一些事情。我尝试使用
因为我的屏幕上有条状应用栏,所以我没有使用 AppBar() 小部件。所以默认情况下状态栏颜色是白色。 有没有办法将状态栏的颜色从银色更改。 下面的代码按预期适用于 Android,但不适用于 iOS
我想要屏幕顶部的 SliverAppBar 和 ReorderableListView 下方的 SliverFillRemaining。 我尝试了多种解决方案,但每一种都不断出现不同的错误。将 Reo
我正在研究您可以在下面的屏幕截图中看到的概念: design concept 注意:箭头不是 UI 的一部分,而是添加来演示可拖动功能。 屏幕有一个显示位置标题的 SliverAppBar,包含位置描
我正在尝试在 SliverList 中运行 Markdown 小部件(包:flutter_markdown 0.2.0),但我遇到了一些问题。 理想情况下,我想在 Sliver 内的 ExpandTi
我是一名优秀的程序员,十分优秀!