Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to create This type of appbar in flutter

Please give some code regarding this image

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can try this SliverPersistentHeaderDelegate. Play with shrinkOffset. I thought It might be easier with CupertinoSliverNavigationBar but it needed to maintain height for multiline.

class AppSliverPersistentHeader extends SliverPersistentHeaderDelegate {
  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
    return Stack(
      children: [
        Align(
          alignment: Alignment.lerp(const Alignment(-1, 0),
              const Alignment(0, 0), (shrinkOffset / maxExtent))!,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Text("Text A"),
              Text("Text B"),
            ],
          ),
        )
      ],
    );
  }

  @override
  double get maxExtent => 120;

  @override
  double get minExtent => kToolbarHeight;

  @override
  bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) {
    return false;
  }
}

And test snippet

class AppBarTest extends StatelessWidget {
  const AppBarTest({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          // CupertinoSliverNavigationBar(
          //   largeTitle: Column(
          //     children: [
          //       Text.rich(TextSpan(text: "MyContaint", children: [
          //         TextSpan(
          //             text: "\nothers",
          //             style: TextStyle(
          //               fontSize: 12,
          //             ))
          //       ])),
          //     ],
          //   ),
          // ),
          SliverPersistentHeader(
            pinned: true,
            delegate: AppSliverPersistentHeader(),
          ),
          SliverToBoxAdapter(
            child: Container(
              height: 3333,
            ),
          ),
        ],
      ),
    );
  }
}

You can choose two stack items instead of one column.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading