Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振:在身体上填充图像_Flutter_Scaffold - Fatal编程技术网

Flutter 颤振:在身体上填充图像

Flutter 颤振:在身体上填充图像,flutter,scaffold,Flutter,Scaffold,我正在做一个颤振项目。我已经加载了一个图像,我想让它填满身体。在阅读了文档之后,我提出了以下建议: void main() => runApp(MaterialApp( home : Scaffold( appBar: AppBar( title: Center( child: Text("I am rich"), ), backgroundColor: Colors.amberAcc

我正在做一个颤振项目。我已经加载了一个图像,我想让它填满身体。在阅读了文档之后,我提出了以下建议:

void main() => runApp(MaterialApp(
  home : Scaffold(
      appBar: AppBar(
        title: Center(
           child: Text("I am rich"),
        ),
        backgroundColor: Colors.amberAccent,
      ),
      backgroundColor: Colors.purple,
      body: Image(
        fit: BoxFit.cover, 
        image: NetworkImage('https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQWqFc0Y7fRegMPpHoqNmD-hdba-3Zk_ttQQw&usqp=CAU'),
      ),
    )
  )
);
但它似乎不起作用。请帮助

如中所述,您可以使用Image.network代替图像小部件。或者,您可以将“高度”属性添加到图像

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var title = 'Web Images';

    return MaterialApp(
      title: title,
      home: Scaffold(
        appBar: AppBar(
          title: Text(title),
        ),
       body: Image(
        height: double.infinity,
        fit: BoxFit.cover,
        image: NetworkImage(
          'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQWqFc0Y7fRegMPpHoqNmD-hdba-3Zk_ttQQw&usqp=CAU',
        ),
      ),
      ),
    );
  }
}
您可以使用Image.network代替图像小部件,如中所述。或者,您可以将“高度”属性添加到图像

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var title = 'Web Images';

    return MaterialApp(
      title: title,
      home: Scaffold(
        appBar: AppBar(
          title: Text(title),
        ),
       body: Image(
        height: double.infinity,
        fit: BoxFit.cover,
        image: NetworkImage(
          'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQWqFc0Y7fRegMPpHoqNmD-hdba-3Zk_ttQQw&usqp=CAU',
        ),
      ),
      ),
    );
  }
}

使用MediaQuery,它将根据手机屏幕大小设置图像

body: Center(
        child: Image.network(
          'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQWqFc0Y7fRegMPpHoqNmD- hdba-          3Zk_ttQQw&usqp=CAU',
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height,
          fit: BoxFit.fill,
        ),
      ),

使用MediaQuery,它将根据手机屏幕大小设置图像

body: Center(
        child: Image.network(
          'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQWqFc0Y7fRegMPpHoqNmD- hdba-          3Zk_ttQQw&usqp=CAU',
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height,
          fit: BoxFit.fill,
        ),
      ),

您可以复制粘贴运行下面的完整代码 您可以直接将宽度和高度设置为window.physicalSize.width和window.physicalSize.height 您可以使用BoxFit.fill,请参见下面的效果

工作演示

完整代码

import 'dart:ui';

import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(
        home: Scaffold(
      appBar: AppBar(
        title: Center(
          child: Text("I am rich"),
        ),
        backgroundColor: Colors.amberAccent,
      ),
      backgroundColor: Colors.purple,
      body: Image(
        fit: BoxFit.fill,
        width: window.physicalSize.width,
        height: window.physicalSize.height,
        image: NetworkImage(
            'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQWqFc0Y7fRegMPpHoqNmD-hdba-3Zk_ttQQw&usqp=CAU'),
      ),
    )));

您可以复制粘贴运行下面的完整代码 您可以直接将宽度和高度设置为window.physicalSize.width和window.physicalSize.height 您可以使用BoxFit.fill,请参见下面的效果

工作演示

完整代码

import 'dart:ui';

import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(
        home: Scaffold(
      appBar: AppBar(
        title: Center(
          child: Text("I am rich"),
        ),
        backgroundColor: Colors.amberAccent,
      ),
      backgroundColor: Colors.purple,
      body: Image(
        fit: BoxFit.fill,
        width: window.physicalSize.width,
        height: window.physicalSize.height,
        image: NetworkImage(
            'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQWqFc0Y7fRegMPpHoqNmD-hdba-3Zk_ttQQw&usqp=CAU'),
      ),
    )));

正是我需要的。我以为只有boxfit就足够了,我做错了。谢谢你!嘿,看起来好像没有窗口类。这是没有得到承认的mine@shankyyyyyyy,你导入dart:ui了吗,你的颤振版本是什么?天哪,我的错。未导入dart.ui。这正是我所需要的。我以为只有boxfit就足够了,我做错了。谢谢你!嘿,看起来好像没有窗口类。这是没有得到承认的mine@shankyyyyyyy,你导入dart:ui了吗,你的颤振版本是什么?天哪,我的错。未导入dart.ui。它正在工作