Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:flutter_svg/flutter_svg.dart';
- import 'package:material_floating_search_bar/material_floating_search_bar.dart';
- class SearchPage extends StatefulWidget {
- const SearchPage({Key? key}) : super(key: key);
- @override
- _SearchPageState createState() => _SearchPageState();
- }
- class _SearchPageState extends State<SearchPage> {
- final controller = FloatingSearchBarController();
- late FocusNode _focusNode;
- @override
- void initState() {
- super.initState();
- _focusNode = FocusNode();
- }
- @override
- Widget build(BuildContext context) {
- return SafeArea(
- child: Scaffold(
- body: Center(
- child: buildFloatingSearchBar(),
- ),
- ),
- );
- }
- Widget buildFloatingSearchBar() {
- final isPortrait =
- MediaQuery.of(context).orientation == Orientation.portrait;
- return FloatingSearchBar(
- hint: 'Search...',
- scrollPadding: const EdgeInsets.only(top: 16, bottom: 56),
- transitionDuration: const Duration(milliseconds: 800),
- transitionCurve: Curves.easeInOut,
- physics: const BouncingScrollPhysics(),
- axisAlignment: isPortrait ? 0.0 : -1.0,
- openAxisAlignment: 0.0,
- width: isPortrait ? 600 : 500,
- debounceDelay: const Duration(milliseconds: 500),
- onQueryChanged: (query) {
- print('Query changed: $query');
- },
- onFocusChanged: (hasFocus) {
- print('Focus changed: $hasFocus');
- },
- transition: CircularFloatingSearchBarTransition(),
- actions: [
- FloatingSearchBarAction(
- showIfOpened: false,
- child: CircularButton(
- icon: const Icon(Icons.place),
- onPressed: () {},
- ),
- ),
- FloatingSearchBarAction.searchToClear(
- showIfClosed: false,
- ),
- ],
- builder: (context, transition) {
- return ClipRRect(
- borderRadius: BorderRadius.circular(8),
- child: Material(
- color: Colors.white,
- elevation: 4.0,
- child: _buildSearchHistoryContainer(),
- ),
- );
- },
- );
- }
- Widget _buildSearchHistoryContainer() {
- return Container(
- padding: EdgeInsets.all(20),
- height: 200,
- child: Column(
- children: [
- const SizedBox(height: 8),
- _buildSearchHistoryHeader(),
- ],
- ),
- );
- }
- Widget _buildSearchHistoryHeader() {
- return Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(
- 'Search history',
- style: TextStyle(
- fontSize: 16,
- fontWeight: FontWeight.w500,
- ),
- ),
- const SizedBox(width: 8),
- SvgPicture.asset(
- "assets/icons/trash_small.svg",
- ),
- ],
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement