Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

when i use ListView.builder it show error

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

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

  @override
  _GameQuizState createState() => _GameQuizState();
}

class _GameQuizState extends State<GameQuiz> {
  List options = ["option 1", "option 2", "option 3", "option 4"];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: MediaQuery.of(context).size.width,
        decoration: const BoxDecoration(
          color: Colors.deepPurple,
          image: DecorationImage(
              image: AssetImage(
                "assets/images/background.jpg",
              ),
              fit: BoxFit.cover),
        ),
        child: Padding(
          padding: const EdgeInsets.fromLTRB(20, 100, 20, 0),
          child: Column(children: [
            Text(
              "Animal Kingdom Quiz",
              style: GoogleFonts.fredokaOne(
                  color: Colors.white,
                  fontSize: 40,
                  fontWeight: FontWeight.bold),
              textAlign: TextAlign.center,
            ),
            Padding(
              padding: const EdgeInsets.fromLTRB(20, 60, 20, 20),
              child: Container(
                width: MediaQuery.of(context).size.width - 40,
                decoration:
                    BoxDecoration(color: Colors.purple.withOpacity(0.3)),
                child: Padding(
                  padding: const EdgeInsets.only(top: 30),
                  child: Column(
                    children: [
                      Text(
                        "My Question",
                        style: GoogleFonts.fredokaOne(
                            color: Colors.white,
                            fontSize: 24,
                            fontWeight: FontWeight.bold),
                      )
                      ListView.builder(
                          itemCount: options.length,
                          itemBuilder: (context , index){
                            return Text(options[index]);
                          }),
                      
                    ],
                  ),
                ),
              ),
            ),
          ]),
        ),
      ),
    );
  }
}

>Solution :

inside your ListView.builder use ‘shrinkWrap: true’ like this code snippet

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading