Как реализовать замену текста из String с помощью DropdownButton?
Я новичок во Flutter, учусь самостоятельно. Делаю проект приложения с книгами. На странице книги есть шапка баннера, под ним DropdownButton и текст главы книги.
Тексты отдельных глав вынесены в отдельный класс Strings (Vincenco) и реализованы через Text.
Вопрос: как заставить DropdownButton изменить String (texto1) на другую String (texto2)? И, учитывая большое количество глав, можно ли прописать это через List? Заранее благодарен!
P.s. 'texto1a' и 'texto2a' - это названия главы книги над текстом главы.
class _BookMainWidgetState extends State<BookMainWidget> {
String texto1 = Vincenco.v1;
String texto1a = Vincenco.v1a;
String texto2 = Vincenco.v2;
String texto2a = Vincenco.v2a;
var _locations = [
'Глава 1',
'Глава 2',
'Глава 3',
'Глава 4',
'Глава 5',
];
var _currentItemSelected = 'Глава 1';
@override
Widget build(BuildContext context) {
return Stack(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Stack(
children: [
Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.black.withOpacity(0.2)),
borderRadius: BorderRadius.all(Radius.circular(10)),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.2),
blurRadius: 8,
offset: Offset(0, 3),
),
],),
clipBehavior: Clip.hardEdge,
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DropdownButton(
hint: Text(' Выберите главу...'),
isExpanded: true,
onChanged: (newValue) {},
value: _currentItemSelected,
items: _locations.map((
String dropDownStringItem) {
return new DropdownMenuItem<String>(
value: dropDownStringItem,
child: new Text(dropDownStringItem),
);
}).toList()
),
SizedBox(height: 10),
Column(
children: [
Padding(
padding: const EdgeInsets.all(
8.0),
child:
Text(texto1a,
style: TextStyle(
color: Colors.brown,
fontSize: 16,
fontWeight: FontWeight
.bold),
),
),
Padding(
padding: const EdgeInsets.all(
8.0),
child:
Text(texto1,
style: TextStyle(fontSize: 14,
fontWeight: FontWeight
.bold),
),
),
]
),