gpt4 book ai didi

flutter - 如何将背景图像添加到 flutter

转载 作者:行者123 更新时间:2023-12-03 03:33:33 25 4
gpt4 key购买 nike

我想删除背景色,并想添加一些图像作为背景。

void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My Title',
debugShowCheckedModeBanner: false,
theme: ThemeData(
scaffoldBackgroundColor: Colors.black,
dialogBackgroundColor: Colors.black,
primarySwatch: Colors.grey,
cardColor: Colors.white70,
accentColor: Colors.black,
),
home: HomePage(),
);
}
}

想要删除此bg颜色并添加图像

最佳答案

你想让它喜欢吗?

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

void main() {
WidgetsFlutterBinding.ensureInitialized();

runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My Title',
debugShowCheckedModeBanner: false,
theme: ThemeData(
scaffoldBackgroundColor: Colors.black,
dialogBackgroundColor: Colors.black,
primarySwatch: Colors.grey,
cardColor: Colors.white70,
accentColor: Colors.black,
),
home: Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/bg.png"),
fit: BoxFit.cover,
),
),
child: null /* add child content here */,
),
),
);
}
}

关于flutter - 如何将背景图像添加到 flutter ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62465613/

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