Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Add the searchEnabled flag to getSearchAction #27

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_search_bar/flutter_search_bar.dart';

Expand All @@ -22,12 +24,13 @@ class SearchBarDemoHome extends StatefulWidget {

class _SearchBarDemoHomeState extends State<SearchBarDemoHome> {
SearchBar searchBar;
bool searchEnabled = false;
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();

AppBar buildAppBar(BuildContext context) {
return new AppBar(
title: new Text('Search Bar Demo'),
actions: [searchBar.getSearchAction(context)]);
actions: [searchBar.getSearchAction(context, searchEnabled)]);
}

void onSubmitted(String value) {
Expand All @@ -48,11 +51,20 @@ class _SearchBarDemoHomeState extends State<SearchBarDemoHome> {

@override
Widget build(BuildContext context) {
enableSearchAfterTenSeconds();
return new Scaffold(
appBar: searchBar.build(context),
key: _scaffoldKey,
body: new Center(
child: new Text("Don't look at me! Press the search button!")),
);
}

void enableSearchAfterTenSeconds() {
Future.delayed(Duration(seconds: 10), () {
setState(() {
searchEnabled = true;
});
});
}
}
6 changes: 2 additions & 4 deletions lib/src/flutter_search_bar_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,10 @@ class SearchBar {
/// Returns an [IconButton] suitable for an Action
///
/// Put this inside your [buildDefaultAppBar] method!
IconButton getSearchAction(BuildContext context) {
IconButton getSearchAction(BuildContext context, bool searchEnabled) {
return new IconButton(
icon: new Icon(Icons.search),
onPressed: () {
beginSearch(context);
}
onPressed: searchEnabled ? () => beginSearch(context) : null
);
}

Expand Down