Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() => runApp(
- MaterialApp(
- home: MyApp()
- ,
- )
- );
- class MyApp extends StatefulWidget{
- MyAppState createState() => MyAppState();
- }
- class MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
- TabController tabController;
- Widget _tabBarView;
- @override
- void initState() {
- super.initState();
- tabController = TabController(length: 2, vsync: this,);
- _tabBarView = TabBarView(
- children: [
- DemoTab(),
- DemoTab(),
- ]);
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: NestedScrollView(
- controller: ScrollController(keepScrollOffset: true),
- headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
- return <Widget>[
- SliverList(
- delegate: SliverChildListDelegate(
- [
- Container(height: 300, color: Colors.blue)
- ]
- ),
- ),
- ];
- },
- body: DefaultTabController(
- length: 2,
- child: Column(
- children: <Widget>[
- Expanded(
- child: Container(
- child: _tabBarView
- ),
- ),
- ],
- ),
- )
- ),
- );
- }
- }
- class DemoTab extends StatefulWidget{
- DemoTabState createState() => DemoTabState();
- }
- class DemoTabState extends State<DemoTab> with AutomaticKeepAliveClientMixin<DemoTab>{
- @override
- // TODO: implement wantKeepAlive
- bool get wantKeepAlive => true;
- @override
- Widget build(BuildContext context) {
- return ListView.builder(
- key: UniqueKey(),
- itemBuilder: (b, i) {
- return Container(
- height: 50,
- color: Colors.green,
- margin: EdgeInsets.only(bottom: 3),
- child: Text(i.toString(),),
- );
- }, itemCount: 30,) ;
- }
- }
Add Comment
Please, Sign In to add comment