Created
June 7, 2017 14:47
-
-
Save HansMuller/e43fecb89706a0245e5b300352482012 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class MyHomePage extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => new _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin { | |
final int numTabs = 20; | |
TabController tabController; | |
@override | |
void initState() { | |
super.initState(); | |
tabController = new TabController(initialIndex: 0, length: numTabs, vsync: this); | |
} | |
@override | |
Widget build(BuildContext context) { | |
List<Widget> pages = <Widget>[]; | |
List<Tab> tabs = <Tab>[]; | |
for (int i = 0; i < numTabs; i++) { | |
pages.add(_buildTab(context, i)); | |
tabs.add(new Tab(text: 'Tab $i')); | |
} | |
return new Scaffold( | |
appBar: new AppBar( | |
title: new Text('MyHomePage'), | |
bottom: new TabBar( | |
controller: tabController, | |
tabs: tabs, | |
isScrollable: true, | |
), | |
), | |
body: new TabBarView( | |
//key: new PageStorageKey<String>('TabBarView'), | |
controller: tabController, | |
children: pages, | |
), | |
); | |
} | |
Widget _buildTab(BuildContext context, int i) { | |
return new MyPage(pageNum: i); | |
} | |
} | |
class MySliverChildDelegate extends SliverChildDelegate { | |
MySliverChildDelegate(this.pageNum); | |
int pageNum; | |
Widget build(BuildContext context, int i) { | |
return new ListTile(title: new Text('Page $pageNum ListTile $i'),); | |
} | |
bool shouldRebuild(MySliverChildDelegate old) { | |
return false; | |
} | |
} | |
class MyPage extends StatefulWidget { | |
MyPage({this.pageNum}); | |
final int pageNum; | |
@override | |
MyPageState createState() => new MyPageState(); | |
} | |
class MyPageState extends State<MyPage> { | |
ScrollController scrollController; | |
@override | |
void initState() { | |
super.initState(); | |
scrollController = new ScrollController(keepScrollOffset: true); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return new KeyedSubtree( | |
key: new PageStorageKey<String>('Page ${widget.pageNum}'), | |
child: new RefreshIndicator( | |
onRefresh: () async { }, | |
child: new CustomScrollView( | |
controller: scrollController, | |
slivers: <Widget>[ | |
new SliverList( | |
delegate: new MySliverChildDelegate(widget.pageNum), | |
), | |
], | |
), | |
), | |
); | |
} | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return | |
} | |
} | |
void main() { | |
runApp(new MaterialApp(home: new MyHomePage())); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment