【发布时间】:2021-12-01 02:44:55
【问题描述】:
我正在尝试制作一个用于教程目的的颤振展示应用程序,但无论我尝试了什么,我都无法在单击页脚项目后向其中添加小部件我失败了,所以我寻求那些知道什么的人的帮助他们在做什么 迷人论坛的人会帮助新手成为程序员吗?
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// This is the main application widget.
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatefulWidget(),
);
}
}
/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key);
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
/// This is the private State class that goes with MyStatefulWidget.
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
int _selectedIndex = 0;
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static const List<Widget> _widgetOptions = <Widget>[
Text(
'Index 0: Home',
style: optionStyle,
),
Text(
'Index 1: Business',
style: optionStyle,
),
Text(
'Index 2: School',
style: optionStyle,
),
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flutter showcase'),
),
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(null),
label: 'Butonlar',
),
BottomNavigationBarItem(
icon: Icon(null),
label: 'TextBox lar',
),
BottomNavigationBarItem(
icon: Icon(null),
label: 'ComboBoxlar',
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
),
);
}
}
更准确地说,我想替换
Text(
'Index 2: School',
style: optionStyle,
),
在此先感谢你们真的帮了很多忙!
【问题讨论】:
-
我无法理解您的问题。您可以添加示例代码来尝试您想要什么吗? (你想改变 _widgetOptions[index] 的内容吗?)