handle enter click when typing search field

This commit is contained in:
lukas-heiligenbrunner 2024-02-19 20:53:11 +01:00
parent d6b388fa03
commit 70f1d76554

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/svg.dart'; import 'package:flutter_svg/svg.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import '../../constants/color_constants.dart'; import '../../constants/color_constants.dart';
@ -12,29 +13,39 @@ class SearchField extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return TextField( return RawKeyboardListener(
controller: controller, focusNode: FocusNode(),
decoration: InputDecoration( onKey: (event) {
hintText: "Search", if (event.runtimeType == RawKeyDownEvent &&
fillColor: secondaryColor, event.logicalKey == LogicalKeyboardKey.enter) {
filled: true, context.push("/aur?query=${controller.text}");
border: const OutlineInputBorder( }
borderSide: BorderSide.none, },
borderRadius: BorderRadius.all(Radius.circular(10)), child: TextField(
), controller: controller,
suffixIcon: InkWell( decoration: InputDecoration(
onTap: () async { hintText: "Search",
context.push("/aur?query=${controller.text}"); fillColor: secondaryColor,
}, filled: true,
child: Container( border: const OutlineInputBorder(
padding: const EdgeInsets.all(defaultPadding * 0.75), borderSide: BorderSide.none,
margin: const EdgeInsets.symmetric(horizontal: defaultPadding / 2), borderRadius: BorderRadius.all(Radius.circular(10)),
decoration: const BoxDecoration( ),
color: darkgreenColor, suffixIcon: InkWell(
borderRadius: BorderRadius.all(Radius.circular(10)), onTap: () async {
), context.push("/aur?query=${controller.text}");
child: SvgPicture.asset( },
"assets/icons/Search.svg", child: Container(
padding: const EdgeInsets.all(defaultPadding * 0.75),
margin:
const EdgeInsets.symmetric(horizontal: defaultPadding / 2),
decoration: const BoxDecoration(
color: darkgreenColor,
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: SvgPicture.asset(
"assets/icons/Search.svg",
),
), ),
), ),
), ),