1
0
mirror of https://github.com/h7x4/Jisho-Study-Tool.git synced 2024-12-22 13:57:29 +01:00
Jisho-Study-Tool/lib/components/search/language_selector.dart
h7x4 28f900c02e
Add more content to search results (#31)
* Add lots of new functionality to search results

* Fix jlpt level

* Make antonyms clickable

* Add kanji list

* Replace Blocof with BlocBuilder

* Make kanji widgets squared

* Add missing colons to headers

* add romaji under sentences

* Fix extensive search not showing

* Miscellaneous refactoring
2022-01-23 18:27:00 +01:00

62 lines
1.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../models/themes/theme.dart';
class LanguageSelector extends StatefulWidget {
const LanguageSelector({Key? key}) : super(key: key);
@override
_LanguageSelectorState createState() => _LanguageSelectorState();
}
class _LanguageSelectorState extends State<LanguageSelector> {
final SharedPreferences prefs = GetIt.instance.get<SharedPreferences>();
late List<bool> isSelected;
@override
void initState() {
super.initState();
isSelected = _getSelectedStatus() ?? [false, false, false];
}
Future<void> _updateSelectedStatus() async => prefs.setStringList(
'languageSelectorStatus',
isSelected.map((b) => b ? '1' : '0').toList(),
);
List<bool>? _getSelectedStatus() => prefs
.getStringList('languageSelectorStatus')
?.map((s) => s == '1')
.toList();
Widget _languageOption(String language) =>
Container(
alignment: Alignment.center,
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
child: Text(language),
);
@override
Widget build(BuildContext context) {
return ToggleButtons(
selectedColor: AppTheme.jishoGreen.background,
isSelected: isSelected,
children: <Widget>[
_languageOption('Auto'),
_languageOption('日本語'),
_languageOption('English')
],
onPressed: (buttonIndex) {
setState(() {
for (final int i in Iterable.generate(isSelected.length)) {
isSelected[i] = i == buttonIndex;
}
_updateSelectedStatus();
});
},
);
}
}