From 16ca1d2a691027e78a8ef2301ed7ede4e102649d Mon Sep 17 00:00:00 2001 From: h7x4 Date: Tue, 2 Mar 2021 23:35:47 +0100 Subject: [PATCH] Fix language selector design --- .../components/search/LanguageSelector.dart | 29 +++++++++---------- lib/view/screens/search.dart | 2 +- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/view/components/search/LanguageSelector.dart b/lib/view/components/search/LanguageSelector.dart index 730fc34..c8a98f2 100644 --- a/lib/view/components/search/LanguageSelector.dart +++ b/lib/view/components/search/LanguageSelector.dart @@ -2,19 +2,14 @@ import 'package:flutter/material.dart'; class LanguageSelector extends StatefulWidget { - final List _languages; - LanguageSelector(this._languages); @override - LanguageSelectorState createState() => new LanguageSelectorState(this._languages); + LanguageSelectorState createState() => new LanguageSelectorState(); } class LanguageSelectorState extends State { - final List _languages; - List isSelected = [true, false, false]; - - LanguageSelectorState(this._languages); + List isSelected; @override void initState() { @@ -25,12 +20,20 @@ class LanguageSelectorState extends State { @override Widget build(BuildContext context) { return ToggleButtons( - children: [ + isSelected: isSelected, + children: [ LanguageOption("Auto"), LanguageOption("Japanese"), LanguageOption("English") ], - isSelected: isSelected + selectedColor: Colors.blue, + onPressed: (int buttonIndex) { + setState(() { + for (var i in Iterable.generate(isSelected.length)) { + isSelected[i] = i == buttonIndex; + } + }); + }, ); } @@ -45,14 +48,8 @@ class LanguageOption extends StatelessWidget { Widget build(BuildContext context) { return Expanded( child: Container( - padding: EdgeInsets.symmetric(vertical: 10.0), + padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0), child: Center(child: Text(_language)), - decoration: BoxDecoration( - border: Border.all( - color: Colors.black, - width: 1.0, - ), - color: Colors.white), ), ); } diff --git a/lib/view/screens/search.dart b/lib/view/screens/search.dart index 3de1a76..23a7dd7 100644 --- a/lib/view/screens/search.dart +++ b/lib/view/screens/search.dart @@ -68,7 +68,7 @@ class SearchBar extends StatelessWidget { SizedBox( height: 10.0, ), - LanguageSelector(["Auto", "Japanese", "English"]) + LanguageSelector() ], ), );