0

I have this seperate page that I navigate to it and I am testing my Question widget with a ListView.builder(). The error occurs when I navigate to the page, at ListView.builder(). I am new to ListView/GridView builders so I followed some tutorials about it. I can't figure out the issue here.

import 'package:flutter/material.dart';

import 'consonants.dart';
import 'functions.dart';
import 'question_bank.dart';

int sum = 0;

class HTP extends StatefulWidget {
  HTP({ Key? key }) : super(key: key);

  @override
  State<HTP> createState() => HTPState();
}

class HTPState extends State<HTP> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: title,
      home: Scaffold(
        backgroundColor: Color(0xFF88FFEF),
        appBar: AppBar(
          backgroundColor: theme_color,
          title: const Text(title,
            style: TextStyle(
              fontSize: 25,
              fontWeight: FontWeight.w400,
              color: Colors.white
            )
          )
        ),
        body: ListView(
          padding: const EdgeInsets.all(5),
          children: [
            Text('TITLE',
              style: TextStyle(
                fontSize: 28, fontWeight: FontWeight.w700)
            ),
            Question(
              'A',
              '1. ...\n2. ...',
              ['a', 'b', 'c'],
              ['etc 1', 'etc 2', 'etc 3']
            )
          ]
        )
      )
    );
  }

  Widget Question(String group_name, String conditions, List<String> subgroups, List<String> options) {
    return Column(
      children: [
        Text('GROUP $group_name',
          style: TextStyle(
            fontWeight: FontWeight.w800,
            fontSize: 18,
            color: theme_color
          )
        ),
        Align(
          alignment: Alignment.centerLeft,
          child: Text(conditions,
            style: TextStyle(fontSize: 16)
          )
        ),
        Align(
          alignment: Alignment.centerLeft,
          child: ListView.builder(
            itemCount: question_points.length,
            itemBuilder: (context, index) {
              return ListTile(
                title: Text(question_points[index].toString())
              );
            }
          )
        )
      ],
    );
  }
}

I am going to display the arguments passed to the widget without using a for loop.

3
  • 1
    there's no thing violates null safety in your widget, but how could you nest a list views, you should disable the scroll ability of the nested one (ListView.builder) in your question widget!! Commented Aug 12, 2024 at 20:07
  • 1
    What is question_points referring to? Are you force unwrapping something there? Also agree with @A-E you'll need to add shrinkWrap: true and physics: const NeverScrollableScrollPhysics() to your nested ListView in the Question widget Commented Aug 12, 2024 at 21:06
  • @rhpekarek That worked! Please answer this thread so I can choose it as the correct answer. Commented Aug 13, 2024 at 16:35

1 Answer 1

1

Add to your nested ListView in the Question Widget:

  • shrinkWrap: true
  • physics: const NeverScrollableScrollPhysics()

.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.