我正在尝试执行与此处材料指南中所述相同的滚动技术:“带标签的应用栏”部分中的https://material.io/guidelines/patterns/scrolling-techniques.html#scrolling-techniques-behavior。
无法找到任何示例。 Flutter目前有可能吗?
答案 0 :(得分:4)
您希望标签栏保持固定在顶部,同时工具栏滚动。您可以使用SliverAppBar
pinned: true
和floating: true
来完成此操作。该示例的完整代码如下所示。
import 'package:flutter/material.dart';
main() async {
runApp(new MaterialApp(
home: new MyHomePage(),
));
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new DefaultTabController(
length: 2,
child: new Scaffold(
body: new NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
new SliverAppBar(
title: const Text('Tabs and scrolling'),
forceElevated: innerBoxIsScrolled,
pinned: true,
floating: true,
bottom: new TabBar(
tabs: <Tab>[
new Tab(text: 'green'),
new Tab(text: 'purple'),
],
),
),
];
},
body: new TabBarView(
children: <Widget>[
new Center(
child: new Container(
height: 1000.0,
color: Colors.green.shade200,
child: new Center(
child: new FlutterLogo(colors: Colors.green),
),
),
),
new Center(
child: new Container(
height: 1000.0,
color: Colors.purple.shade200,
child: new Center(
child: new FlutterLogo(colors: Colors.purple),
),
),
),
],
),
),
),
);
}
}