Matt123
Matt123

Reputation: 411

Flutter returning multiple widgets stuck

I am working on a Flutter widget but I can't seem to get it to return multiple widgets. The Widget is called Widg and it should return the listView.builder widget and the floatingActionButton widget. 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!

Upvotes: 0

Views: 7719

Answers (1)

cmd_prompter
cmd_prompter

Reputation: 1680

This should work.

FloatingActionButton documentation for your reference.

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();
      },
    ),
  );
}

Upvotes: 1

Related Questions