【问题标题】:Flutter : Display Values inside GridView depending on Selected CategoryFlutter:根据所选类别在 GridView 内显示值
【发布时间】:2020-10-18 23:22:07
【问题描述】:

我有一个显示 _customCard 的应用程序,它是 GridView 中的自定义卡片。我想控制 GridView 中卡片的内容,以便可以根据 6 个不同类别的选定值 SelectedCategory 进行更改。

这里是我控制 SelectedCategory 的地方:

_favouritePressed(int index){
    setState(() {
      selectedIndex = index;
    });
  }

这里是GridView的代码:

GridView.count(
          crossAxisCount: 2,
          children: <Widget>[
            _customCard(
              imageUrl: "assassin.png", item: "game", price: "\$50", count: 1
            ),
            _customCard(
              imageUrl: "sedan.png", item: "car", price: "\$25", count: 4
            ),
            _customCard(
              imageUrl: "blouse.png", item: "T-shirt", price: "\$20", count: 2
            ),
            _customCard(
              imageUrl: "toy.png", item: "kids", price: "\$2", count: 3
            ),
          ],
        ),

【问题讨论】:

    标签: flutter dart gridview card


    【解决方案1】:

    我不确定我是否理解您的问题,但我会尝试解决方案:

    GridView.count(
          crossAxisCount: 2,
          children: <Widget>[
            if (selectedIndex==0)
              _customCard(
                imageUrl: "assassin.png", item: "game", price: "\$50", count: 1
              ),
            if (selectedIndex==1)
              _customCard(
                imageUrl: "sedan.png", item: "car", price: "\$25", count: 4
              ),
            if (selectedIndex==2)
              _customCard(
                imageUrl: "blouse.png", item: "T-shirt", price: "\$20", count: 2
              ),
            if (selectedIndex==3)
              _customCard(
                imageUrl: "toy.png", item: "kids", price: "\$2", count: 3
              ),
          ],
        ),
    

    抱歉,如果我误解了您的问题。

    【讨论】:

    • 首先感谢您的帮助.. 我的意思是我希望根据一个类别的选择来改变四个 _cusomCards 的详细信息
    • 那么也许你应该看一个函数来根据卡片ID和所选索引查找卡片属性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-05
    • 1970-01-01
    • 2015-07-02
    相关资源
    最近更新 更多