gpt4 book ai didi

Flutter:放置 Logo 图像后背景变为一半

转载 作者:行者123 更新时间:2023-12-03 04:15:41 28 4
gpt4 key购买 nike

所以我试图将我的图像标志放在背景上,但我的背景突然被裁剪,出现了一半的黑屏。如图:enter image description here

我的 main.dart 代码:

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

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

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new LoginPage(),
theme: new ThemeData(
primarySwatch: Colors.green
)
);
}
}

我的 login_page.dart 代码:
import 'package:flutter/material.dart';

class LoginPage extends StatefulWidget{
@override
State createState() => new LoginPageState();
}

class LoginPageState extends State<LoginPage>{
@override
Widget build(BuildContext context){
return new Scaffold(
backgroundColor: Colors.transparent,
body: new Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('assets/arrowPNG.png'),
]
),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/background.png"),
fit: BoxFit.cover,
)
)
)
);
}
}

它是在放置图像标志“Image.asset('assets/arrowPNG.png'),”之后发生的。我该如何解决这个问题?

最佳答案

试试下面的代码

class LoginPageState extends State<LoginPage>{
@override
Widget build(BuildContext context){
return new Scaffold(
backgroundColor: Colors.transparent,
body: new Container(
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('images/a_dot_ham.png'),
]
),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("images/background.jpg"),
fit: BoxFit.cover,
)
)
)
);
}

当您将以下行添加到容器时,问题将得到解决
width: MediaQuery.of(context).size.width

这是我的结果

result

关于Flutter:放置 Logo 图像后背景变为一半,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58888411/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com