Home > OS >  List of buttons using ListTile Flutter
List of buttons using ListTile Flutter

Time:03-26

I am getting an error while trying to compile my code could anyone help me fix it? I am trying to create a list of buttons that will navigate to another screen. It was previously a expansion tile and I am trying to switch it to a list tile.

    return ListTile(
      title: Text(StudyViewModel.studies[index].name,
          style: TextStyle(fontSize: 18.0)),
      children: <Widget>[
        ListView.builder(
          shrinkWrap: true,
          physics: ClampingScrollPhysics(),
          itemCount: StudyViewModel.studies[index].tasks.length,
          itemBuilder: (context, int taskIndex) {
            return ListTile(
              title: Text(StudyViewModel.studies[index].tasks[taskIndex].name),
              contentPadding: EdgeInsets.symmetric(horizontal: 32.0),
              subtitle: Text(
                  StudyViewModel.studies[index].tasks[taskIndex].elapsedTime),
            );
          },
        ),

Based off of responses, the goal of this code is to create a list of buttons that have previously been defined in a template. These buttons will be used in a time study app. I would like to be able to upload the activities into a new page. Originally, the code was written as an expansiontile, but I am trying to change it to a listtile. The error we are encountering is:

lib/pages/home_page.dart:107:7: Error: No named parameter with the name 'children'. children: [ ^^^^^^^^ ../../lib/flutter/packages/flutter/lib/src/material/list_tile.dart:762:9: Context: Found this candidate, but the arguments don't match. const ListTile({ ^^^^^^^^ Failed to compile application.

CodePudding user response:

The ListTile widget doesn't contain a parameter named children. In your code you're setting a parameter 'children' which is invalid.

This might help:

return ListView(
    children: <Widget>[
        Text(StudyViewModel.studies[index].name,
            style: TextStyle(fontSize: 18.0),
        ),
        ListView.builder(
            shrinkWrap: true,
            primary: false,
            itemCount: StudyViewModel.studies[index].tasks.length,
            itemBuilder: (context, int taskIndex) {
                return ListTile(
                    title: Text(StudyViewModel.studies[index].tasks[taskIndex].name),
                    contentPadding: EdgeInsets.symmetric(horizontal: 32.0),
                    subtitle: Text(StudyViewModel.studies[index].tasks[taskIndex].elapsedTime),
                );
            },
        ),
  • Related