Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
List of data in Flutter is not showing

I have a list of quotes (three quotes) and am using the map function to map through the list of quotes to create a small widget for each one. But the quotes doesn't display on the app.

import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    home: QuoteList(),
  ));
}

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

  @override
  State<QuoteList> createState() => _QuoteListState();
}

class _QuoteListState extends State<QuoteList> {

  List<String> quotes = [
    "There are three constants in life.. change, choice and principles.",
    "In three words I can sum up everything Ive learned about life: it goes on.",
    "Guests, like fish, begin to smell after three days."
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[200],
      appBar: AppBar(
        title: Text('Awesome Quotes'),
        centerTitle: true,
        backgroundColor: Colors.redAccent,
      ),
      body: Column(
        children: quotes.map((e) => Text(e)).toList(),
      ),
    );
  }
}
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Works perfect on DartPad.

Try to run "flutter clean" and then "flutter run "

about 4 years ago · Juan Pablo Isaza Relatório

0

try this instead of column

ListView.builder(
        itemCount: 5,
        itemBuilder: (BuildContext context,int index){
      return Text(quotes[index]);
        }
        ),
    );
about 4 years ago · Juan Pablo Isaza Relatório

0

Move the quotes variable initialization inside the build method.

class _QuoteListState extends State<QuoteList> {
  @override
  Widget build(BuildContext context) {
    var quotes = [
      "There are three constants in life.. change, choice and principles.",
      "In three words I can sum up everything Ive learned about life: it goes on.",
      "Guests, like fish, begin to smell after three days."
    ];

    return Scaffold(
      backgroundColor: Colors.grey[200],
      appBar: AppBar(
        title: Text('Awesome Quotes'),
        centerTitle: true,
        backgroundColor: Colors.redAccent,
      ),
      body: Column(
        children: quotes.map((e) => Text(e)).toList(),
      ),
    );
  }
}

Also you can use type inference and use var instead of clarifying List<String>.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda