Created
January 23, 2024 15:17
-
-
Save demirdev/64cf4cfff133d53cfe0e70c711412c22 to your computer and use it in GitHub Desktop.
nested-scroll-tabbars.dart
This file contains hidden or 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'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith( | |
scaffoldBackgroundColor: darkBlue, | |
), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: TabTests(), | |
), | |
), | |
); | |
} | |
} | |
class TabTests extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return DefaultTabController( | |
length: 3, | |
child: NestedScrollView( | |
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { | |
return [ | |
SliverToBoxAdapter( | |
child: Text('Header'), | |
) | |
]; | |
}, | |
body: Scaffold( | |
appBar: AppBar( | |
bottom: const TabBar( | |
tabs: [ | |
Tab(icon: Icon(Icons.directions_car)), | |
Tab(icon: Icon(Icons.directions_transit)), | |
Tab(icon: Icon(Icons.directions_bike)), | |
], | |
), | |
title: const Text('Tabs Demo'), | |
), | |
body: TabBarView( | |
children: [ | |
TestTabView(), | |
TestTabView(), | |
TestTabView(), | |
], | |
), | |
), | |
), | |
); | |
} | |
} | |
class TestTabView extends StatefulWidget { | |
const TestTabView({ | |
super.key, | |
}); | |
@override | |
State<TestTabView> createState() => _TestTabViewState(); | |
} | |
class _TestTabViewState extends State<TestTabView> | |
with AutomaticKeepAliveClientMixin { | |
@override | |
Widget build(BuildContext context) { | |
return SingleChildScrollView( | |
child: Column(children: [ | |
for (int i = 0; i < 140; i++) | |
Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: Text('$i'), | |
) | |
])); | |
} | |
@override | |
bool get wantKeepAlive => true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment