sliver_app_bar_title 1.0.1+7 sliver_app_bar_title: ^1.0.1+7 copied to clipboard
SliverAppBarTitle is a widget that can be used to show a title on pinned SliverAppBar based on scrolling and particular widget
import 'package:flutter/material.dart';
import 'package:sliver_app_bar_title/sliver_app_bar_title.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
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,
))
],
),
);
}
}