Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/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 - Fatal编程技术网

Flutter 通过小部件构造函数传递数据

Flutter 通过小部件构造函数传递数据,flutter,dart,Flutter,Dart,我丢失了一小段关于构造函数的信息,我试图通过小部件升级卡([…])传递一些数据。我在调试控制台中看不到任何错误。我尝试了小部件和其他不同的东西来显示数据,但我无法找出下面这段代码的错误 注意:当我打印snapshot.data时,我可以看到它完全返回 请帮忙 **promotions_page.dart** class PromotionsPage extends StatefulWidget { @override _PromotionsPageState createState()

我丢失了一小段关于构造函数的信息,我试图通过小部件升级卡([…])传递一些数据。我在调试控制台中看不到任何错误。我尝试了小部件和其他不同的东西来显示数据,但我无法找出下面这段代码的错误

注意:当我打印snapshot.data时,我可以看到它完全返回

请帮忙

**promotions_page.dart**

class PromotionsPage extends StatefulWidget {
  @override
  _PromotionsPageState createState() => _PromotionsPageState();
}

class _PromotionsPageState extends State<PromotionsPage> {
  Future<Result> _promotionsResultsData;

  @override
  void initState() {
    _promotionsResultsData = PromotionApi().fetchPromotions();

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        margin: EdgeInsets.symmetric(horizontal: 10.0, vertical: 20.0),
        child: ListView(
          physics: PageScrollPhysics(),
          children: [
            Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      'Акции',
                      style: TextStyle(
                        fontSize: 18.0,
                        fontWeight: FontWeight.bold,
                        fontFamily: 'BuffetBold',
                      ),
                    ),
                    InkWell(
                      onTap: () => print('Archive promotion pressed!'),
                      child: Text(
                        'Архив Акции',
                        style: TextStyle(
                          fontSize: 16.0,
                          fontWeight: FontWeight.bold,
                          fontFamily: 'BuffetBold',
                          color: Colors.grey[400],
                        ),
                      ),
                    ),
                  ],
                ),
                SizedBox(
                  height: 10.0,
                ),
                Container(
                  child: FutureBuilder<Result>(
                    future: _promotionsResultsData,
                    builder: (context, snapshot) {
                      if (snapshot.hasData) {
                        return GridView.builder(
                          padding: EdgeInsets.zero,
                          gridDelegate:
                              SliverGridDelegateWithFixedCrossAxisCount(
                            childAspectRatio: (45 / 35),
                            crossAxisCount: 1,
                          ),
                          shrinkWrap: true,
                          physics: ScrollPhysics(),
                          itemCount: snapshot.data.result.length,
                          itemBuilder: (BuildContext context, int index) {
                            //print(snapshot.data.result.length);
                            var promos = snapshot.data.result[index];
                            PromotionCard(
                                id: promos.id,
                                title: promos.title,
                                description: promos.description,
                                image: promos.image);
                          },
                        );
                      } else {}
                      return Center(
                        child: Text(
                          "Loading ...",
                          style: TextStyle(
                              fontWeight: FontWeight.w900, fontSize: 30.0),
                        ),
                      );
                    },
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

你错过了回报声明

itemBuilder: (BuildContext context, int index) {
                            //print(snapshot.data.result.length);
                            var promos = snapshot.data.result[index];
                            // you have to return the widget
                            return PromotionCard(
                                id: promos.id,
                                title: promos.title,
                                description: promos.description,
                                image: promos.image);
                          },

谢谢你,伙计。真不敢相信:)欢迎@ShareKnowledge。
itemBuilder: (BuildContext context, int index) {
                            //print(snapshot.data.result.length);
                            var promos = snapshot.data.result[index];
                            // you have to return the widget
                            return PromotionCard(
                                id: promos.id,
                                title: promos.title,
                                description: promos.description,
                                image: promos.image);
                          },