Jisho-Study-Tool/lib/view/components/search/LanguageSelector.dart

54 lines
1.2 KiB
Dart
Raw Normal View History

2021-03-02 22:26:59 +01:00
import 'package:flutter/material.dart';
class LanguageSelector extends StatefulWidget {
@override
2021-03-03 00:24:25 +01:00
_LanguageSelectorState createState() => new _LanguageSelectorState();
2021-03-02 22:26:59 +01:00
}
2021-03-03 00:24:25 +01:00
class _LanguageSelectorState extends State<LanguageSelector> {
2021-03-02 23:35:47 +01:00
List<bool> isSelected;
2021-03-02 22:26:59 +01:00
@override
void initState() {
super.initState();
isSelected = [true, false, false];
}
@override
Widget build(BuildContext context) {
return ToggleButtons(
2021-03-02 23:35:47 +01:00
isSelected: isSelected,
children: <Widget> [
2021-03-03 00:24:25 +01:00
_LanguageOption("Auto"),
_LanguageOption("Japanese"),
_LanguageOption("English")
2021-03-02 22:26:59 +01:00
],
2021-03-02 23:35:47 +01:00
selectedColor: Colors.blue,
onPressed: (int buttonIndex) {
setState(() {
for (var i in Iterable.generate(isSelected.length)) {
isSelected[i] = i == buttonIndex;
}
});
},
2021-03-02 22:26:59 +01:00
);
}
}
2021-03-03 00:24:25 +01:00
class _LanguageOption extends StatelessWidget {
final String language;
2021-03-02 22:26:59 +01:00
2021-03-03 00:24:25 +01:00
_LanguageOption(this.language);
2021-03-02 22:26:59 +01:00
@override
Widget build(BuildContext context) {
return Expanded(
child: Container(
2021-03-02 23:35:47 +01:00
padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
2021-03-03 00:24:25 +01:00
child: Center(child: Text(language)),
2021-03-02 22:26:59 +01:00
),
);
}
}