Guest User

Untitled

a guest
Feb 15th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() => runApp(
  4. MaterialApp(
  5. home: MyApp()
  6. ,
  7. )
  8. );
  9.  
  10.  
  11. class MyApp extends StatefulWidget{
  12. MyAppState createState() => MyAppState();
  13. }
  14.  
  15. class MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
  16.  
  17. TabController tabController;
  18. Widget _tabBarView;
  19.  
  20. @override
  21. void initState() {
  22. super.initState();
  23. tabController = TabController(length: 2, vsync: this,);
  24. _tabBarView = TabBarView(
  25. children: [
  26. DemoTab(),
  27. DemoTab(),
  28. ]);
  29. }
  30.  
  31. @override
  32. Widget build(BuildContext context) {
  33. return Scaffold(
  34. body: NestedScrollView(
  35. controller: ScrollController(keepScrollOffset: true),
  36. headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
  37. return <Widget>[
  38. SliverList(
  39. delegate: SliverChildListDelegate(
  40. [
  41. Container(height: 300, color: Colors.blue)
  42. ]
  43. ),
  44. ),
  45. ];
  46. },
  47. body: DefaultTabController(
  48. length: 2,
  49. child: Column(
  50. children: <Widget>[
  51. Expanded(
  52. child: Container(
  53. child: _tabBarView
  54. ),
  55. ),
  56. ],
  57. ),
  58. )
  59. ),
  60. );
  61. }
  62. }
  63.  
  64. class DemoTab extends StatefulWidget{
  65. DemoTabState createState() => DemoTabState();
  66. }
  67.  
  68. class DemoTabState extends State<DemoTab> with AutomaticKeepAliveClientMixin<DemoTab>{
  69. @override
  70. // TODO: implement wantKeepAlive
  71. bool get wantKeepAlive => true;
  72.  
  73.  
  74. @override
  75. Widget build(BuildContext context) {
  76.  
  77. return ListView.builder(
  78. key: UniqueKey(),
  79. itemBuilder: (b, i) {
  80. return Container(
  81. height: 50,
  82. color: Colors.green,
  83. margin: EdgeInsets.only(bottom: 3),
  84. child: Text(i.toString(),),
  85. );
  86. }, itemCount: 30,) ;
  87.  
  88. }
  89. }
Add Comment
Please, Sign In to add comment