Flutter将SingleChildScrollView或ListView添加到屏幕中的部分窗口小部件

时间:2019-09-04 15:31:18

标签: flutter

我尝试在此以下实现的代码中为我的窗口小部件添加简单的滚动视图窗口小部件,例如 return MongoClient.connect(url, { useNewUrlParser: true, useUnifiedTopology: true},function(err, db) { if (err) throw err; var dbo = db.db("sdb"); dbo.collection("servers").findOne({id: `${message.guild.id}`}, function(err, result) { if(result.verification == "true") return message.channel.send("", {embed: new Discord.RichEmbed().setAuthor("Verification System:").setDescription("Verifications are already Enabled!").setColor("RED")}) if(!message.guild.channels.find(c => c.id === result.verificationchannel)) return message.channel.send("", {embed:new Discord.RichEmbed().setAuthor("Verification System:").setDescription("Verification Channels Must be setup!"+ `\nUse: \`${result.prefix}verification setchannel\``)}) if(!message.guild.roles.find(r => r.id === result.onjoinrole)) return message.channel.send("",{embed:new Discord.RichEmbed().setDescription("`Autorole` must be Setup in order to Enable this module!").setAuthor("Verification System:").setColor("RED")}) dbo.collection("servers").updateOne({ id: message.guild.id }, {$set: {verification: `true`}}, function(err, res) { message.channel.send("", { embed: new Discord.RichEmbed() .setAuthor("Verification System:") .setDescription(`Successfully Enabled Verifications!\nChannel: <#${result.verificationchannel}>`) .setFooter(`Enabled by: ${message.author.username}`, message.author.displayAvatarURL) }) }) }) if (err) throw err; db.close(); }) SingleChildScrollView,尽管我花了几个小时才为{{1}的父级添加此窗口小部件}小部件,我报错了,我无法做到这一点,

我想知道为什么这种实现应该让我们有时间添加简单的滚动视图

ListView

2 个答案:

答案 0 :(得分:1)

从代码中删除Spacer小部件,因为Column的父级是SingleChildScrollView

您不能将这两个小部件组合在一起,因为SingleChildScrollView没有定界,并且Spacer想要占用剩余的空间,因此它们彼此矛盾。

答案 1 :(得分:0)

有效

enter image description here

return Scaffold(
  body: Container(
    padding: EdgeInsets.all(20.0),
    child: Column(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Expanded(
          child: Container(
            margin: EdgeInsets.only(top: 10.0),
            child: Card(
              child: Container(
                  padding: EdgeInsets.all(10.0),
                  child: SingleChildScrollView(
                      child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisSize: MainAxisSize.min,
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: <Widget>[
                        Container(
                            constraints: BoxConstraints.expand(
                                height: MediaQuery.of(context).size.height),
                            child: Text('asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda asfdasasda asjdalksjda '))
                      ]))),
            ),
          ),
        ),
      ],
    ),
  ),
);