颤振,飞镖指数

时间:2020-06-02 13:45:26

标签: flutter dart

我的项目中有一个索引值,但是当我运行应用程序时,索引值从0开始。我希望它从1开始,该怎么办?

tabBuilder: (BuildContext context, int index) {
return CupertinoTabView(
builder: (BuildContext context){
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('Page 1 of tab $index'),
backgroundColor: Colors.blue,
),

1 个答案:

答案 0 :(得分:0)

数组在dart中从0开始。 如果您希望用户界面在第一个位置显示1或在每个位置添加1,则可以使用index+1

tabBuilder: (BuildContext context, int index) {
return CupertinoTabView(
builder: (BuildContext context){
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('Page 1 of tab ${index+1}'), // add +1 to your index here
backgroundColor: Colors.blue,
),