Skip to content

Instantly share code, notes, and snippets.

@zmtzawqlp
Created April 24, 2020 09:02
Show Gist options
  • Save zmtzawqlp/933d0b3924848c32c07fa7f2477132e7 to your computer and use it in GitHub Desktop.
Save zmtzawqlp/933d0b3924848c32c07fa7f2477132e7 to your computer and use it in GitHub Desktop.
demo
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SamplePage(),
),
);
}
}
class SamplePage extends StatefulWidget {
SamplePage({Key key}) : super(key: key);
@override
_SamplePageState createState() => _SamplePageState();
}
class _SamplePageState extends State<SamplePage> with TickerProviderStateMixin {
TabController _tabController;
var tabData = ['tab1', 'tab2'];
@override
void initState() {
_tabController = TabController(length: tabData.length, vsync: this);
super.initState();
}
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Expanded(
child: NestedScrollView(
headerSliverBuilder: (c, d) {
return <Widget>[
SliverToBoxAdapter(
child: Container(
height: 50,
alignment: Alignment.center,
child: Text('Header'),
)),
SliverToBoxAdapter(
child: TabBar(
controller: _tabController,
tabs: [
...tabData.map(
(item) => Tab(
child: Text(item),
),
),
],
),
)
];
},
body: TabBarView(
controller: _tabController,
children: <Widget>[tabContent('tab1', 50), tabContent('tab2', 5)],
),
),
),
Container(
height: 50,
alignment: Alignment.center,
child: Text('Footer'),
),
],
);
}
Widget tabContent(
String title,
int length,
) {
return ListView.builder(
itemBuilder: (c, index) => ListTile(
title: Text('${title} item ${index}'),
trailing: Icon(Icons.access_alarm),
),itemCount: length,);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment