Skip to content

Instantly share code, notes, and snippets.

@demirdev
Created January 23, 2024 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save demirdev/64cf4cfff133d53cfe0e70c711412c22 to your computer and use it in GitHub Desktop.
Save demirdev/64cf4cfff133d53cfe0e70c711412c22 to your computer and use it in GitHub Desktop.
nested-scroll-tabbars.dart
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