简体   繁体   English

Flutter 返回多个小部件卡住

[英]Flutter returning multiple widgets stuck

I am working on a Flutter widget but I can't seem to get it to return multiple widgets.我正在开发 Flutter 小部件,但似乎无法让它返回多个小部件。 The Widget is called Widg and it should return the listView.builder widget and the floatingActionButton widget.该小部件称为 Widg,它应该返回 listView.builder 小部件和 floatActionButton 小部件。 Here is my code:这是我的代码:

@override
Widget build(BuildContext context) {
  return <Widget>[

    //children: <Widget> [
      ListView.builder(
      itemCount: list.length,
      itemBuilder: (context, i) {
        return listRow();
      },
    ),
    floatingActionButton: FloatingActionButton(
      child: Icon(Icons.add),
      onPressed: () {
        setState(() {
          list.add(list.length);
        });
      }
    )
  ]
  ];
}

I am unable to figure out how to do this.我无法弄清楚如何做到这一点。 I tried listing them as children as per the comment, but it didn't work.我尝试根据评论将他们列为孩子,但没有用。 This is where I call my widget:这是我调用我的小部件的地方:



  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("Next Page"),
      ),

        body: Widg()


    );
  }

Can someone please help me out?有人可以帮我吗? Thanks!谢谢!

This should work.这应该有效。

FloatingActionButton documentation for your reference. FloatingActionButton 文档供您参考。

import 'package:flutter/material.dart';

Widget build(BuildContext context) {
  List list;
  return new Scaffold(
    floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () {
          setState(() {
            list.add(list.length);
          });
        }),
    appBar: new AppBar(
      title: new Text("Next Page"),
    ),
    body: ListView.builder(
      itemCount: list.length,
      itemBuilder: (context, i) {
        return listRow();
      },
    ),
  );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM