Flutter-RenderFlex在底部溢出了13个像素

时间:2020-04-29 20:35:48

标签: flutter

尝试在flutter中打开屏幕时出现此错误

══╡渲染库引起的异常╞══════════════════════════════════════ ═══════════════════ I / flutter(9590):在布局过程中引发了以下断言: I / flutter(9590):RenderFlex在底部溢出了3.1像素。 I /颤振(9590): I / flutter(9590):相关的引起错误的小部件是: I /颤振(9590):列 I / flutter(9590):file:///home/jananath/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/getflutter-1.0.11/lib/components/card/gf_card.dart:11

这是我在屏幕上使用Column的地方:

class _FirstScreenState extends State<FirstScreen> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: _getAppBar(context, widget.news),
      body: Column(
        children: <Widget>[
          _showSearchBar(context),
          SizedBox(
            height: 20.0,
          ),
          Expanded(
              child: StreamBuilder(
            stream: FireStoreServiceApi().getNews(),
            builder:
                (BuildContext context, AsyncSnapshot<List<News>> snapshot) {
              if (snapshot.hasError || !snapshot.hasData) {
                return _progressIndicator();
              } else {

                return ListView.builder(
                  itemCount: snapshot.data.length,
                  itemBuilder: (BuildContext context, int index) {
                    News news = snapshot.data[index];
                    return _getTiles(context, news);
                  },
                );
              }
            },
          )),
        ],
      ),
      floatingActionButton: FloatingActionButton.extended(
        elevation: 4.0,
        icon: const Icon(Icons.camera_enhance),
        label: const Text('Snap'),
        backgroundColor: Colors.red,
        onPressed: () {
          Navigator.push(
            context,
            MaterialPageRoute(builder: (_) => CameraScreen()),
          );
        },
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      bottomNavigationBar: BottomAppBar(
        child: new Row(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            IconButton(
              icon: Icon(null),
              onPressed: () {},
            ),
            IconButton(
              icon: Icon(null),
              onPressed: () {},
            )
          ],
        ),
      ),
    );
  }
}

这也是我正在调用的_getTiles方法:

Widget _getTiles(BuildContext context, News news) {
  var now = new DateTime.now();
  var formatter = new DateFormat('yyyy-MM-dd');
  String formattedDate = formatter.format(now);

  dynamic currentTime = DateFormat.jm().format(DateTime.now());

  String dateNew;
  String timeNew;
  String showDateAndTime;

  if (news.timeDate == null) {
    dateNew = formattedDate;
  } else {
    dateNew = news.timeDate;
  }

  if (news.timeNews == null) {
    timeNew = currentTime;
  } else {
    timeNew = news.timeNews;
  }

  showDateAndTime = dateNew + " - " + timeNew;

  String subtitleNew = "";

  if (news.description.length <= 20) {
    subtitleNew = news.description;
  } else {
    subtitleNew = news.description.substring(0, 60) + "...";
  }

  Color priorityBadgeColor;
  String priorityNew;
  String headlineNew;

  if(news.headline.length <= 20){
    headlineNew = news.headline;
  }else{
    headlineNew = news.headline.substring(0, 20) + "...";
  }

  if (news.priority != null) {
    priorityNew = news.priority;
    if (news.priority.toLowerCase() == "high") {
      priorityBadgeColor = Colors.red;
      priorityNew = "H";
    } else if (news.priority.toLowerCase() == "medium") {
      priorityBadgeColor = Colors.orange;
      priorityNew = "M";
    } else if (news.priority.toLowerCase() == "low") {
      priorityBadgeColor = Colors.green;
      priorityNew = "L";
    }
  } else {
    priorityBadgeColor = Colors.grey;
    priorityNew = "N/A";
  }

  return GFCard(
    boxFit: BoxFit.cover,
    image: (news.imageUrl == null || news.imageUrl.isEmpty || news.imageUrl == "")
        ? Image.asset(
            "images/default_news_image.png",
            height: 200.0,
            width: double.infinity,
            fit: BoxFit.cover,
          )
        : Image.network(news.imageUrl,
            height: 200.0, width: double.infinity, fit: BoxFit.cover),
    title: GFListTile(
      title: Align(
        alignment: Alignment.center,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              headlineNew.toUpperCase(),
              style: TextStyle(color: Colors.black, fontSize: 20.0),
            ),
            SizedBox(
              width: 10.0,
            ),
          ],
        ),
      ),
      subTitle: Align(
        alignment: Alignment.center,
        child: Center(
          child: Text(
            "\n" + subtitleNew,
            style: TextStyle(color: Colors.grey),
            textAlign: TextAlign.center,
          ),
        ),
      ),
    ),
    content: Align(
      alignment: Alignment.center,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Text(
            showDateAndTime,
            style: TextStyle(color: Colors.grey),
          ),
          SizedBox(
            width: 10.0,
          ),
          GFBadge(
            color: priorityBadgeColor,
            text: priorityNew,
            size: GFSize.SMALL,
          ),
        ],
      ),
    ),
    buttonBar: GFButtonBar(
      alignment: WrapAlignment.center,
      children: <Widget>[
        GFButton(
          onPressed: () {
            Navigator.push(
                context,
                MaterialPageRoute(
                    builder: (_) => ViewParticularNews(news: news)));
          },
          icon: Icon(
            Icons.more,
            color: Colors.white,
            size: 14.0,
          ),
          text: 'Read More',
        )
      ],
    ),
  );
}

有人可以帮我解决这个问题吗?

0 个答案:

没有答案