Created
June 27, 2021 07:32
-
-
Save kmanadkat/3e12571fac31406af67915525078f2a7 to your computer and use it in GitHub Desktop.
Sliver App Bar Hiding Content Issue
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 'dart:math'; | |
| import 'package:flutter/material.dart'; | |
| void main() { | |
| runApp(MyApp()); | |
| } | |
| class MyApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| title: 'Flutter Demo', | |
| theme: ThemeData( | |
| primarySwatch: Colors.blue, | |
| visualDensity: VisualDensity.adaptivePlatformDensity, | |
| ), | |
| home: CustomSliverAppbar(), | |
| ); | |
| } | |
| } | |
| class CustomSliverAppbar extends StatefulWidget { | |
| @override | |
| _CustomSliverAppbarState createState() => _CustomSliverAppbarState(); | |
| } | |
| class _CustomSliverAppbarState extends State<CustomSliverAppbar> | |
| with SingleTickerProviderStateMixin { | |
| TabController _tabController; | |
| @override | |
| void initState() { | |
| _tabController = TabController( | |
| initialIndex: 0, | |
| length: 2, | |
| vsync: this, | |
| ); | |
| super.initState(); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| body: NestedScrollView( | |
| floatHeaderSlivers: true, | |
| headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { | |
| return <Widget>[ | |
| SliverAppBar( | |
| title: Text( | |
| "WhatsApp type sliver appbar", | |
| ), | |
| centerTitle: true, | |
| pinned: true, | |
| floating: true, | |
| bottom: TabBar( | |
| indicatorColor: Colors.black, | |
| labelPadding: const EdgeInsets.only( | |
| bottom: 16, | |
| ), | |
| controller: _tabController, | |
| tabs: [ | |
| Text("TAB A"), | |
| Text("TAB B"), | |
| ]), | |
| ), | |
| ]; | |
| }, | |
| body: TabBarView( | |
| controller: _tabController, | |
| children: [ | |
| TabA(), | |
| Text('Display Tab 2', | |
| style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| @override | |
| void dispose() { | |
| _tabController.dispose(); | |
| super.dispose(); | |
| } | |
| } | |
| class TabA extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scrollbar( | |
| child: ListView.separated( | |
| separatorBuilder: (context, child) => Divider( | |
| height: 1, | |
| ), | |
| padding: EdgeInsets.all(0.0), | |
| itemCount: 30, | |
| itemBuilder: (context, i) { | |
| return Container( | |
| height: 100, | |
| width: double.infinity, | |
| color: Colors.primaries[Random().nextInt(Colors.primaries.length)], | |
| ); | |
| }, | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment