颤音:如何彩色盒子(不使用容器)
1。说明
我想更改“ sizedbox”的完整颜色,以查看“ sizedbox”的位置和范围。我想知道有什么方法可以在不用容器或装饰盒填充的情况下更改Sizedbox的颜色。如果没有,我想知道如何用装饰盒填充大小写。
2。代码
这是我尝试的代码。
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home : Scaffold(
appBar: AppBar(
title : const Text('this is title'),
),
body : const SizedBox(
width : 200,
child: DecoratedBox(
decoration: BoxDecoration(
color : Colors.red,
),
),
),
bottomNavigationBar: (
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: const [
Icon(Icons.favorite),
Icon(Icons.home),
Icon(Icons.settings)
],
)
),
),
);
}
}
** 3。结果**
这是我从代码中得到的。
1. Explanation
I want to change full color of 'SizedBox' to see the location and scope of 'SizedBox'. I wonder is there any way to change SizedBox's color without filling it with Container or Decoration box. If not, I want to know how to fill SizedBox with decoration box.
2. Code
Here is a code that I tried.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home : Scaffold(
appBar: AppBar(
title : const Text('this is title'),
),
body : const SizedBox(
width : 200,
child: DecoratedBox(
decoration: BoxDecoration(
color : Colors.red,
),
),
),
bottomNavigationBar: (
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: const [
Icon(Icons.favorite),
Icon(Icons.home),
Icon(Icons.settings)
],
)
),
),
);
}
}
**3. Result **
Here is what I got from the code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以用
用
coloredbox
包装sizedbox
You can wrap your
SizedBox
withColoredBox
您可以尝试 coloredBox widget
You can try ColoredBox widget
如果您想装饰
sizedbox
以查看widget
仅出于调试目的的位置和范围,我们可以启用debugpaintsizeEnabled
仅仅通过在启动flutter Run
命令时,在CLI上按p
。否则,使用具有显式大小参数的
容器
,它与使用sizedbox
的主要相同,并且它可以使用背景颜色或边框装饰。另一个选项是将
coloredbox
用作sizedbox
的孩子,反之亦然。If you'd like to decorate the
SizedBox
to see the location and scope of theWidget
just for debugging purposes, we can enable thedebugPaintSizeEnabled
just by pressingp
on the CLI upon launching theflutter run
command.Otherwise, using a
Container
with explicit size parameters it's mostly the same as usingSizedBox
, and it would allow you to use have a background color or border decoration.Another option would be to use a
ColoredBox
as the child of theSizedBox
, or vice versa.我不确定您为什么要使用它,但是您可以让Sizidbox的孩子成为带有所需颜色的容器。容器还将延伸到提供的尺寸,
您还可以使用Flutter提供的小部件检查器:
https://docs.flutter.dev/develiment/toolment/tools/tools/devtools/devtools/devtools/inspector#:teptor#:text:text= the %20flutter%20widget%20 Inspector%20IS,%2C%20ROWS%2C%20和%20columns )。
I'm not sure why you'd use it but you could have the child of the SizedBox be a container with the color you want. The container will stretch to the sizes provided
Also you could use the widget inspector provided by flutter:
https://docs.flutter.dev/development/tools/devtools/inspector#:~:text=The%20Flutter%20widget%20inspector%20is,%2C%20rows%2C%20and%20columns).