Last active
September 19, 2020 13:19
-
-
Save TokisakiKurumi2001/f5e93e4330e0121873c38844dbe87ae9 to your computer and use it in GitHub Desktop.
Pinned search bar.
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 'package:flutter/material.dart'; | |
| class HeaderWithSearchBox extends StatelessWidget { | |
| const HeaderWithSearchBox({ | |
| Key key, | |
| @required this.size, | |
| }) : super(key: key); | |
| final Size size; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Container( | |
| height: size.height * 0.12, | |
| child: Stack( | |
| children: <Widget>[ | |
| Container( | |
| padding: EdgeInsets.only( | |
| left: 20.0, | |
| right: 20.0, | |
| bottom: 56, | |
| ), | |
| height: size.height * 0.2 - 100, | |
| decoration: BoxDecoration( | |
| color: Colors.blue, | |
| borderRadius: BorderRadius.only( | |
| bottomLeft: Radius.circular(36), | |
| bottomRight: Radius.circular(36), | |
| ), | |
| ), | |
| ), | |
| Positioned( | |
| top: 45, | |
| left: 0, | |
| right: 0, | |
| child: Container( | |
| alignment: Alignment.center, | |
| margin: EdgeInsets.symmetric(horizontal: 20.0), | |
| padding: EdgeInsets.symmetric(horizontal: 20.0), | |
| height: 54, | |
| decoration: BoxDecoration( | |
| color: Colors.white, | |
| borderRadius: BorderRadius.circular(20), | |
| boxShadow: [ | |
| BoxShadow( | |
| offset: Offset(0, 10), | |
| blurRadius: 50, | |
| color: Colors.blue.withOpacity(0.23), | |
| ), | |
| ], | |
| ), | |
| child: Row( | |
| children: <Widget>[ | |
| Expanded( | |
| child: TextField( | |
| onChanged: (value) {}, | |
| decoration: InputDecoration( | |
| hintText: "Search", | |
| hintStyle: TextStyle( | |
| color: Colors.blue.withOpacity(0.5), | |
| ), | |
| enabledBorder: InputBorder.none, | |
| focusedBorder: InputBorder.none, | |
| ), | |
| ), | |
| ), | |
| Icon(Icons.search), | |
| ], | |
| ), | |
| ), | |
| ), | |
| ], | |
| ), | |
| ); | |
| } | |
| } | |
| class PersistentHeader extends SliverPersistentHeaderDelegate { | |
| final Widget widget; | |
| PersistentHeader({this.widget}); | |
| @override | |
| Widget build( | |
| BuildContext context, double shrinkOffset, bool overlapsContent) { | |
| return Container( | |
| width: double.infinity, | |
| height: 105.0, | |
| child: Card( | |
| margin: EdgeInsets.all(0), | |
| color: Colors.white, | |
| elevation: 5.0, | |
| child: Center(child: widget), | |
| ), | |
| ); | |
| } | |
| @override | |
| double get maxExtent => 105.0; | |
| @override | |
| double get minExtent => 105.0; | |
| @override | |
| bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) { | |
| return true; | |
| } | |
| } |
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 'package:ForLingo/home/components/word/wordpage.dart'; | |
| import 'package:flutter/material.dart'; | |
| //import 'components/body.dart'; | |
| import 'components/header_with_searchbox.dart'; | |
| import 'components/bottom_nav_bar/bottom_nav_bar.dart'; | |
| import 'components/word/add.dart'; | |
| class HomeScreen extends StatefulWidget { | |
| @override | |
| _HomeScreenState createState() => _HomeScreenState(); | |
| } | |
| class _HomeScreenState extends State<HomeScreen> { | |
| @override | |
| Widget build(BuildContext context) { | |
| Size size = MediaQuery.of(context).size; | |
| return Scaffold( | |
| //appBar: buildAppBar(), | |
| //body: Body(), | |
| body: CustomScrollView( | |
| slivers: <Widget>[ | |
| SliverAppBar( | |
| elevation: 0, | |
| pinned: false, | |
| snap: false, | |
| floating: true, | |
| flexibleSpace: FlexibleSpaceBar( | |
| centerTitle: true, | |
| title: Text( | |
| '4Lingo', | |
| style: TextStyle( | |
| fontSize: 30.0, | |
| fontWeight: FontWeight.bold, | |
| ), | |
| ), | |
| ), | |
| // shape: RoundedRectangleBorder( | |
| // borderRadius: BorderRadius.vertical( | |
| // bottom: Radius.circular(20), | |
| // ), | |
| // ), | |
| ), | |
| // SliverAppBar( | |
| // toolbarHeight: 80, | |
| // pinned: true, | |
| // backgroundColor: Colors.white, | |
| // automaticallyImplyLeading: false, | |
| // actions: <Widget>[ | |
| // Container(), | |
| // ], | |
| // title: HeaderWithSearchBox(size: size), | |
| // ), | |
| SliverPersistentHeader( | |
| pinned: true, | |
| delegate: PersistentHeader( | |
| widget: HeaderWithSearchBox(size: size), | |
| ), | |
| ), | |
| SliverList( | |
| delegate: SliverChildListDelegate( | |
| [ | |
| Column( | |
| children: <Widget>[ | |
| Word(), | |
| ], | |
| ), | |
| ], | |
| ), | |
| ), | |
| ], | |
| ), | |
| bottomNavigationBar: MyBottomNavBar(), | |
| floatingActionButton: Padding( | |
| padding: const EdgeInsets.all(10.0), | |
| child: FloatingActionButton( | |
| onPressed: () { | |
| Navigator.push( | |
| context, MaterialPageRoute(builder: (context) => Adding())) | |
| .then((value) => setState(() {})); | |
| }, | |
| child: Icon( | |
| Icons.add, | |
| color: Colors.white, | |
| ), | |
| ), | |
| ), | |
| drawer: Drawer( | |
| child: ListView( | |
| padding: EdgeInsets.zero, | |
| children: <Widget>[ | |
| DrawerHeader( | |
| child: Text( | |
| '4Lingo', | |
| style: TextStyle( | |
| fontSize: 50.0, | |
| fontWeight: FontWeight.bold, | |
| ), | |
| ), | |
| decoration: BoxDecoration( | |
| color: Colors.blue, | |
| ), | |
| ), | |
| ListTile( | |
| title: Text( | |
| 'Guide', | |
| style: TextStyle( | |
| fontSize: 30.0, | |
| fontWeight: FontWeight.bold, | |
| ), | |
| ), | |
| onTap: () { | |
| //Guide popup | |
| Navigator.pop(context); | |
| }, | |
| ), | |
| ListTile( | |
| title: Text( | |
| 'Setting', | |
| style: TextStyle( | |
| fontSize: 30.0, | |
| fontWeight: FontWeight.bold, | |
| ), | |
| ), | |
| onTap: () { | |
| //Setting popup | |
| Navigator.pop(context); | |
| }, | |
| ), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| /* | |
| AppBar buildAppBar() { | |
| return AppBar( | |
| centerTitle: true, | |
| elevation: 0, | |
| title: Text( | |
| '4Lingo', | |
| style: TextStyle( | |
| fontSize: 30, | |
| fontWeight: FontWeight.bold, | |
| ), | |
| ), | |
| ); | |
| } | |
| */ | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference from: https://stackoverflow.com/questions/61127826/how-to-pin-a-container-or-any-other-widget-below-appbar-in-scroll-view-in-flutte