-1

When I try to generate more texts than my page can display I get this error enter image description here

Is there a way to make the content be scrollable instead? I followed some general instructions and all work fine as long as I write text manually by using Text(), sadly this doesn't fit what I'm looking for, since I need data to be generated automatically.

import 'package:flutter/cupertino.dart';
    import 'package:flutter/material.dart';
    void main() => runApp(MaterialApp(
          debugShowCheckedModeBanner: false,
          home: QuoteList(),
        ));
    class QuoteList extends StatefulWidget {
      @override
      _QuoteListState createState() => _QuoteListState();
    }
    class _QuoteListState extends State<QuoteList> {
      List<Quote> quotes = [
        Quote(author: 'aaa', text: 'aaa'),
        Quote(author: 'aaa', text: 'aaa'),
        Quote(author: 'aaa', text: 'aaa'),
        Quote(author: 'aaa', text: 'aaa'),
        Quote(author: 'aaa', text: 'aaa'),
        Quote(author: 'aaa', text: 'aaa'),
        Quote(author: 'aaa', text: 'aaa'),
        Quote(author: 'aaa', text: 'aaa'),
        Quote(author: 'aaa', text: 'aaa'),
        Quote(author: 'aaa', text: 'aaa'),
        Quote(author: 'aaa', text: 'aaa'),
        Quote(author: 'aaa', text: 'aaa'),
        Quote(author: 'aaa', text: 'aaa'),
        Quote(author: 'aaa', text: 'aaa'),
        Quote(author: 'aaa', text: 'aaa'),
        Quote(author: 'aaa', text: 'aaa'),
        Quote(author: 'aaa', text: 'aaa'),
        Quote(author: 'aaa', text: 'aaa'),
      ];
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            backgroundColor: Colors.grey[300],
            body: Container(
                width: double.infinity,
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                      begin: Alignment.topLeft,
                      end: Alignment.bottomRight,
                      colors: [
                        Colors.black,
                        Colors.black,
                      ]),
                ),
                child: Padding(
                  padding: EdgeInsets.fromLTRB(0.0, 3.0, 0.0, 3.0),
                  child: Column(
                    children: <Widget>[
                      Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: quotes
                            .map((quote) => QuoteCard(
                                quote: quote,
                                delete: () {
                                  setState(() {
                                    quotes.remove(quote);
                                  });
                                }))
                            .toList(),
                      )
                    ],
                  ),
                )));
      }
    }
    class QuoteCard extends StatelessWidget {
      final Quote quote;
      final Function delete;
      QuoteCard({this.quote, this.delete});
      @override
      Widget build(BuildContext context) {
        return Padding(
            padding: EdgeInsets.fromLTRB(0.0, 3.0, 0.0, 3.0),
            child: Container(
              child: Card(
                color: Colors.grey[800],
                child: Column(
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: <Widget>[
                      Container(
                        child: Row(
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: <Widget>[
                              SizedBox(
                                width: 20.0,
                              ),
                              Text(
                                '${quote.text}',
                                style: TextStyle(
                                  fontSize: 18.0,
                                  color: Colors.white,
                                  letterSpacing: 3.0,
                                ),
                              ),
                            ]),
                      ),
                      ListTile(
                        title: Row(
                          children: <Widget>[
                            Expanded(
                                child: RaisedButton(
                              child: Text("delete"),
                              onPressed: delete,
                              color: Colors.grey[900],
                              textColor: Colors.white,
                              padding: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 10.0),
                            )),
                            SizedBox(
                              width: 20.0,
                            ),
                          ],
                        ),
                      )
                    ]),
              ),
            ));
      }
    }
    class Quote {
      String text;
      String author;
      Quote({String this.text, String this.author});
    }
KikiDiki
  • 21
  • 6

4 Answers4

2

Please, run below code. i have solve this issue from your existing code,

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(
  debugShowCheckedModeBanner: false,
  home: QuoteList(),
));
class QuoteList extends StatefulWidget {
  @override
  _QuoteListState createState() => _QuoteListState();
}
class _QuoteListState extends State<QuoteList> {
  List<Quote> quotes = [
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.grey[300],
        body: Container(
            width: double.infinity,
            decoration: BoxDecoration(
              gradient: LinearGradient(
                  begin: Alignment.topLeft,
                  end: Alignment.bottomRight,
                  colors: [
                    Colors.black,
                    Colors.black,
                  ]),
            ),
            child: Padding(
              padding: EdgeInsets.fromLTRB(0.0, 3.0, 0.0, 3.0),
              child: SingleChildScrollView(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: quotes
                      .map((quote) => QuoteCard(
                      quote: quote,
                      delete: () {
                        setState(() {
                          quotes.remove(quote);
                        });
                      }))
                      .toList(),
                ),
              ),
            )));
  }
}
class QuoteCard extends StatelessWidget {
  final Quote quote;
  final Function delete;
  QuoteCard({this.quote, this.delete});
  @override
  Widget build(BuildContext context) {
    return Padding(
        padding: EdgeInsets.fromLTRB(0.0, 3.0, 0.0, 3.0),
        child: SingleChildScrollView(
          child: Container(
            child: Card(
              color: Colors.grey[800],
              child: Column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: <Widget>[
                    Container(
                      child: Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: <Widget>[
                            SizedBox(
                              width: 20.0,
                            ),
                            Text(
                              '${quote.text}',
                              style: TextStyle(
                                fontSize: 18.0,
                                color: Colors.white,
                                letterSpacing: 3.0,
                              ),
                            ),
                          ]),
                    ),
                    ListTile(
                      title: Row(
                        children: <Widget>[
                          Expanded(
                              child: RaisedButton(
                                child: Text("delete"),
                                onPressed: delete,
                                color: Colors.grey[900],
                                textColor: Colors.white,
                                padding: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 10.0),
                              )),
                          SizedBox(
                            width: 20.0,
                          ),
                        ],
                      ),
                    )
                  ]),
            ),
          ),
        ));
  }
}
class Quote {
  String text;
  String author;
  Quote({String this.text, String this.author});
}

enter image description here

Kaushik Bhingradiya
  • 827
  • 1
  • 13
  • 23
1

You can use Listview.builder for making list scrollable

Janvi Patel
  • 242
  • 1
  • 12
0

Use SingleChildScrollView widget.

For more details about SingleChildScrollView widget use below link: https://api.flutter.dev/flutter/widgets/SingleChildScrollView-class.html

Working code:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(
      debugShowCheckedModeBanner: false,
      home: QuoteList(),
    ));
class QuoteList extends StatefulWidget {
  @override
  _QuoteListState createState() => _QuoteListState();
}
class _QuoteListState extends State<QuoteList> {
  List<Quote> quotes = [
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
    Quote(author: 'aaa', text: 'aaa'),
  ];
  @override
Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.grey[300],
        body: SingleChildScrollView(
        child: Container(
            width: double.infinity,
            decoration: BoxDecoration(
                gradient: LinearGradient(
                    begin: Alignment.topLeft,
                    end: Alignment.bottomRight,
                    colors: [
                    Colors.black,
                    Colors.black,
                    ]),
            ),
            child: Padding(
                padding: EdgeInsets.fromLTRB(0.0, 3.0, 0.0, 3.0),
                child: Column(
                children: <Widget>[
                    Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: quotes
                        .map((quote) => QuoteCard(
                            quote: quote,
                            delete: () {
                                setState(() {
                                quotes.remove(quote);
                                });
                            }))
                        .toList(),
                    )
                ],
                ),
            )),
        ));
}
}
class QuoteCard extends StatelessWidget {
  final Quote quote;
  final Function delete;
  QuoteCard({this.quote, this.delete});
  @override
  Widget build(BuildContext context) {
    return Padding(
        padding: EdgeInsets.fromLTRB(0.0, 3.0, 0.0, 3.0),
        child: Container(
          child: Card(
            color: Colors.grey[800],
            child: Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: <Widget>[
                  Container(
                    child: Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: <Widget>[
                          SizedBox(
                            width: 20.0,
                          ),
                          Text(
                            '${quote.text}',
                            style: TextStyle(
                              fontSize: 18.0,
                              color: Colors.white,
                              letterSpacing: 3.0,
                            ),
                          ),
                        ]),
                  ),
                  ListTile(
                    title: Row(
                      children: <Widget>[
                        Expanded(
                            child: RaisedButton(
                          child: Text("delete"),
                          onPressed: delete,
                          color: Colors.grey[900],
                          textColor: Colors.white,
                          padding: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 10.0),
                        )),
                        SizedBox(
                          width: 20.0,
                        ),
                      ],
                    ),
                  )
                ]),
          ),
        ));
  }
}
class Quote {
  String text;
  String author;
  Quote({String this.text, String this.author});
}
Deepak
  • 1,373
  • 2
  • 10
  • 31
0

Wrap your cointner in SingleChildScrollview. It will make your list scrollable .Like

child: SingleChildScrollView(
          child: Container()
  )
Rahul Kushwaha
  • 5,473
  • 3
  • 26
  • 30