Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save GiangHoGoVap/9bfae0344ae858673be6cdf7b2677f4a to your computer and use it in GitHub Desktop.

Select an option

Save GiangHoGoVap/9bfae0344ae858673be6cdf7b2677f4a to your computer and use it in GitHub Desktop.
Pinned search bar.
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),
),
),
*/
),
Container(
alignment: Alignment.center,
margin: EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.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,
color: Colors.blue,
),
],
),
),
],
),
);
}
}
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: 0,
child: Center(child: widget),
),
);
}
@override
double get maxExtent => 105.0;
@override
double get minExtent => 105.0;
@override
bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
return true;
}
}
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,
),
),
);
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment