flutter - 我得到了小部件库捕获的异常
问题描述
import 'package:app1/answer.dart';
import 'package:flutter/material.dart';
import 'question.dart';
import 'answer.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
MyAppState createState() => MyAppState();
}
class MyAppState extends State<MyApp> {
var questionindex = 0;
void answerquestion() {
if (questionindex == 1) questionindex = -1;
setState(() {
questionindex++;
});
print(questionindex);
print("answer chosen");
}
final List<Map<String, Object>> question = [
{
'questionText': 'what is your fav color?',
'answers': ['black', 'green', 'blue', 'yellow']
},
{
'questionText': 'whats your fav animal?',
'answers': ['rabbit', 'dog', 'cat', 'monkey']
},
];
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
elevatedButtonTheme: ElevatedButtonThemeData(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.red),
))),
home: Scaffold(
appBar: AppBar(
title: Text("quiz app"),
),
body: Container(
child: Column(
children: <Widget>[
Question(question[questionindex]['questionText'] as String),
...(question[questionindex]['answers'] as List<String>).map(
(answer1) {
return Answer(answerquestion, answer1);
},
).toList(),
],
),
),
),
);
}
}
这些是我得到的例外
═════ Exception caught by rendering library ═════════════════════════════════
A RenderFlex overflowed by 399452 pixels on the bottom.
The relevant error-causing widget was
Column
Exception caught by widgets library ═══════════════════════════════════
setState() or markNeedsBuild() called during build.
The relevant error-causing widget was
Answer
解决方案
添加您的列小部件SingleChildScrollView或扩展的容器
SingleChildScrollView(
child:Column(
children: <Widget>[
Question(question[questionindex]['questionText'] as String),
...(question[questionindex]['answers'] as List<String>).map(
(answer1) {
return Answer(answerquestion, answer1);
},
).toList(),
],
),
),
推荐阅读
- flutter - Flutter json Api日期中的天数计算差异 - 当前日期
- kubernetes - 如何在 env 中为 k8s 设置数组结构属性?
- mysql - 书中的 JOIN 语句等价似乎不正确?
- swift - 如何在 applicationWillEnterForeground(_:) 中调用 LaunchScreen
- laravel - 从域访问时未发送 Sanctum CSRF Cookie
- async-await - JS:带有 await 语句的异步函数导致未定义的承诺。我究竟做错了什么?简单的例子
- python - Python中是否有特定于属性的方法/接口?
- php - Laravel 工匠版
- typescript - 组合来自多个 RxJS 可观察对象的数据的更好方法
- amazon-web-services - Backblaze S3 兼容 API - 预签名 URL - 节点 AWS 开发工具包不起作用