简体   繁体   English

如何在 flutter 中使显示响应

[英]how to make display responsive in flutter

i am beginner in flutter, i was creating a widget that represents schedules in a football league, but after i executed i found that my screen is not responsive and the display is not fine, a yellow zone appeared, and the display of the date and time is not always in the center, the widget became not ergonomic here an image after execution:我是 flutter 的初学者,我正在创建一个代表足球联赛日程的小部件,但执行后我发现我的屏幕没有响应并且显示不正常,出现黄色区域,并且显示日期和时间并不总是在中心,小部件在执行后变得不符合人体工程学: 在此处输入图像描述

Here the code i have tried:这是我尝试过的代码:

import 'package:flutter/material.dart';


class BroadcastSchedule extends StatelessWidget  {

  String home;
  String homeImage;
  String away;
  String awayImage;
  String time;
  String date;

  BroadcastSchedule(this.home,this.homeImage,this.away,this.awayImage,this.time,this.date);

  @override
  Widget build(BuildContext context) {
    return  Card(
      elevation: 4.0,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(10.0),
      ),
      child: Padding(
        padding: const EdgeInsets.all(16.0),
        child:
        Row(
          children: <Widget>[
            CircleAvatar(
              backgroundImage: NetworkImage(this.homeImage),
            ),
            const SizedBox(width:10.0),
            Spacer(),
            Column(
              crossAxisAlignment: CrossAxisAlignment.end,
              children: <Widget> [
                Text(this.home),
                const SizedBox(height: 5.0, ),
              ],
            ),
            Padding(
              padding: EdgeInsets.only(top:20.0, left: 20.0, right: 20.0),
             child: Container(
               padding: EdgeInsets.all(2.0),
               decoration: BoxDecoration(
                color: Colors.grey[700],
                 borderRadius: BorderRadius.circular(11.0),
               ),
               child: Column(

                 children: [
                   Text(this.time,style: TextStyle(
                       fontWeight: FontWeight.bold,
                       fontSize: 18.0,
                       color: Colors.white,
                   ),),
                   const SizedBox(height: 5.0, ),
                   Text(this.date,style: TextStyle(
                       fontWeight: FontWeight.bold,
                       fontSize: 16.0,
                       color: Colors.white
                   ),),
                 ],
               ),
             ),
           ),
           
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget> [
                Text(this.away),
                const SizedBox(height: 5.0, ),
              ],
            ),
            Spacer(),
            CircleAvatar(
              backgroundImage: NetworkImage(this.awayImage),
            ),
          ],
        ),
      ),
    );
  }
}

My girl is to learn how to make my code responsive and that will not at any case have an error in display like this我的女孩要学习如何使我的代码具有响应性,并且在任何情况下都不会出现这样的显示错误

after adding Expanded above column, the grey Box is still misplaced and there is a problem with the long Text添加Expanded上面的列后,灰色的Box还是放错了地方,长Text有问题

在此处输入图像描述

Seems like your text is overflowing.好像你的文字溢出了。

Added Expanded above Column widget.在 Column 小部件上方添加了 Expanded。 Expanded:A widget that expands a child of a [Row], [Column], or [Flex] so that the child fills the available space. Expanded:扩展 [Row]、[Column] 或 [Flex] 的子项以使子项填充可用空间的小部件。

溶胶

But now we have to Fix Long text.但现在我们必须修复长文本。

Expanded(child:  Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget> [
                Text(this.away),
                const SizedBox(height: 5.0, ),
              ],
            ),
            Spacer(),
            CircleAvatar(
              backgroundImage: NetworkImage(this.awayImage),
            ),)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM