【发布时间】:2021-10-13 05:26:44
【问题描述】:
我想为在 NestedScrollView 中定义的 SliverAppBar 设置动画。 我希望在滚动到相机选项卡时拥有与 Whatsapp 相同的动画,但禁止使用动画小部件作为 Slivers 父级。我怎样才能做到这一点? here 是一种昂贵的方式,但它对性能不友好
【问题讨论】:
标签: flutter flutter-animation flutter-sliver
我想为在 NestedScrollView 中定义的 SliverAppBar 设置动画。 我希望在滚动到相机选项卡时拥有与 Whatsapp 相同的动画,但禁止使用动画小部件作为 Slivers 父级。我怎样才能做到这一点? here 是一种昂贵的方式,但它对性能不友好
【问题讨论】:
标签: flutter flutter-animation flutter-sliver
您可以像这样设置应用栏以在用户滚动视图时隐藏 AppBar
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
const title = 'Floating App Bar';
return MaterialApp(
title: title,
home: Scaffold(
// No appbar provided to the Scaffold, only a body with a
// CustomScrollView.
body: CustomScrollView(
slivers: [
// Add the app bar to the CustomScrollView.
const SliverAppBar(
// Provide a standard title.
title: Text(title),
// Allows the user to reveal the app bar if they begin scrolling
// back up the list of items.
floating: true,
// Display a placeholder widget to visualize the shrinking size.
flexibleSpace: Placeholder(),
// Make the initial height of the SliverAppBar larger than normal.
expandedHeight: 200,
),
// Next, create a SliverList
SliverList(
// Use a delegate to build items as they're scrolled on screen.
delegate: SliverChildBuilderDelegate(
// The builder function returns a ListTile with a title that
// displays the index of the current item.
(context, index) => ListTile(title: Text('Item #$index')),
// Builds 1000 ListTiles
childCount: 1000,
),
),
],
),
),
);
}
}
【讨论】: