revanced-manager/lib/ui/widgets/search_bar.dart

86 lines
2.6 KiB
Dart
Raw Normal View History

2022-08-02 12:26:37 +02:00
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class SearchBar extends StatefulWidget {
2022-08-08 01:24:45 +02:00
final String? hintText;
final Color? backgroundColor;
2022-08-11 22:17:10 +02:00
final Color? fillColor;
2022-08-08 01:24:45 +02:00
final Color? hintTextColor;
2022-08-07 21:15:52 +02:00
2022-08-08 01:24:45 +02:00
const SearchBar({
2022-08-07 21:15:52 +02:00
required this.hintText,
this.backgroundColor = const Color(0xff1B222B),
this.hintTextColor = Colors.white,
2022-08-11 22:17:10 +02:00
required this.fillColor,
2022-08-02 12:26:37 +02:00
Key? key,
2022-08-02 15:11:29 +02:00
required this.onQueryChanged,
2022-08-02 12:26:37 +02:00
}) : super(key: key);
2022-08-02 15:11:29 +02:00
final Function(String) onQueryChanged;
2022-08-02 12:26:37 +02:00
@override
State<SearchBar> createState() => _SearchBarState();
}
class _SearchBarState extends State<SearchBar> {
2022-08-12 00:45:51 +02:00
final TextEditingController _textController = TextEditingController();
2022-08-02 12:26:37 +02:00
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
2022-08-07 21:15:52 +02:00
color: widget.backgroundColor,
2022-08-02 12:26:37 +02:00
border: Border.all(
2022-08-08 01:24:45 +02:00
color: widget.backgroundColor != null
? widget.backgroundColor!
: Colors.white,
2022-08-02 12:26:37 +02:00
width: 1,
),
),
child: Row(
children: [
Expanded(
child: TextField(
2022-08-02 15:11:29 +02:00
onChanged: widget.onQueryChanged,
2022-08-12 00:45:51 +02:00
controller: _textController,
2022-08-02 12:26:37 +02:00
decoration: InputDecoration(
2022-08-11 22:17:10 +02:00
fillColor: widget.fillColor,
2022-08-02 12:26:37 +02:00
filled: true,
contentPadding: const EdgeInsets.all(12.0),
2022-08-07 21:15:52 +02:00
hintText: widget.hintText,
2022-08-02 12:26:37 +02:00
hintStyle: GoogleFonts.poppins(
2022-08-07 21:15:52 +02:00
color: widget.hintTextColor,
2022-08-02 12:26:37 +02:00
fontWeight: FontWeight.w400,
),
prefixIcon: const Icon(
Icons.search,
size: 24.0,
),
2022-08-12 00:45:51 +02:00
suffixIcon: _textController.text.isNotEmpty
? IconButton(
icon: const Icon(Icons.clear),
iconSize: 24.0,
onPressed: () {
_textController.clear();
widget.onQueryChanged('');
},
)
: null,
2022-08-02 12:26:37 +02:00
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide.none,
),
),
style: GoogleFonts.poppins(
color: Colors.white,
fontWeight: FontWeight.w400,
fontSize: 16,
),
),
),
],
),
);
}
}