Thursday, June 23, 2022

Search Bar

 Search Bar - 3.0.0


Package :-  Pubspec.yaml

                    flutter_search_bar: ^3.0.0-dev.1


class ErrorSolves extends StatefulWidget {
@override
_ErrorSolvesState createState() => _ErrorSolvesState();
}

class _ErrorSolvesState extends State<ErrorSolves> {

late SearchBar searchBar;
final GlobalKey<ScaffoldState>_scaffoldKey=GlobalKey<ScaffoldState>();

AppBar buildAppBar(BuildContext context){
return AppBar(
//title: Text("Search Bar"),
actions: [searchBar.getSearchAction(context)],
);
}

void onSubmitted(String value){
setState((){
var context = _scaffoldKey.currentContext;
if (context == null) {
return;
}
ScaffoldMessenger.maybeOf(context)
?.showSnackBar(new SnackBar(content: new Text('You wrote "$value"!')));
//_scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("you wrote $value")));
});
}

_ErrorSolvesState(){
searchBar=SearchBar(
inBar: false,
buildDefaultAppBar: buildAppBar,
setState: setState,
onSubmitted: onSubmitted,
onCleared: (){
print("cleared");
},
onClosed: (){
print("closed");
}
);
}

@override
Widget build(BuildContext context) {

return Scaffold(
appBar: searchBar.build(context),
key: _scaffoldKey,
body: ListView(
children: <Widget>[

Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[

TextButton(
child: Text("Don`t look at me! Press the search button!"),
onPressed: (){
print("worked");
}
),

],
),
],
),
);

}
}

No comments:

Post a Comment

Featured post

Compress Image With Show File Size & Resolution in Flutter

 Compress Image With Show File Size & Resolution  1.Multiple File Image Compress with file Size import 'dart:io' ; import 'p...

LightBlog