65 lines
2.1 KiB
Dart
65 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:mymuseum_visitapp/Helpers/translationHelper.dart';
|
|
import 'package:mymuseum_visitapp/app_context.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../constants.dart';
|
|
|
|
class SearchBox extends StatefulWidget {
|
|
const SearchBox({
|
|
Key? key,
|
|
this.onChanged,
|
|
this.width,
|
|
}) : super(key: key);
|
|
|
|
final ValueChanged? onChanged;
|
|
final double? width;
|
|
|
|
@override
|
|
State<SearchBox> createState() => _SearchBoxState();
|
|
}
|
|
|
|
class _SearchBoxState extends State<SearchBox> {
|
|
final TextEditingController _controller = TextEditingController();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Size size = MediaQuery.of(context).size;
|
|
final appContext = Provider.of<AppContext>(context);
|
|
|
|
return Container(
|
|
width: widget.width ?? size.width*0.65,
|
|
margin: const EdgeInsets.all(kDefaultPadding),
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: kDefaultPadding,
|
|
vertical: kDefaultPadding / 4, // 5 top and bottom
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white.withValues(alpha: 0.4),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: TextFormField(
|
|
cursorColor: kMainColor,
|
|
controller: _controller,
|
|
onChanged: widget.onChanged,
|
|
style: const TextStyle(color: Colors.white),
|
|
decoration: InputDecoration(
|
|
enabledBorder: InputBorder.none,
|
|
focusedBorder: InputBorder.none,
|
|
icon: const Icon(Icons.search, color: Colors.white),
|
|
hintText: TranslationHelper.getFromLocale("search", appContext.getContext()),
|
|
hintStyle: const TextStyle(color: Colors.white),
|
|
contentPadding: const EdgeInsets.symmetric(vertical: 13.0),
|
|
suffixIcon: _controller.value.text.isNotEmpty ? InkWell(
|
|
onTap: () {
|
|
if(_controller.value.text.isNotEmpty) {
|
|
_controller.clear();
|
|
widget.onChanged!("");
|
|
}
|
|
},
|
|
child: const Icon(Icons.close, color: Colors.white)
|
|
): const Text(''),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |