如何解决抖动中的垂直视点错误?

时间:2018-12-25 02:56:59

标签: android ios mobile dart flutter

以下代码在日志中显示错误,并且仅在屏幕上输出一个应用栏。 请解释为什么会出现此错误,以及如何避免将来发生这种情况。

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

class AchievementsPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: AppBar(title: Text('Achievements',),),
      body: Container(
          padding: EdgeInsets.all(20),
          alignment: Alignment(0, 0),
          child: Container(
            child: Column(
              children: <Widget>[
                Achievement() ,
              ] ,
            ),
          )
          )
      );
  }
}


class Achievement extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
        child: StreamBuilder<QuerySnapshot>(
          stream: Firestore.instance.collection('achievements').snapshots(),
          builder: (BuildContext context,
              AsyncSnapshot<QuerySnapshot> snapshot) {
            if (snapshot.hasError) {
              print(snapshot.error);
              return Text("Error : ${snapshot.error}");
            }

            switch (snapshot.connectionState) {
              case ConnectionState.waiting :
                return Text("Loading...");
              default :
                return ListView(
                  children: snapshot.data.documents.map((
                      DocumentSnapshot document) {
                    return ListTile(
                      title: Text(document['title']),
                      subtitle: Text(document['description']),
                      enabled: true,
                      isThreeLine: true,
                      contentPadding: EdgeInsets.all(2),
                    );
                  }).toList(),
                );
            }
          },
        )
    );
  }
}

这是Log的样子:

Performing hot reload...
Syncing files to device Android SDK built for x86...
I/flutter (12007): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (12007): The following assertion was thrown during performResize():
I/flutter (12007): Vertical viewport was given unbounded height.
I/flutter (12007): Viewports expand in the scrolling direction to fill their container.In this case, a vertical
I/flutter (12007): viewport was given an unlimited amount of vertical space in which to expand. This situation
I/flutter (12007): typically happens when a scrollable widget is nested inside another scrollable widget.
I/flutter (12007): If this widget is always nested in a scrollable widget there is no need to use a viewport because
I/flutter (12007): there will always be enough vertical space for the children. In this case, consider using a Column
I/flutter (12007): instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
I/flutter (12007): the height of the viewport to the sum of the heights of its children.
I/flutter (12007): 
I/flutter (12007): When the exception was thrown, this was the stack:
I/flutter (12007): #0      RenderViewport.performResize.<anonymous closure> (package:flutter/src/rendering/viewport.dart:1129:15)
I/flutter (12007): #1      RenderViewport.performResize (package:flutter/src/rendering/viewport.dart:1182:6)
I/flutter (12007): #2      RenderObject.layout (package:flutter/src/rendering/object.dart:1619:9)
I/flutter (12007): #3      _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)

0 个答案:

没有答案