English 中文(简体)
如何将部分职能分散在冲碎中?
原标题:How to loop somepart of function in flutter?

I want to loop some part of function base on widget.menuItem.category.length, I am new in flutter. Here is my current code :

_buildContentView({BuildContext context}) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: <Widget>[
        _buildMenuItemImage(),
        Container(
          child: Text(widget.menuItem.name,
              style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
          padding: EdgeInsets.only(left: 16, right: 16, top: 12, bottom: 8),
        ),
        Container(
          child: Text(widget.menuItem.itemDescription,
              style: TextStyle(fontSize: 18, fontWeight: FontWeight.normal)),
          padding: EdgeInsets.only(left: 16, right: 16, top: 12, bottom: 8),
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Container(
              child: Text( Select   + widget.menuItem.category[0]),
              padding: EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 6),
            ),
            Container(
              child: Text( Select   +
                  _qty.toString() +
                    item (  +
                  _qty.toString() +
                   /  +
                  widget.menuItem.setMenuItems.length.toString() +
                   ) ),
              padding: EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 6),
            ),
          ],
        ),
        _buildSetMenusView(setMenuItems: widget.menuItem.setMenuItems),
        Padding(
          padding: EdgeInsets.only(left: 12, right: 12, top: 8, bottom: 12),
          child: _buildActionButtons(context: context),
        )
      ],
    );
  }

我想谈谈这一部分:

Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Container(
              child: Text( Select   + widget.menuItem.category[0]),
              padding: EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 6),
            ),
            Container(
              child: Text( Select   +
                  _qty.toString() +
                    item (  +
                  _qty.toString() +
                   /  +
                  widget.menuItem.setMenuItems.length.toString() +
                   ) ),
              padding: EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 6),
            ),
          ],
        ),
        _buildSetMenusView(setMenuItems: widget.menuItem.setMenuItems),

我尝试了这一法典,但没有成功。

for(var i = 0; i < widget.menuItem.category.length; i++){
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Container(
              child: Text( Select   + widget.menuItem.category[i]),
              padding: EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 6),
            ),
            Container(
              child: Text( Select   +
                  _qty.toString() +
                    item (  +
                  _qty.toString() +
                   /  +
                  widget.menuItem.setMenuItems.length.toString() +
                   ) ),
              padding: EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 6),
            ),
          ],
        ),
        _buildSetMenusView(setMenuItems: widget.menuItem.setMenuItems),
}

哪一部正确的法典能够把这一部分放在冲碎中? 请帮助我修复这一冲破碎的隔op。

问题回答

如果获得你的权利,你就必须在<条码>内填上植被。 页: 1 当你有大批儿童种植植被时,以及你想要在需求的基础上建设这些植被时,便选择了“ListView.builder。 这里,你如何在<代码>内填满植被。 名单:

  1. Import Flutter Material: First, make sure you have imported the necessary Flutter material library in your Dart file.
import  package:flutter/material.dart ;
  1. Create a ListView.builder: Define a ListView.builder widget. This widget takes a builder function that generates the list items dynamically based on the index.
ListView.builder(
  itemCount: itemCount, // Replace itemCount with the actual number of items you have.
  itemBuilder: (BuildContext context, int index) {
    // Here, you can return a widget for each list item based on the index.
    return YourListItemWidget(index); // Replace YourListItemWidget with your custom widget.
  },
)
  1. Create Your Custom List Item Widget: You ll need to create a custom widget for each item in the list. This is where you can define the layout and design of your list items.
class YourListItemWidget extends StatelessWidget {
  final int index;

  YourListItemWidget(this.index);

  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: Text( Item $index ), // Customize this based on your data.
      // Add other widgets and styling as needed.
    );
  }
}
  1. www.un.org/Depts/DGACM/index_spanish.htm 用你的数据取代项目Count和YouListItemWidget:。 在<代码>ListView.builder上,将itemCount与您名单上所列项目的实际数目相替换,并将与您的习俗清单项目重重。

  2. Display the ListView.builder: Finally, add your ListView.builder to your widget tree in the appropriate part of your Flutter app.

Here s a complete example:

import  package:flutter/material.dart ;

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text( ListView.builder Example ),
        ),
        body: MyListView(),
      ),
    );
  }
}

class MyListView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemCount: 20, // Replace with the actual number of items.
      itemBuilder: (BuildContext context, int index) {
        return YourListItemWidget(index); // Replace with your custom widget.
      },
    );
  }
}

class YourListItemWidget extends StatelessWidget {
  final int index;

  YourListItemWidget(this.index);

  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: Text( Item $index ), // Customize this based on your data.
      // Add other widgets and styling as needed.
    );
  }
}

将<条码>项目编码>(Count)和<条码>(YourListItemWidget的内容改为您的实际数据和根据需要定制植被。 这将使你能够使用<代码”编制一个可滚动项目清单。 ListView.builder in Flutter.

虽然你在哥伦内找工作,并想归还多种植被,但你可以为此使用假操作器。

for(var i = 0; i < widget.menuItem.category.length; i++)
  ...[
      Row(),
      _buildSetMenusView()
     ], 

另外,你还可以回来另一兄弟。





相关问题
Memory Leak when using for(object in array) with iPhone SDK

I am running into some serious memory leaks in one of my applications I am building. I have a UINavigatonController that is inside a UITabBarview. Inside the NavView is a MKMap view. When you click an ...

PHP - Foreach loops and ressources

I m using a foreach loop to process a large set of items, unfortunately it s using alot of memory. (probably because It s doing a copy of the array). Apparently there is a way to save some memory with ...

as2 simple for loop not populating textbox

I have got an xml file that brings text into a flash movie in the form of an array, I need to population some textboxes and want to do this using a for loop. My loop look like this: for(var i=...

Weird acting loop in C#

Note: I added actual code snippets. Just scroll to end. // files is created by a OpenFileDialog. public void Function(String[] files, ...) { for(int i; i<files.Length; i++) { ...

iterating over map and array simultaneously in a for loop

I am having some trouble creating a for loop within a constructor to iterate over a map and an array at the same time. Here, it is indicated that this cannot be done with an enhanced for loop. I have ...

Are one-line if / for -statements good Python style?

Every so often on here I see someone s code and what looks to be a one-liner , that being a one line statement that performs in the standard way a traditional if statement or for loop works. I ...

Geocoding town names to their coordinates in a loop

I ve read similar posts, but still didn t find a solution for myself. Basically I have an array with countries+towns in PHP and I need to show them on the map with markers. Here is my code: function ...

热门标签