diegoveloper / flutter-samples

Flutter Samples
MIT License
3.1k stars 745 forks source link

I use your MainCollapsingToolbar widget,but find a question #1

Closed zjc closed 6 years ago

zjc commented 6 years ago

hi, I want to add a listview widget in tab,but have a space in tab between listview,I want to remove it ,how can i fix it ,thanks my code is:

ScrollController _scrollController = new ScrollController(); @override Widget build(BuildContext context) { return Scaffold( body: NestedScrollView( controller: _scrollController, headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { return [ SliverAppBar( expandedHeight: _appBarHeight, floating: false, pinned: true, backgroundColor: FunColors.c_333, actions: [ new IconButton( icon: new Icon(Icons.share), tooltip: "分享话题", onPressed: () { showShareBottomSheet(context); }, ) ], flexibleSpace: FlexibleSpaceBar( title: Text(widget.topicName, style: TextStyle( color: Colors.white, fontSize: 16.0, )), background: new Stack( fit: StackFit.expand, children: [ _buildTopicBackground(), new Align( alignment: Alignment.bottomRight, child: new Container( margin: EdgeInsets.only(bottom: 15.0, right: 15.0), height: 35.0, width: 75.0, child: new RaisedButton( highlightColor: FunColors.themeColor, onPressed: () {}, color: FunColors.themeColor, shape: new RoundedRectangleBorder( borderRadius: new BorderRadius.circular(20.0), ), child: new Text( "关注", style: new TextStyle(color: Colors.white), ), ), ), ), ], ), ), ), SliverPersistentHeader( delegate: _SliverAppBarDelegate( _tabController, ), pinned: true, ), ]; }, body: new TabBarView( controller: _tabController, children: [ new TopicDetailChildPage( TopicDetailPresenter.TYPE_HOT, widget.topicName), new TopicDetailChildPage( TopicDetailPresenter.TYPE_NEW, widget.topicName), ], ), ), ); }

class TopicDetailChildPage extends StatefulWidget { int type = 0; // 0:hot 1:new String topicName;

TopicDetailChildPage(this.type, this.topicName);

@override State createState() { return new TopicDetailChildState(); } }

class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { _SliverAppBarDelegate(this.controller);

final TabController controller;

@override double get minExtent => kToolbarHeight;

@override double get maxExtent => kToolbarHeight;

@override Widget build( BuildContext context, double shrinkOffset, bool overlapsContent) { return new Container( color: Theme.of(context).cardColor, height: kToolbarHeight, child: new TabBar( controller: controller, key: new PageStorageKey(TabBar), labelColor: Colors.black87, indicatorColor: FunColors.themeColor, tabs: [ new Tab(text: '最热'), new Tab(text: '最新'), ], ), ); }

@override bool shouldRebuild(_SliverAppBarDelegate oldDelegate) { // return oldDelegate.controller != controller; return false; } }

class TopicDetailChildState extends LoadMoreState<TopicDetailPresenter, TopicDetailChildPage> implements TopicDetailView { List _dataSource = [];

@override void initState() { super.initState(); mPresenter.setType(widget.type); mPresenter.setTopicName(widget.topicName); mPresenter.fetchData(); }

@override Widget build(BuildContext context) { return _buildContent(); }

Widget _buildContent() { if (_dataSource == null || _dataSource.isEmpty) { return showLoading(); } else { return ListView.builder( itemCount: _dataSource.length, itemBuilder: (context, index) { return new PostWidget( _dataSource[index], PostWidget.SOURCE_TYPE_TOPIC); }); } }

@override TopicDetailPresenter newInstance() { return new TopicDetailPresenter(); }

@override void getTopicDetail(TopicBean topicBean) {}

@override void getPosts(List posts) { if (posts != null && posts.isNotEmpty) { setState(() { _dataSource.addAll(posts); }); } } } has a space

diegoveloper commented 6 years ago

nice observation, can you play with these values?

@override double get minExtent => _tabBar.preferredSize.height; @override double get maxExtent => _tabBar.preferredSize.height;

Maybe there is a padding on one of your widgets or by default. Put some fixed values there.