flutter - 如何将背景图像添加到颤动
问题描述
我想删除背景颜色并想添加一些图像作为背景。
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 */,
),
),
);
}
}
推荐阅读
- python - 如何在 Pandas 中按顺序标记分类变量?
- c++ - 如何使 for_each 采用带有 2 个参数的 lambda 函数?
- python - 如何拒绝python中的随机数?
- java - 如何将 arg 或字符串转换为用户?
- c# - 在报告中查找“列 ID”的问题
- google-people-api - Google 的 People API——更新联系人的问题 (Python)
- xcode - 如何检查是否在 mobileVLCkit 中发送数据
- ios - Swift“无法将“AppName.ToDoViewViewCtonroller”类型的值转换为 AppName.CalendarView”SIGBART
- python - 如何将文本文件的内容更改为元组字典?
- ruby - 在 Ruby 中捕获“无法统计:没有这样的文件或目录”错误