Skip to content

itsmeabhi12/sliver_app_bar_title

Repository files navigation

SliverAppBarTitle is a widget that can be used to show a title on pinned SliverAppBar based on scrolling and particular widget

Features

  • Can target a particular widget in a List
  • Animation
  • Automatically show / hides title on SliverAppBar

Demo

Usage

First create a GlobalKey and then assign that key to target widget now the sliver app bar title will be visible once the targeted widget go behinds the sliver app bar

class _MyHomePageState extends State<MyHomePage> {
  final globalKey = GlobalKey();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          SliverAppBar(
            pinned: true,
            title: SliverAppBarTitle(
              targetWidgetKey: globalKey,
              duration: const Duration(milliseconds: 100),
              child: const Text("Number 2 is hidden"),
            ),
            expandedHeight: 256,
          ),
          SliverList(
              delegate: SliverChildBuilderDelegate(
            (BuildContext context, int index) {
              return Container(
                color: index.isOdd ? Colors.white : Colors.black12,
                height: 100.0,
                child: Center(
                  child: Text('$index',
                      key: index == 2 ? globalKey : null, textScaleFactor: 5),
                ),
              );
            },
            childCount: 20,
          ))
        ],
      ),
    );
  }
}

Info

Feel free to request any missing features or report issues here.

License

Copyright (c) 2022 Abhishek Ghimire

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.