import 'package:flutter/material.dart';
class commentPage extends StatefulWidget {
commentPage({Key key}) : super(key: key);
@override
_commentPageState createState() => _commentPageState();
}
class _commentPageState extends State<commentPage>
with SingleTickerProviderStateMixin {
TabController tabController;
@override
void initState() {
super.initState();
this.tabController = TabController(length: 2, vsync: this);
}
@override
Widget build(BuildContext context) {
return Scaffold(
// appBar: AppBar(
// title: Text('评论'),
// ),
body: Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
pinned: true,
elevation: 0,
expandedHeight: 250,
flexibleSpace: FlexibleSpaceBar(
title: Text('评论'),
background: Image.network(
'https://img0.baidu.com/it/u=4092964127,2965208246&fm=26&fmt=auto&gp=0.jpg',
fit: BoxFit.cover,
),
),
),
SliverPersistentHeader(
pinned: true,
delegate: StickyTabBarDelegate(
child: TabBar(
labelColor: Colors.black,
controller: this.tabController,
tabs: <Widget>[
Tab(text: 'Home'),
Tab(text: 'Profile'),
],
),
),
),
SliverFillRemaining(
child: TabBarView(
controller: this.tabController,
children: <Widget>[
Center(child: Text('Content of Home')),
Center(child: Text('Content of Profile')),
],
),
),
],
),
),
);
}
}
class StickyTabBarDelegate extends SliverPersistentHeaderDelegate {
final TabBar child;
StickyTabBarDelegate({@required this.child});
@override
Widget build(
BuildContext context, double shrinkOffset, bool overlapsContent) {
return this.child;
}
@override
double get maxExtent => this.child.preferredSize.height;
@override
double get minExtent => this.child.preferredSize.height;
@override
bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
return true;
}
}
网友评论