Skip to content

Instantly share code, notes, and snippets.

@pedromassango
Created June 2, 2019 21:36
Show Gist options
  • Save pedromassango/27b9b836c3557903f39126acbbce9998 to your computer and use it in GitHub Desktop.
Save pedromassango/27b9b836c3557903f39126acbbce9998 to your computer and use it in GitHub Desktop.
Fixed issue of Search App Bar
import 'package:flutter/material.dart';
void main() => runApp(SearchAppBar());
class SearchAppBar extends StatefulWidget {
@override
_SearchAppBarState createState() => new _SearchAppBarState();
}
class _SearchAppBarState extends State<SearchAppBar> {
String appTitle = "AppBar Title";
bool isSearchEnabled = true;
_switchSearchBarState(){
setState(() {
isSearchEnabled = !isSearchEnabled;
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: "My App 2019",
home: Scaffold(
appBar: AppBar(
elevation: 1,
backgroundColor: Color(0xFF1D5D51),
title: !isSearchEnabled ? Text(appTitle) : TextField(
style: new TextStyle(
color: Colors.white,
),
decoration: new InputDecoration(
border: InputBorder.none,
prefixIcon: new Icon(Icons.search,color: Colors.white),
hintText: "Search...",
hintStyle: new TextStyle(color: Colors.white)
),
),
actions: <Widget>[
IconButton(
icon: Icon(isSearchEnabled ? Icons.close : Icons.search),
onPressed: _switchSearchBarState,
),
IconButton(
onPressed: (){},
icon: Icon(Icons.filter_list),
),
IconButton(
onPressed: (){},
icon:Icon(Icons.more_vert),
)
]
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment