Add search button

This commit is contained in:
Oystein Kristoffer Tveit 2022-01-23 20:58:25 +01:00
parent 28f900c02e
commit 6aab6d57bc
3 changed files with 34 additions and 10 deletions

View File

@ -1,10 +1,19 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../models/themes/theme.dart';
import '../../routing/routes.dart'; import '../../routing/routes.dart';
import 'language_selector.dart'; import 'language_selector.dart';
class SearchBar extends StatelessWidget { class SearchBar extends StatelessWidget {
const SearchBar({Key? key}) : super(key: key); final TextEditingController controller = TextEditingController();
SearchBar({Key? key}) : super(key: key);
void _search(BuildContext context, String text) => Navigator.pushNamed(
context,
Routes.search,
arguments: text,
);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -13,17 +22,34 @@ class SearchBar extends StatelessWidget {
child: Column( child: Column(
children: [ children: [
TextField( TextField(
onSubmitted: (text) => onSubmitted: (text) => _search(context, text),
Navigator.pushNamed(context, Routes.search, arguments: text), controller: controller,
controller: TextEditingController(),
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Search', labelText: 'Search',
border: OutlineInputBorder( border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0), borderRadius: BorderRadius.circular(10.0),
), ),
suffixIconConstraints: const BoxConstraints.tightFor(height: 60),
suffixIcon: Material(
borderRadius: const BorderRadius.only(
topRight: Radius.circular(10.0),
bottomRight: Radius.circular(10.0),
),
color: AppTheme.jishoGreen.background,
child: IconButton(
onPressed: () {
if (controller.text.isNotEmpty)
_search(context, controller.text);
},
icon: const Icon(
Icons.search,
color: Colors.white,
),
),
),
), ),
), ),
const SizedBox(height: 10.0), const SizedBox(height: 20),
const LanguageSelector() const LanguageSelector()
], ],
), ),

View File

@ -8,9 +8,7 @@ class SearchView extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: const <Widget>[ children: <Widget>[SearchBar()],
SearchBar(),
],
); );
} }
} }

View File

@ -285,7 +285,7 @@ packages:
name: flutter_svg name: flutter_svg
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.2" version: "1.0.3"
flutter_test: flutter_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter
@ -407,7 +407,7 @@ packages:
name: just_audio_web name: just_audio_web
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.2" version: "0.4.3"
logging: logging:
dependency: transitive dependency: transitive
description: description: