Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振:如何从映射(列表)中检索索引_Flutter_Dart_Flutter Layout - Fatal编程技术网

Flutter 颤振:如何从映射(列表)中检索索引

Flutter 颤振:如何从映射(列表)中检索索引,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,我目前正在进行颤振开发,我需要从映射中检索索引到脚手架的其他部分。是否可以将索引值从下面的映射检索到脚手架的其他部分(浮动操作按钮) Iterable获取正整数同步*{ int i=articleList.length-1; 虽然(真的)产生了我--; } @凌驾 小部件构建(构建上下文){ int getLength=articleList.length; var list=positiveIntegers.take(getLength.toList(); 返回脚手架( appBar:appB

我目前正在进行颤振开发,我需要从映射中检索索引到脚手架的其他部分。是否可以将索引值从下面的映射检索到脚手架的其他部分(浮动操作按钮)

Iterable获取正整数同步*{
int i=articleList.length-1;
虽然(真的)产生了我--;
}
@凌驾
小部件构建(构建上下文){
int getLength=articleList.length;
var list=positiveIntegers.take(getLength.toList();
返回脚手架(
appBar:appBar(
标题:新文本(
"大众",,
textAlign:textAlign.center,
),
textTheme:textTheme(
标题:文本样式(
尺寸:16,
fontWeight:fontWeight.w700,
颜色:颜色。黑色),
背景颜色:Colors.white,
标题:对,
标高:0.0,
),
正文:SwipeStack(
子项:list.map((索引){
...
}
),
浮动操作按钮:容器(
页边距:仅限边集(顶部:25,底部:25,左侧:20),
对齐:对齐(0,1),
孩子:新的一排(
儿童:[
原材料按钮(
已按下:(){
if(isOutOfCards==true){
设置状态(){
isOutOfCards=false;
});
}
},
子项:iconBuild(上下文),
形状:新的CircleBorder(),
fillColor:Colors.red[700],
splashColor:Colors.transparent,
highlightColor:Colors.transparent,
填充:常量边集。全部(11),
),
buttonTextBuild(上下文),
],
),
),
);
}
小部件buttonTextBuild(构建上下文){
如果(isOutOfCards==false){
返回容器(
子项:文本(“$cardIndex/${articleList.length}”,
textAlign:textAlign.left,
样式:TextStyle(
字体大小:12.75,
fontWeight:fontWeight.w500,
字母间距:1);
}否则{
返回容器(
子项:文本('重新开始',
textAlign:textAlign.left,
样式:TextStyle(
字体大小:12.75,
fontWeight:fontWeight.w500,
字母间距:1);
}
}

像上面的代码一样,我想从list.map中检索“index”,并将其传递给buttonTextBuild中的cardIndex。

您可以这样做:

儿童:[
for(int index=0;index

文本小部件只是一个例子,您可以使用您需要的任何小部件或调用传递函数来获取项目

您可以这样做:

儿童:[
for(int index=0;index
文本小部件只是一个示例,您可以使用所需的任何小部件或调用传递函数来获取项目

您可以使用:

子项:枚举(列表).map((indexedValue){
var指数=indexedValue.index;
var值=indexedValue.value;
...
}),
您可以使用:

子项:枚举(列表).map((indexedValue){
var指数=indexedValue.index;
var值=indexedValue.value;
...
}),

使用
List.asMap()
。检查文档。使用
List.asMap()
。检查文档。如何将其传递到int中?因为它的stringlist[index]是int,将其传递给您需要的任何对象。我如何将其传递到int中?因为它的stringlist[index]是int,将其传递给您需要的任何对象
  Iterable<int> get positiveIntegers sync* {
    int i = articleList.length - 1;
    while (true) yield i--;
  }

  @override
  Widget build(BuildContext context) {
    int getLength = articleList.length;
    var list = positiveIntegers.take(getLength).toList();

    return Scaffold(
      appBar: AppBar(
        title: new Text(
          'Popular',
          textAlign: TextAlign.center,
        ),
        textTheme: TextTheme(
            title: TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.w700,
                color: Colors.black)),
        backgroundColor: Colors.white,
        centerTitle: true,
        elevation: 0.0,
      ),
      body: SwipeStack(
          children: list.map((index) {
              ...
          }
      ),
      floatingActionButton: Container(
        margin: EdgeInsets.only(top: 25, bottom: 25, left: 20),
        alignment: Alignment(0, 1),
        child: new Row(
          children: <Widget>[
            RawMaterialButton(
              onPressed: () {
                if (isOutOfCards == true) {
                  setState(() {
                    isOutOfCards = false;
                  });
                }
              },
              child: iconBuild(context),
              shape: new CircleBorder(),
              fillColor: Colors.red[700],
              splashColor: Colors.transparent,
              highlightColor: Colors.transparent,
              padding: const EdgeInsets.all(11),
            ),
            buttonTextBuild(context),
          ],
        ),
      ),
    );
  }

  Widget buttonTextBuild(BuildContext context) {
    if (isOutOfCards == false) {
      return Container(
          child: Text('$cardIndex/${articleList.length}',
              textAlign: TextAlign.left,
              style: TextStyle(
                  fontSize: 12.75,
                  fontWeight: FontWeight.w500,
                  letterSpacing: 1)));
    } else {
      return Container(
          child: Text('Start Again',
              textAlign: TextAlign.left,
              style: TextStyle(
                  fontSize: 12.75,
                  fontWeight: FontWeight.w500,
                  letterSpacing: 1)));
    }
  }