Guest User

Untitled

a guest
Jan 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. // SearchForm Implementation
  2.  
  3. class _SearchBar extends StatefulWidget {
  4. final GithubSearchBloc githubSearchBloc;
  5.  
  6. _SearchBar({Key key, this.githubSearchBloc}) : super(key: key);
  7.  
  8. @override
  9. State<_SearchBar> createState() => _SearchBarState();
  10. }
  11.  
  12. class _SearchBarState extends State<_SearchBar> {
  13. final _textController = TextEditingController();
  14.  
  15. GithubSearchBloc get githubSearchBloc => widget.githubSearchBloc;
  16.  
  17. @override
  18. Widget build(BuildContext context) {
  19. return TextField(
  20. controller: _textController,
  21. autocorrect: false,
  22. onChanged: (text) {
  23. githubSearchBloc.dispatch(
  24. TextChanged(text: text),
  25. );
  26. },
  27. decoration: InputDecoration(
  28. prefixIcon: Icon(Icons.search),
  29. suffixIcon: GestureDetector(
  30. child: Icon(Icons.clear),
  31. onTap: _onClearTapped,
  32. ),
  33. border: InputBorder.none,
  34. hintText: 'Enter a search term',
  35. ),
  36. );
  37. }
  38.  
  39. void _onClearTapped() {
  40. _textController.text = '';
  41. githubSearchBloc.dispatch(TextChanged(text: ''));
  42. }
  43. }
Add Comment
Please, Sign In to add comment