forked from lxm_flutter/FlutterUnit
✨ 更新macOS版
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// create by 张风捷特烈 on 2020/6/16
|
||||
/// contact me by email 1981462002@qq.com
|
||||
/// 说明:
|
||||
|
||||
// {
|
||||
// "widgetId": 251,
|
||||
// "name": 'NestedScrollView基本用法',
|
||||
// "priority": 1,
|
||||
// "subtitle":
|
||||
// "【controller】 : 滑动控制器 【ScrollController】\n"
|
||||
// "【scrollDirection】 : 滑动方向 【Axis】\n"
|
||||
// "【reverse】 : 是否反向 【bool】\n"
|
||||
// "【physics】 : 滑顶样式 【ScrollPhysics】\n"
|
||||
// "【dragStartBehavior】 : 开始拖动行为 【DragStartBehavior】\n"
|
||||
// "【headerSliverBuilder】 : *头部构造器 【NestedScrollViewHeaderSliversBuilder】\n"
|
||||
// "【body】 : *内容 【Widget】",
|
||||
// }
|
||||
|
||||
class NestedScrollViewDemo extends StatelessWidget {
|
||||
final _tabs = ['风神传', '封妖志', "幻将录", "永恒传说"];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
height: MediaQuery.of(context).size.height - 200,
|
||||
child: Scaffold(
|
||||
body: DefaultTabController(
|
||||
length: _tabs.length,
|
||||
child: NestedScrollView(
|
||||
headerSliverBuilder:
|
||||
(BuildContext context, bool innerBoxIsScrolled) {
|
||||
return <Widget>[
|
||||
SliverOverlapAbsorber(
|
||||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(
|
||||
context),
|
||||
sliver: SliverAppBar(
|
||||
title: const Text('旷古奇书'),
|
||||
pinned: true,
|
||||
elevation: 6, //影深
|
||||
expandedHeight: 220.0,
|
||||
forceElevated: innerBoxIsScrolled, //为true时展开有阴影
|
||||
flexibleSpace: FlexibleSpaceBar(
|
||||
background: Image.asset(
|
||||
"assets/images/wy_300x200_filter.jpg",
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
bottom: TabBar(
|
||||
tabs: _tabs
|
||||
.map((String name) => Tab(text: name,))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
];
|
||||
},
|
||||
body: _buildTabBarView(),
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
Widget _buildTabBarView() {
|
||||
return TabBarView(
|
||||
children: _tabs.map((String name) {
|
||||
return SafeArea(
|
||||
top: false,
|
||||
bottom: false,
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return CustomScrollView(
|
||||
key: PageStorageKey<String>(name),
|
||||
slivers: <Widget>[
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
sliver: SliverFixedExtentList(
|
||||
itemExtent: 48.0,
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, int index) {
|
||||
return ListTile(
|
||||
title: Text('《$name》 第 $index章'),
|
||||
);
|
||||
},
|
||||
childCount: 50,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user