xxxxxxxxxx
import 'package:flutter/material.dart';
class SearchBarWidget extends StatefulWidget {
@override
_SearchBarWidgetState createState() => _SearchBarWidgetState();
}
class _SearchBarWidgetState extends State<SearchBarWidget> {
TextEditingController _searchController = TextEditingController();
@override
void dispose() {
_searchController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AppBar(
title: TextField(
controller: _searchController,
decoration: InputDecoration(
hintText: 'Search...',
),
onChanged: (value) {
// Perform search operations based on the entered value
},
),
);
}
}
xxxxxxxxxx
SearchBar(
hintText: "Search",
controller: controller,
padding: MaterialStateProperty.all<EdgeInsets>(
const EdgeInsets.symmetric(horizontal: 15)),
leading: const Icon(Icons.search),
trailing: const [Icon(Icons.mic)],
),
xxxxxxxxxx
import 'package:flutter/material.dart';
class SearchBar extends StatefulWidget {
@override
_SearchBarState createState() => _SearchBarState();
}
class _SearchBarState extends State<SearchBar> {
TextEditingController _searchController = TextEditingController();
@override
Widget build(BuildContext context) {
return TextField(
controller: _searchController,
onChanged: (value) {
// Perform search logic based on the input value
// You can call a function or update the search results here
print('Search query: $value');
},
decoration: InputDecoration(
hintText: 'Search',
prefixIcon: Icon(Icons.search),
),
);
}
}
// Usage:
SearchBar()
xxxxxxxxxx
import 'package:flutter/material.dart';
class SearchBar extends StatefulWidget {
@override
_SearchBarState createState() => _SearchBarState();
}
class _SearchBarState extends State<SearchBar> {
String searchString = '';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Search Bar'),
),
body: Column(
children: [
Padding(
padding: EdgeInsets.all(10.0),
child: TextField(
onChanged: (value) {
setState(() {
searchString = value;
});
},
decoration: InputDecoration(
labelText: 'Search',
),
),
),
Text('Search String: $searchString'),
],
),
);
}
}
void main() {
runApp(MaterialApp(
home: SearchBar(),
));
}